add example query

Project: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/commit/cddffe4d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/tree/cddffe4d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/diff/cddffe4d

Branch: refs/heads/master
Commit: cddffe4d3b5e572fe964ee7be953c83c3b10d452
Parents: 2febaae
Author: daewon <[email protected]>
Authored: Mon May 14 14:57:32 2018 +0900
Committer: daewon <[email protected]>
Committed: Mon May 14 14:57:32 2018 +0900

----------------------------------------------------------------------
 example/common.sh                               | 15 ++------
 example/movielens/jobdesc.template              |  2 ++
 example/movielens/postprocess.sh                | 37 ++++++++++++++++++++
 example/movielens/query/recommend_movie.graphql | 35 ++++++++++++++++++
 ..._genres_and_title_with_simlar_movies.graphql | 33 +++++++++++++++++
 .../query/search_movie_by_title.graphql         | 36 +++++++++++++++++++
 example/postprocess.sh                          | 22 ------------
 example/run.sh                                  |  7 +++-
 .../core/index/LuceneIndexProvider.scala        | 18 ++++++++--
 9 files changed, 166 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/cddffe4d/example/common.sh
----------------------------------------------------------------------
diff --git a/example/common.sh b/example/common.sh
index 4fe65fc..19a5834 100644
--- a/example/common.sh
+++ b/example/common.sh
@@ -56,28 +56,17 @@ graphql_rest() {
     }"
     sleep 5
 }
+
 get_services() {
     curl -i -XPOST $REST/graphql -H 'content-type: application/json' -d '
     {
         "query": "query{Management{Services{id name }}}"
     }'
 }
+
 get_labels() {
     curl -i -XPOST $REST/graphql -H 'content-type: application/json' -d '
     {
         "query": "query{Management{Labels {id name}}}"
     }'
 }
