You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@s2graph.apache.org by st...@apache.org on 2018/04/24 02:10:49 UTC
[2/3] incubator-s2graph git commit: add vertexQueryParam on
esIndexProvider
add vertexQueryParam on esIndexProvider
Project: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/commit/37b4a45b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/tree/37b4a45b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/diff/37b4a45b
Branch: refs/heads/master
Commit: 37b4a45bb47db48d05cfbcdafb8f0867c1d33cca
Parents: 70da150
Author: daewon <da...@apache.org>
Authored: Mon Apr 23 18:42:13 2018 +0900
Committer: daewon <da...@apache.org>
Committed: Mon Apr 23 18:42:28 2018 +0900
----------------------------------------------------------------------
.../org/apache/s2graph/core/QueryParam.scala | 4 +++
.../s2graph/core/index/ESIndexProvider.scala | 27 ++++++++++++++++----
.../core/index/LuceneIndexProvider.scala | 2 +-
.../apache/s2graph/graphql/ScenarioTest.scala | 25 ++++++++++++++++++
4 files changed, 52 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/37b4a45b/s2core/src/main/scala/org/apache/s2graph/core/QueryParam.scala
----------------------------------------------------------------------
diff --git a/s2core/src/main/scala/org/apache/s2graph/core/QueryParam.scala b/s2core/src/main/scala/org/apache/s2graph/core/QueryParam.scala
index faf04db..6d24c3f 100644
--- a/s2core/src/main/scala/org/apache/s2graph/core/QueryParam.scala
+++ b/s2core/src/main/scala/org/apache/s2graph/core/QueryParam.scala
@@ -293,6 +293,10 @@ object QueryParam {
}
}
+object VertexQueryParam {
+ def Empty: VertexQueryParam = VertexQueryParam(0, 1, None)
+}
+
case class VertexQueryParam(offset: Int,
limit: Int,
searchString: Option[String],
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/37b4a45b/s2core/src/main/scala/org/apache/s2graph/core/index/ESIndexProvider.scala
----------------------------------------------------------------------
diff --git a/s2core/src/main/scala/org/apache/s2graph/core/index/ESIndexProvider.scala b/s2core/src/main/scala/org/apache/s2graph/core/index/ESIndexProvider.scala
index 27039e5..e67d529 100644
--- a/s2core/src/main/scala/org/apache/s2graph/core/index/ESIndexProvider.scala
+++ b/s2core/src/main/scala/org/apache/s2graph/core/index/ESIndexProvider.scala
@@ -152,11 +152,11 @@ class ESIndexProvider(config: Config)(implicit ec: ExecutionContext) extends Ind
}
}
- private def fetchInner[T](queryString: String, indexKey: String, field: String, reads: Reads[T])(validate: (T => Boolean)): Future[util.List[T]] = {
+ private def fetchInner[T](queryString: String, offset: Int, limit: Int, indexKey: String, field: String, reads: Reads[T])(validate: (T => Boolean)): Future[util.List[T]] = {
val ids = new java.util.HashSet[T]
client.execute {
- search(indexKey).query(queryString)
+ search(indexKey).query(queryString).from(offset).limit(limit)
}.map { ret =>
ret match {
case Left(failure) =>
@@ -181,7 +181,13 @@ class ESIndexProvider(config: Config)(implicit ec: ExecutionContext) extends Ind
val field = eidField
val queryString = buildQueryString(hasContainers)
- fetchInner[EdgeId](queryString, GlobalIndex.EdgeIndexName, field, Conversions.s2EdgeIdReads)(e => EdgeId.isValid(e).isDefined)
+ fetchInner[EdgeId](
+ queryString,
+ 0,
+ 1000,
+ GlobalIndex.EdgeIndexName,
+ field,
+ Conversions.s2EdgeIdReads)(e => EdgeId.isValid(e).isDefined)
}
override def fetchVertexIds(hasContainers: util.List[HasContainer]): util.List[VertexId] =
@@ -191,7 +197,12 @@ class ESIndexProvider(config: Config)(implicit ec: ExecutionContext) extends Ind
val field = vidField
val queryString = buildQueryString(hasContainers)
- fetchInner[VertexId](queryString, GlobalIndex.VertexIndexName, field, Conversions.s2VertexIdReads)(v => VertexId.isValid(v).isDefined)
+ fetchInner[VertexId](queryString,
+ 0,
+ 1000,
+ GlobalIndex.VertexIndexName,
+ field,
+ Conversions.s2VertexIdReads)(v => VertexId.isValid(v).isDefined)
}
override def fetchVertexIdsAsyncRaw(vertexQueryParam: VertexQueryParam): Future[util.List[VertexId]] = {
@@ -200,7 +211,13 @@ class ESIndexProvider(config: Config)(implicit ec: ExecutionContext) extends Ind
vertexQueryParam.searchString match {
case Some(queryString) =>
- fetchInner[VertexId](queryString, GlobalIndex.VertexIndexName, field, Conversions.s2VertexIdReads)(v => VertexId.isValid(v).isDefined)
+ fetchInner[VertexId](
+ queryString,
+ vertexQueryParam.offset,
+ vertexQueryParam.limit,
+ GlobalIndex.VertexIndexName,
+ field,
+ Conversions.s2VertexIdReads)(v => VertexId.isValid(v).isDefined)
case None => Future.successful(empty)
}
}
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/37b4a45b/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 1b9d087..c417022 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
@@ -183,7 +183,7 @@ class LuceneIndexProvider(config: Config) extends IndexProvider {
val reader = DirectoryReader.open(getOrElseDirectory(indexKey))
val searcher = new IndexSearcher(reader)
val collector = TopScoreDocCollector.create(MAX_RESULTS)
- val startIndex = offset * limit
+ val startIndex = offset
searcher.search(q, collector)
http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/37b4a45b/s2graphql/src/test/scala/org/apache/s2graph/graphql/ScenarioTest.scala
----------------------------------------------------------------------
diff --git a/s2graphql/src/test/scala/org/apache/s2graph/graphql/ScenarioTest.scala b/s2graphql/src/test/scala/org/apache/s2graph/graphql/ScenarioTest.scala
index 58e473d..940f11c 100644
--- a/s2graphql/src/test/scala/org/apache/s2graph/graphql/ScenarioTest.scala
+++ b/s2graphql/src/test/scala/org/apache/s2graph/graphql/ScenarioTest.scala
@@ -437,6 +437,31 @@ class ScenarioTest extends FunSpec with Matchers with BeforeAndAfterAll {
actual shouldBe expected
}
+ it("should fetch vertices: offset, limit") {
+ val query =
+ graphql"""
+
+ query FetchVertices {
+ kakao {
+ user(search: "gender: M OR gender: F or gender: T", offset: 1, limit: 2) {
+ id
+ age
+ gender
+ props {
+ age
+ }
+ }
+ }
+ }
+ """
+
+ val actual = testGraph.queryAsJs(query)
+ val expected = 2
+
+ // The user order may vary depending on the indexProvider(es, lucene).
+ (actual \\ "gender").size shouldBe expected
+ }
+
it("should fetch vertices using VertexIndex: 'gender in (F, M)') from kakao.user") {
def query(search: String) = {
QueryParser.parse(