refactor search
Project: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/commit/ea26552f Tree: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/tree/ea26552f Diff: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/diff/ea26552f Branch: refs/heads/master Commit: ea26552f54f92f096711c66c5b86a85ca5692dd3 Parents: ba938bc Author: daewon <[email protected]> Authored: Thu Apr 19 18:55:12 2018 +0900 Committer: daewon <[email protected]> Committed: Thu Apr 19 18:55:12 2018 +0900 ---------------------------------------------------------------------- .../scala/org/apache/s2graph/core/S2Graph.scala | 9 ++++---- .../core/index/LuceneIndexProvider.scala | 7 ++++--- .../graphql/repository/GraphRepository.scala | 5 ++++- .../s2graph/graphql/types/FieldResolver.scala | 2 -- .../apache/s2graph/graphql/types/S2Type.scala | 22 ++++++-------------- 5 files changed, 18 insertions(+), 27 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/ea26552f/s2core/src/main/scala/org/apache/s2graph/core/S2Graph.scala ---------------------------------------------------------------------- diff --git a/s2core/src/main/scala/org/apache/s2graph/core/S2Graph.scala b/s2core/src/main/scala/org/apache/s2graph/core/S2Graph.scala index 2dc9f63..74574ed 100644 --- a/s2core/src/main/scala/org/apache/s2graph/core/S2Graph.scala +++ b/s2core/src/main/scala/org/apache/s2graph/core/S2Graph.scala @@ -268,7 +268,7 @@ class S2Graph(_config: Config)(implicit val ec: ExecutionContext) extends S2Grap (queryParam.vertexIds ++ vids).distinct.map(vid => elementBuilder.newVertex(vid)) } - if (queryParam.fetchProp) matchedVertices.flatMap(getVertices) + if (true) matchedVertices.flatMap(vs => getVertices(vs)) else matchedVertices } @@ -312,10 +312,9 @@ class S2Graph(_config: Config)(implicit val ec: ExecutionContext) extends S2Grap mutateVertices(getStorage(service))(service.cluster, vertexGroup.map(_._1), withWait).map(_.zip(vertexGroup.map(_._2))) } - Future.sequence(futures).flatMap { ls => - indexProvider.mutateVerticesAsync(vertices).map { _ => - ls.flatten.toSeq.sortBy(_._2).map(_._1) - } + indexProvider.mutateVerticesAsync(vertices) + Future.sequence(futures).map{ ls => + ls.flatten.toSeq.sortBy(_._2).map(_._1) } } http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/ea26552f/s2core/src/main/scala/org/apache/s2graph/core/index/LuceneIndexProvider.scala ---------------------------------------------------------------------- diff --git a/s2core/src/main/scala/org/apache/s2graph/core/index/LuceneIndexProvider.scala b/s2core/src/main/scala/org/apache/s2graph/core/index/LuceneIndexProvider.scala index 68d481c..8d5f997 100644 --- a/s2core/src/main/scala/org/apache/s2graph/core/index/LuceneIndexProvider.scala +++ b/s2core/src/main/scala/org/apache/s2graph/core/index/LuceneIndexProvider.scala @@ -23,6 +23,7 @@ import java.io.File import java.util import com.typesafe.config.Config +import org.apache.lucene.analysis.core.KeywordAnalyzer import org.apache.lucene.analysis.standard.StandardAnalyzer import org.apache.lucene.document.{Document, Field, StringField} import org.apache.lucene.index.{DirectoryReader, IndexWriter, IndexWriterConfig, Term} @@ -48,7 +49,7 @@ class LuceneIndexProvider(config: Config) extends IndexProvider { import scala.collection.JavaConverters._ import scala.collection.mutable - val analyzer = new StandardAnalyzer() + val analyzer = new KeywordAnalyzer() val writers = mutable.Map.empty[String, IndexWriter] val directories = mutable.Map.empty[String, BaseDirectory] val baseDirectory = scala.util.Try(config.getString("index.provider.base.dir")).getOrElse(".") @@ -174,11 +175,11 @@ class LuceneIndexProvider(config: Config) extends IndexProvider { val searcher = new IndexSearcher(reader) val docs = searcher.search(q, hitsPerPage) - logger.error(s"total hit: ${docs.scoreDocs.length}") +// logger.error(s"total hit: ${docs.scoreDocs.length}") docs.scoreDocs.foreach { scoreDoc => val document = searcher.doc(scoreDoc.doc) - logger.error(s"DOC_IN_L: ${document.toString}") +// logger.error(s"DOC_IN_L: ${document.toString}") val id = reads.reads(Json.parse(document.get(field))).get ids.add(id) http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/ea26552f/s2graphql/src/main/scala/org/apache/s2graph/graphql/repository/GraphRepository.scala ---------------------------------------------------------------------- diff --git a/s2graphql/src/main/scala/org/apache/s2graph/graphql/repository/GraphRepository.scala b/s2graphql/src/main/scala/org/apache/s2graph/graphql/repository/GraphRepository.scala index 1f53c76..a83b7f2 100644 --- a/s2graphql/src/main/scala/org/apache/s2graph/graphql/repository/GraphRepository.scala +++ b/s2graphql/src/main/scala/org/apache/s2graph/graphql/repository/GraphRepository.scala @@ -126,7 +126,10 @@ class GraphRepository(val graph: S2GraphLike) { } def getVertices(queryParam: VertexQueryParam): Future[Seq[S2VertexLike]] = { - graph.asInstanceOf[S2Graph].searchVertices(queryParam) + graph.asInstanceOf[S2Graph].searchVertices(queryParam).map { a => + println(a) + a + } } def getEdges(vertices: Seq[S2VertexLike], queryParam: QueryParam): Future[Seq[S2EdgeLike]] = { http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/ea26552f/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/FieldResolver.scala ---------------------------------------------------------------------- diff --git a/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/FieldResolver.scala b/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/FieldResolver.scala index 64650d3..4f092dd 100644 --- a/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/FieldResolver.scala +++ b/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/FieldResolver.scala @@ -53,8 +53,6 @@ object FieldResolver { val ids = c.argOpt[Any]("id").toSeq ++ c.argOpt[List[Any]]("ids").toList.flatten val vertices = ids.map(vid => c.ctx.toS2VertexLike(vid, column)) - val search = c.argOpt[String]("search") - val columnFields = column.metasInvMap.keySet val selectedFields = AstHelper.selectedFields(c.astFields) http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/ea26552f/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/S2Type.scala ---------------------------------------------------------------------- diff --git a/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/S2Type.scala b/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/S2Type.scala index 4ba6680..b532263 100644 --- a/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/S2Type.scala +++ b/s2graphql/src/main/scala/org/apache/s2graph/graphql/types/S2Type.scala @@ -146,23 +146,14 @@ object S2Type { implicit val ec = c.ctx.ec val (vertices, canSkipFetchVertex) = FieldResolver.serviceColumnOnService(column, c) val searchOpt = c.argOpt[String]("search").map { qs => - val prefix = s"${GlobalIndex.serviceField}:${service.serviceName} AND ${GlobalIndex.serviceColumnField}:${column.columnName}" + val prefix = s"(${GlobalIndex.serviceField}:${service.serviceName} AND ${GlobalIndex.serviceColumnField}:${column.columnName})" + if (qs.trim.nonEmpty) Seq(prefix, qs).mkString(" AND ") else prefix - qs } - println(searchOpt) - - val vertexQueryParam = VertexQueryParam(0, 100, searchOpt, vertices.map(_.id)) - -// if (canSkipFetchVertex) Future.successful(vertices) -// else GraphRepository.vertexFetcher.deferSeq(deferVertices) - -// val empty = Seq.empty[S2VertexLike] -// DeferredValue(GraphRepository.vertexFetcher.defer(vertexQueryParam)).map(m => m._2) - - c.ctx.getVertices(vertexQueryParam) + val vertexQueryParam = VertexQueryParam(0, 100, searchOpt, vertices.map(_.id), !canSkipFetchVertex) + DeferredValue(GraphRepository.vertexFetcher.defer(vertexQueryParam)).map(m => m._2) } ): Field[GraphRepository, Any] } @@ -189,9 +180,8 @@ object S2Type { implicit val ec = c.ctx.ec val (vertex, canSkipFetchVertex) = FieldResolver.serviceColumnOnLabel(c) - // if (canSkipFetchVertex) Future.successful(vertex) - // else GraphRepository.vertexFetcher.defer(vertex) - Future.successful(vertex) + val vertexQueryParam = VertexQueryParam(0, 100, None, Seq(vertex.id), !canSkipFetchVertex) + DeferredValue(GraphRepository.vertexFetcher.defer(vertexQueryParam)).map(m => m._2.head) }) lazy val EdgeType = ObjectType(
