lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbern...@apache.org
Subject [08/11] lucene-solr:branch_6x: SOLR-8925: Integrate the GraphTermsQuery into the gatherNodes expression
Date Mon, 02 May 2016 13:29:39 GMT
SOLR-8925: Integrate the GraphTermsQuery into the gatherNodes expression


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/d1f32c04
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/d1f32c04
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/d1f32c04

Branch: refs/heads/branch_6x
Commit: d1f32c04325f97d7fae287de154e628a81c7c98e
Parents: 06f9bd2
Author: jbernste <jbernste@apache.org>
Authored: Tue Apr 26 14:25:35 2016 -0400
Committer: jbernste <jbernste@apache.org>
Committed: Mon May 2 08:42:24 2016 -0400

----------------------------------------------------------------------
 .../solr/search/GraphTermsQParserPlugin.java    |  2 +-
 .../search/TestGraphTermsQParserPlugin.java     |  2 +-
 .../solrj/io/graph/GatherNodesStream.java       | 43 ++++++++++++++------
 .../solrj/io/graph/GraphExpressionTest.java     | 17 ++++++++
 4 files changed, 50 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d1f32c04/solr/core/src/java/org/apache/solr/search/GraphTermsQParserPlugin.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/search/GraphTermsQParserPlugin.java b/solr/core/src/java/org/apache/solr/search/GraphTermsQParserPlugin.java