-
-update_edge_fetcher() {
-    curl -i -XPOST $REST/updateEdgeFetcher -H 'content-type: application/json' 
-d '
-    {
-        "label": "similar_movie",
-        "options": {
-            "fetcher": {
-                "className": 
"org.apache.s2graph.core.fetcher.annoy.AnnoyModelFetcher",
-                "annoyIndexFilePath": "/tmp/annoy_result"
-            }
-        }
-    }'
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/cddffe4d/example/movielens/jobdesc.template
----------------------------------------------------------------------
diff --git a/example/movielens/jobdesc.template 
b/example/movielens/jobdesc.template
index 19ee116..ca9d5d6 100644
--- a/example/movielens/jobdesc.template
+++ b/example/movielens/jobdesc.template
@@ -125,6 +125,8 @@
       ],
       "type": "s2graph",
       "options": {
+        "index.provider.lucene.fsType": "file",
+        "index.provider.base.dir": "/tmp/lucene",
         "db.default.driver":"org.h2.Driver",
         "db.default.url": "jdbc:h2:tcp://localhost/./var/metastore;MODE=MYSQL",
         "s2.spark.sql.streaming.sink.grouped.size": "10",

http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/cddffe4d/example/movielens/postprocess.sh
----------------------------------------------------------------------
diff --git a/example/movielens/postprocess.sh b/example/movielens/postprocess.sh
new file mode 100644
index 0000000..808c782
--- /dev/null
+++ b/example/movielens/postprocess.sh
@@ -0,0 +1,37 @@
+#!/usr/bin/env bash
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+source common.sh
+
+update_edge_fetcher() {
+    curl -i -XPOST $REST/updateEdgeFetcher -H 'content-type: application/json' 
-d '
+    {
+        "label": "similar_movie",
+        "options": {
+            "fetcher": {
+                "className": 
"org.apache.s2graph.core.fetcher.annoy.AnnoyModelFetcher",
+                "annoyIndexFilePath": "/tmp/annoy_result"
+            }
+        }
+    }'
+}
+
+q "update edge fetcher."
+
+update_edge_fetcher
+
+info "postprocess finished.."

http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/cddffe4d/example/movielens/query/recommend_movie.graphql
----------------------------------------------------------------------
diff --git a/example/movielens/query/recommend_movie.graphql 
b/example/movielens/query/recommend_movie.graphql
new file mode 100644
index 0000000..de8fa32
--- /dev/null
+++ b/example/movielens/query/recommend_movie.graphql
@@ -0,0 +1,35 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+query {
+  movielens {
+    User(id: 1) {
+      rated {
+       Movie {
+          title
+          similar_movie(limit: 5) {
+            Movie {
+              title
+            }
+          }
+        }
+      }
+    }
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/cddffe4d/example/movielens/query/search_movie_by_genres_and_title_with_simlar_movies.graphql
----------------------------------------------------------------------
diff --git 
a/example/movielens/query/search_movie_by_genres_and_title_with_simlar_movies.graphql
 
b/example/movielens/query/search_movie_by_genres_and_title_with_simlar_movies.graphql
new file mode 100644
index 0000000..646376e
--- /dev/null
+++ 
b/example/movielens/query/search_movie_by_genres_and_title_with_simlar_movies.graphql
@@ -0,0 +1,33 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+query {
+  movielens {
+    Movie(search: "genres: *Comedy* AND title: *1995*", limit: 5) {
+      title
+      genres
+      similar_movie(limit: 5) {
+        Movie {
+          title
+          genres
+        }
+      }
+    }
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/cddffe4d/example/movielens/query/search_movie_by_title.graphql
----------------------------------------------------------------------
diff --git a/example/movielens/query/search_movie_by_title.graphql 
b/example/movielens/query/search_movie_by_title.graphql
new file mode 100644
index 0000000..e080431
--- /dev/null
+++ b/example/movielens/query/search_movie_by_title.graphql
@@ -0,0 +1,36 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+query {
+  movielens {
+    Movie(search: "title: *Toy*", limit: 5) {
+      title
+      tagged(limit: 10) {
+        User {
+          id
+          rated(limit: 5) {
+            Movie {
+              title
+            }
+          }
+        }
+      }
+    }
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/cddffe4d/example/postprocess.sh
----------------------------------------------------------------------
diff --git a/example/postprocess.sh b/example/postprocess.sh
deleted file mode 100644
index 79ce327..0000000
--- a/example/postprocess.sh
+++ /dev/null
@@ -1,22 +0,0 @@
-#!/usr/bin/env bash
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#   http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied.  See the License for the
-# specific language governing permissions and limitations
-# under the License.
-source common.sh
-
-q "update edge fetcher."
-update_edge_fetcher
-info "postprocess finished.."
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/cddffe4d/example/run.sh
----------------------------------------------------------------------
diff --git a/example/run.sh b/example/run.sh
index 32a2397..fcbfcf8 100644
--- a/example/run.sh
+++ b/example/run.sh
@@ -37,6 +37,11 @@ q "And now, we create vertex and edge schema using graphql"
 sh ./create_schema.sh $SERVICE
 [ $? -ne 0 ] && { exit -1; }
 
-q "Finally, we import example data to service"
+q "And, we import example data to service"
 sh ./import_data.sh $SERVICE
 [ $? -ne 0 ] && { exit -1; }
+
+q "Finally, we import similar_model data"
+sh ./$SERVICE/postprocess.sh
+[ $? -ne 0 ] && { exit -1; }
+

http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/cddffe4d/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 4a3d044..00f2e20 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.Analyzer
 import org.apache.lucene.analysis.core.KeywordAnalyzer
 import org.apache.lucene.document.{Document, Field, StringField}
 import org.apache.lucene.index.{DirectoryReader, IndexWriter, 
IndexWriterConfig, Term}
@@ -41,6 +42,7 @@ import scala.concurrent.Future
 
 
 class LuceneIndexProvider(config: Config) extends IndexProvider {
+
   import IndexProvider._
 
   import scala.collection.JavaConverters._
@@ -133,6 +135,12 @@ class LuceneIndexProvider(config: Config) extends 
IndexProvider {
     }
   }
 
+  private def createQueryParser(field: String, analyzer: Analyzer): 
QueryParser = {
+    val qp = new QueryParser(field, analyzer)
+    qp.setAllowLeadingWildcard(true)
+    qp
+  }
+
   override def mutateEdgesAsync(edges: Seq[S2EdgeLike], forceToIndex: Boolean 
= false): Future[Seq[Boolean]] =
     Future.successful(mutateEdges(edges, forceToIndex))
 
@@ -204,7 +212,8 @@ class LuceneIndexProvider(config: Config) extends 
IndexProvider {
     val queryString = buildQueryString(hasContainers)
 
     try {
-      val q = new QueryParser(field, analyzer).parse(queryString)
+      val qp = createQueryParser(field, analyzer)
+      val q = qp.parse(queryString)
       fetchInner[VertexId](q, 0, 100, VertexIndexName, vidField, 
Conversions.s2VertexIdReads)
     } catch {
       case ex: ParseException =>
@@ -218,7 +227,8 @@ class LuceneIndexProvider(config: Config) extends 
IndexProvider {
     val queryString = buildQueryString(hasContainers)
 
     try {
-      val q = new QueryParser(field, analyzer).parse(queryString)
+      val qp = createQueryParser(field, analyzer)
+      val q = qp.parse(queryString)
       fetchInner[EdgeId](q, 0, 100, EdgeIndexName, field, 
Conversions.s2EdgeIdReads)
     } catch {
       case ex: ParseException =>
@@ -235,7 +245,9 @@ class LuceneIndexProvider(config: Config) extends 
IndexProvider {
     val ret = 
vertexQueryParam.searchString.fold(util.Arrays.asList[VertexId]()) { 
queryString =>
       val field = vidField
       try {
-        val q = new QueryParser(field, analyzer).parse(queryString)
+        val qp = createQueryParser(field, analyzer)
+        val q = qp.parse(queryString)
+
         fetchInner[VertexId](q, vertexQueryParam.offset, 
vertexQueryParam.limit, VertexIndexName, vidField, Conversions.s2VertexIdReads)
       } catch {
         case ex: ParseException =>

Reply via email to