index 5a2fe11..9c1c162 100644
--- a/solr/core/src/java/org/apache/solr/search/GraphTermsQParserPlugin.java
+++ b/solr/core/src/java/org/apache/solr/search/GraphTermsQParserPlugin.java
@@ -133,7 +133,7 @@ public class GraphTermsQParserPlugin extends QParserPlugin {
         collectTermContext(reader, contexts, termContexts, this.queryTerms);
         for(int i=0; i<termContexts.length; i++) {
           TermContext termContext = termContexts[i];
-          if(termContext != null && termContext.docFreq() < this.maxDocFreq) {
+          if(termContext != null && termContext.docFreq() <= this.maxDocFreq)
{
             this.finalContexts.add(termContext);
             this.finalTerms.add(queryTerms[i]);
           }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d1f32c04/solr/core/src/test/org/apache/solr/search/TestGraphTermsQParserPlugin.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/search/TestGraphTermsQParserPlugin.java b/solr/core/src/test/org/apache/solr/search/TestGraphTermsQParserPlugin.java
index cfff980..858800a 100644
--- a/solr/core/src/test/org/apache/solr/search/TestGraphTermsQParserPlugin.java
+++ b/solr/core/src/test/org/apache/solr/search/TestGraphTermsQParserPlugin.java
@@ -125,7 +125,7 @@ public class TestGraphTermsQParserPlugin extends SolrTestCaseJ4 {
 
     //Test with int field
     params = new ModifiableSolrParams();
-    params.add("q", "{!graphTerms f=test_ti maxDocFreq=3}5,10");
+    params.add("q", "{!graphTerms f=test_ti maxDocFreq=2}5,10");
     params.add("sort", "id asc");
     assertQ(req(params, "indent", "on"), "*[count(//doc)=2]",
         "//result/doc[1]/float[@name='id'][.='6.0']",

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d1f32c04/solr/solrj/src/java/org/apache/solr/client/solrj/io/graph/GatherNodesStream.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/io/graph/GatherNodesStream.java
b/solr/solrj/src/java/org/apache/solr/client/solrj/io/graph/GatherNodesStream.java
index 7ab6e97..ee76937 100644
--- a/solr/solrj/src/java/org/apache/solr/client/solrj/io/graph/GatherNodesStream.java
+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/io/graph/GatherNodesStream.java
@@ -66,6 +66,7 @@ public class GatherNodesStream extends TupleStream implements Expressible
{
   private Iterator<Tuple> out;
   private Traversal traversal;
   private List<Metric> metrics;
+  private int maxDocFreq;
 
   public GatherNodesStream(String zkHost,
                            String collection,
@@ -76,7 +77,8 @@ public class GatherNodesStream extends TupleStream implements Expressible
{
                            Map queryParams,
                            List<Metric> metrics,
                            boolean trackTraversal,
-                           Set<Traversal.Scatter> scatter) {
+                           Set<Traversal.Scatter> scatter,
+                           int maxDocFreq) {
 
     init(zkHost,
         collection,
@@ -87,7 +89,8 @@ public class GatherNodesStream extends TupleStream implements Expressible
{
         queryParams,
         metrics,
         trackTraversal,
-        scatter);
+        scatter,
+        maxDocFreq);
   }
 
   public GatherNodesStream(StreamExpression expression, StreamFactory factory) throws IOException
{
@@ -185,10 +188,11 @@ public class GatherNodesStream extends TupleStream implements Expressible
{
       useDefaultTraversal = true;
     }
 
-    StreamExpressionNamedParameter scopeExpression = factory.getNamedOperand(expression,
"localScope");
+    StreamExpressionNamedParameter docFreqExpression = factory.getNamedOperand(expression,
"maxDocFreq");
+    int docFreq = -1;
 
-    if(trackExpression != null) {
-      trackTraversal = Boolean.parseBoolean(((StreamExpressionValue) trackExpression.getParameter()).getValue());
+    if(docFreqExpression != null) {
+      docFreq = Integer.parseInt(((StreamExpressionValue) docFreqExpression.getParameter()).getValue());
     }
 
     Map<String,String> params = new HashMap<String,String>();
@@ -197,6 +201,7 @@ public class GatherNodesStream extends TupleStream implements Expressible
{
           !namedParam.getName().equals("gather") &&
           !namedParam.getName().equals("walk") &&
           !namedParam.getName().equals("scatter") &&
+          !namedParam.getName().equals("maxDocFreq") &&
           !namedParam.getName().equals("trackTraversal"))
       {
         params.put(namedParam.getName(), namedParam.getParameter().toString().trim());
@@ -228,7 +233,8 @@ public class GatherNodesStream extends TupleStream implements Expressible
{
          params,
          metrics,
          trackTraversal,
-         scatter);
+         scatter,
+         docFreq);
   }
 
   private void init(String zkHost,
@@ -240,7 +246,8 @@ public class GatherNodesStream extends TupleStream implements Expressible
{
                     Map queryParams,
                     List<Metric> metrics,
                     boolean trackTraversal,
-                    Set<Traversal.Scatter> scatter) {
+                    Set<Traversal.Scatter> scatter,
+                    int maxDocFreq) {
     this.zkHost = zkHost;
     this.collection = collection;
     this.tupleStream = tupleStream;
@@ -251,6 +258,7 @@ public class GatherNodesStream extends TupleStream implements Expressible
{
     this.metrics = metrics;
     this.trackTraversal = trackTraversal;
     this.scatter = scatter;
+    this.maxDocFreq = maxDocFreq;
   }
 
   @Override
@@ -298,6 +306,9 @@ public class GatherNodesStream extends TupleStream implements Expressible
{
 
     expression.addParameter(new StreamExpressionNamedParameter("zkHost", zkHost));
     expression.addParameter(new StreamExpressionNamedParameter("gather", zkHost));
+    if(maxDocFreq > -1) {
+      expression.addParameter(new StreamExpressionNamedParameter("maxDocFreq", Integer.toString(maxDocFreq)));
+    }
     expression.addParameter(new StreamExpressionNamedParameter("walk", traverseFrom+"->"+traverseTo));
     expression.addParameter(new StreamExpressionNamedParameter("trackTraversal", Boolean.toString(trackTraversal)));
 
@@ -410,7 +421,7 @@ public class GatherNodesStream extends TupleStream implements Expressible
{
       }
 
       if(queryParams.containsKey("fl")) {
-        String flString = (String)queryParams.get("fl");
+        String flString = queryParams.get("fl");
         String[] flArray = flString.split(",");
         for(String f : flArray) {
           flSet.add(f.trim());
@@ -433,14 +444,22 @@ public class GatherNodesStream extends TupleStream implements Expressible
{
 
       StringBuffer nodeQuery = new StringBuffer();
 
+      boolean comma = false;
       for(String node : nodes) {
-        nodeQuery.append(node).append(" ");
+        if(comma) {
+          nodeQuery.append(",");
+        }
+        nodeQuery.append(node);
+        comma = true;
       }
 
-      String q = traverseTo + ":(" + nodeQuery.toString().trim() + ")";
-
+      if(maxDocFreq > -1) {
+        String docFreqParam = " maxDocFreq="+maxDocFreq;
+        joinParams.put("q", "{!graphTerms f=" + traverseTo + docFreqParam + "}" + nodeQuery.toString());
+      } else {
+        joinParams.put("q", "{!terms f=" + traverseTo+"}" + nodeQuery.toString());
+      }
 
-      joinParams.put("q", q);
       TupleStream stream = null;
       try {
         stream = new UniqueStream(new CloudSolrStream(zkHost, collection, joinParams), new
MultipleFieldEqualitor(new FieldEqualitor(gather), new FieldEqualitor(traverseTo)));

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d1f32c04/solr/solrj/src/test/org/apache/solr/client/solrj/io/graph/GraphExpressionTest.java
----------------------------------------------------------------------
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/io/graph/GraphExpressionTest.java
b/solr/solrj/src/test/org/apache/solr/client/solrj/io/graph/GraphExpressionTest.java
index b5231e2..7c1f97d 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/io/graph/GraphExpressionTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/io/graph/GraphExpressionTest.java
@@ -326,6 +326,23 @@ public class GraphExpressionTest extends AbstractFullDistribZkTestBase
{
     assertTrue(tuples.get(2).getString("node").equals("basket3"));
     assertTrue(tuples.get(3).getString("node").equals("basket4"));
 
+
+    //Test maxDocFreq param
+    String docFreqExpr = "gatherNodes(collection1, " +
+                         "walk=\"product1, product7->product_s\"," +
+                         "maxDocFreq=\"2\","+
+                         "gather=\"basket_s\")";
+
+    stream = (GatherNodesStream)factory.constructStream(docFreqExpr);
+    stream.setStreamContext(context);
+
+    tuples = getTuples(stream);
+    Collections.sort(tuples, new FieldComparator("node", ComparatorOrder.ASCENDING));
+    assertTrue(tuples.size() == 1);
+    assertTrue(tuples.get(0).getString("node").equals("basket2"));
+
+
+
     String expr2 = "gatherNodes(collection1, " +
                                  expr+","+
                                 "walk=\"node->basket_s\"," +


Mime
View raw message