You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2014/02/06 17:24:29 UTC

svn commit: r1565325 - in /lucene/dev/branches/lucene5376/lucene: facet/src/java/org/apache/lucene/facet/range/ server/src/java/org/apache/lucene/server/ server/src/test/org/apache/lucene/server/

Author: mikemccand
Date: Thu Feb  6 16:24:29 2014
New Revision: 1565325

URL: http://svn.apache.org/r1565325
Log:
LUCENE-5376: add some more test cases for dynamic expressions; clean up test code

Modified:
    lucene/dev/branches/lucene5376/lucene/facet/src/java/org/apache/lucene/facet/range/Range.java
    lucene/dev/branches/lucene5376/lucene/server/src/java/org/apache/lucene/server/MyIndexSearcher.java
    lucene/dev/branches/lucene5376/lucene/server/src/test/org/apache/lucene/server/ServerBaseTestCase.java
    lucene/dev/branches/lucene5376/lucene/server/src/test/org/apache/lucene/server/TestVirtualFields.java

Modified: lucene/dev/branches/lucene5376/lucene/facet/src/java/org/apache/lucene/facet/range/Range.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5376/lucene/facet/src/java/org/apache/lucene/facet/range/Range.java?rev=1565325&r1=1565324&r2=1565325&view=diff
==============================================================================
--- lucene/dev/branches/lucene5376/lucene/facet/src/java/org/apache/lucene/facet/range/Range.java (original)
+++ lucene/dev/branches/lucene5376/lucene/facet/src/java/org/apache/lucene/facet/range/Range.java Thu Feb  6 16:24:29 2014
@@ -17,9 +17,12 @@ package org.apache.lucene.facet.range;
  * limitations under the License.
  */
 
+import org.apache.lucene.facet.DrillDownQuery; // javadocs
+import org.apache.lucene.facet.DrillSideways; // javadocs
 import org.apache.lucene.queries.function.ValueSource;
 import org.apache.lucene.search.Filter;
 import org.apache.lucene.search.FilteredQuery; // javadocs
+import org.apache.lucene.search.NumericRangeFilter; // javadocs
 
 /** Base class for a single labeled range.
  *

Modified: lucene/dev/branches/lucene5376/lucene/server/src/java/org/apache/lucene/server/MyIndexSearcher.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5376/lucene/server/src/java/org/apache/lucene/server/MyIndexSearcher.java?rev=1565325&r1=1565324&r2=1565325&view=diff
==============================================================================
--- lucene/dev/branches/lucene5376/lucene/server/src/java/org/apache/lucene/server/MyIndexSearcher.java (original)
+++ lucene/dev/branches/lucene5376/lucene/server/src/java/org/apache/lucene/server/MyIndexSearcher.java Thu Feb  6 16:24:29 2014
@@ -21,6 +21,7 @@ import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.lucene.facet.sortedset.DefaultSortedSetDocValuesReaderState;
 import org.apache.lucene.facet.sortedset.SortedSetDocValuesReaderState;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.search.Collector;
@@ -49,7 +50,7 @@ public class MyIndexSearcher extends Ind
         String indexFieldName = state.facetsConfig.getDimConfig(field.name).indexFieldName;
         if (ssdvStates.containsKey(indexFieldName) == false) {
           // TODO: log how long this took
-          ssdvStates.put(indexFieldName, new SortedSetDocValuesReaderState(r, indexFieldName));
+          ssdvStates.put(indexFieldName, new DefaultSortedSetDocValuesReaderState(r, indexFieldName));
         }
       }
     }

Modified: lucene/dev/branches/lucene5376/lucene/server/src/test/org/apache/lucene/server/ServerBaseTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5376/lucene/server/src/test/org/apache/lucene/server/ServerBaseTestCase.java?rev=1565325&r1=1565324&r2=1565325&view=diff
==============================================================================
--- lucene/dev/branches/lucene5376/lucene/server/src/test/org/apache/lucene/server/ServerBaseTestCase.java (original)
+++ lucene/dev/branches/lucene5376/lucene/server/src/test/org/apache/lucene/server/ServerBaseTestCase.java Thu Feb  6 16:24:29 2014
@@ -548,6 +548,14 @@ public abstract class ServerBaseTestCase
    *  that all fragments occur in the failure message
    *  string.  Use this to verify a failure case is hitting
    *  the right error messages back to the user. */
+  protected void assertFailsWith(String command, JSONObject args, String... fragments) throws Exception {
+    assertFailsWith(command, args.toString(), fragments);
+  }
+
+  /** Sends the command + args, expecting a failure such
+   *  that all fragments occur in the failure message
+   *  string.  Use this to verify a failure case is hitting
+   *  the right error messages back to the user. */
   protected void assertFailsWith(String command, String args, String... fragments) throws Exception {
     try {
       send(command, args);

Modified: lucene/dev/branches/lucene5376/lucene/server/src/test/org/apache/lucene/server/TestVirtualFields.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5376/lucene/server/src/test/org/apache/lucene/server/TestVirtualFields.java?rev=1565325&r1=1565324&r2=1565325&view=diff
==============================================================================
--- lucene/dev/branches/lucene5376/lucene/server/src/test/org/apache/lucene/server/TestVirtualFields.java (original)
+++ lucene/dev/branches/lucene5376/lucene/server/src/test/org/apache/lucene/server/TestVirtualFields.java Thu Feb  6 16:24:29 2014
@@ -56,56 +56,56 @@ public class TestVirtualFields extends S
   public void testSortByVirtualFieldStraight() throws Exception {
     deleteAllDocs();
     send("addDocument", "{fields: {id: 0, boost: 1.0}}");
-    long gen = getLong(send("addDocument", "{fields: {id: 1, boost: 2.0}}"), "indexGen");
-    JSONObject result = send("search", "{query: MatchAllDocsQuery, sort: {fields: [{field: logboost}]}, retrieveFields: [id], searcher: {indexGen: " + gen + "}}");
-    assertEquals(2, getInt(result, "totalHits"));
-    assertEquals(0, getInt(result, "hits[0].fields.id"));
-    assertEquals(1, getInt(result, "hits[1].fields.id"));
+    send("addDocument", "{fields: {id: 1, boost: 2.0}}");
+    send("search", "{query: MatchAllDocsQuery, sort: {fields: [{field: logboost}]}, retrieveFields: [id]}");
+    assertEquals(2, getInt("totalHits"));
+    assertEquals(0, getInt("hits[0].fields.id"));
+    assertEquals(1, getInt("hits[1].fields.id"));
 
-    assertEquals(0.0f, getFloat(result, "hits[0].fields.sortFields.logboost"), .0001f);
-    assertEquals(.6931f, getFloat(result, "hits[1].fields.sortFields.logboost"), .0001f);
+    assertEquals(0.0f, getFloat("hits[0].fields.sortFields.logboost"), .0001f);
+    assertEquals(.6931f, getFloat("hits[1].fields.sortFields.logboost"), .0001f);
   }
 
   /** Reversed sort by virtual field */
   public void testSortByVirtualFieldReversed() throws Exception {
     deleteAllDocs();
     send("addDocument", "{fields: {id: 0, boost: 1.0}}");
-    long gen = getLong(send("addDocument", "{fields: {id: 1, boost: 2.0}}"), "indexGen");
-    JSONObject result = send("search", "{query: MatchAllDocsQuery, sort: {fields: [{field: logboost, reverse: true}]}, retrieveFields: [id], searcher: {indexGen: " + gen + "}}");
-    assertEquals(2, getInt(result, "totalHits"));
-    assertEquals(1, getInt(result, "hits[0].fields.id"));
-    assertEquals(0, getInt(result, "hits[1].fields.id"));
+    send("addDocument", "{fields: {id: 1, boost: 2.0}}");
+    send("search", "{query: MatchAllDocsQuery, sort: {fields: [{field: logboost, reverse: true}]}, retrieveFields: [id]}");
+    assertEquals(2, getInt("totalHits"));
+    assertEquals(1, getInt("hits[0].fields.id"));
+    assertEquals(0, getInt("hits[1].fields.id"));
 
-    assertEquals(.6931f, getFloat(result, "hits[0].fields.sortFields.logboost"), .0001f);
-    assertEquals(0.0f, getFloat(result, "hits[1].fields.sortFields.logboost"), .0001f);
+    assertEquals(.6931f, getFloat("hits[0].fields.sortFields.logboost"), .0001f);
+    assertEquals(0.0f, getFloat("hits[1].fields.sortFields.logboost"), .0001f);
   }
 
   /** Sort by virtual field, and ask for its value */
   public void testRetrieveVirtualFieldWithSort() throws Exception {
     deleteAllDocs();
     send("addDocument", "{fields: {id: 0, boost: 1.0}}");
-    long gen = getLong(send("addDocument", "{fields: {id: 1, boost: 2.0}}"), "indexGen");
-    JSONObject result = send("search", "{query: MatchAllDocsQuery, sort: {fields: [{field: logboost}]}, retrieveFields: [id, logboost], searcher: {indexGen: " + gen + "}}");
-    assertEquals(2, getInt(result, "totalHits"));
-    assertEquals(0, getInt(result, "hits[0].fields.id"));
-    assertEquals(1, getInt(result, "hits[1].fields.id"));
+    send("addDocument", "{fields: {id: 1, boost: 2.0}}");
+    send("search", "{query: MatchAllDocsQuery, sort: {fields: [{field: logboost}]}, retrieveFields: [id, logboost]}");
+    assertEquals(2, getInt("totalHits"));
+    assertEquals(0, getInt("hits[0].fields.id"));
+    assertEquals(1, getInt("hits[1].fields.id"));
 
-    assertEquals(0.0f, getFloat(result, "hits[0].fields.logboost"), .0001f);
-    assertEquals(.6931f, getFloat(result, "hits[1].fields.logboost"), .0001f);
+    assertEquals(0.0f, getFloat("hits[0].fields.logboost"), .0001f);
+    assertEquals(.6931f, getFloat("hits[1].fields.logboost"), .0001f);
   }
 
   /** Don't sort by virtual field, and ask for its value */
   public void testRetrieveVirtualFieldWithoutSort() throws Exception {
     deleteAllDocs();
     send("addDocument", "{fields: {id: 0, boost: 1.0}}");
-    long gen = getLong(send("addDocument", "{fields: {id: 1, boost: 2.0}}"), "indexGen");
-    JSONObject result = send("search", "{query: MatchAllDocsQuery, sort: {fields: [{field: id, reverse: true}]}, retrieveFields: [id, logboost], searcher: {indexGen: " + gen + "}}");
-    assertEquals(2, getInt(result, "totalHits"));
-    assertEquals(1, getInt(result, "hits[0].fields.id"));
-    assertEquals(0, getInt(result, "hits[1].fields.id"));
+    send("addDocument", "{fields: {id: 1, boost: 2.0}}");
+    send("search", "{query: MatchAllDocsQuery, sort: {fields: [{field: id, reverse: true}]}, retrieveFields: [id, logboost]}");
+    assertEquals(2, getInt("totalHits"));
+    assertEquals(1, getInt("hits[0].fields.id"));
+    assertEquals(0, getInt("hits[1].fields.id"));
 
-    assertEquals(.6931f, getFloat(result, "hits[0].fields.logboost"), .0001f);
-    assertEquals(0.0f, getFloat(result, "hits[1].fields.logboost"), .0001f);
+    assertEquals(.6931f, getFloat("hits[0].fields.logboost"), .0001f);
+    assertEquals(0.0f, getFloat("hits[1].fields.logboost"), .0001f);
   }
 
   public void testFieldUsingAnother() throws Exception {
@@ -113,47 +113,47 @@ public class TestVirtualFields extends S
     send("registerFields", "{fields: {scoreboost2: {type: virtual, expression: '2*scoreboost'}}}");
 
     send("addDocument", "{fields: {text: 'the wind is howling like this swirling storm inside', id: 0, boost: 1.0}}");
-    long gen = getLong(send("addDocument", "{fields: {text: 'I am one with the wind and sky', id: 1, boost: 2.0}}"), "indexGen");
-    JSONObject result = send("search", "{queryText: wind, sort: {fields: [{field: scoreboost2, reverse: true}]}, retrieveFields: [id, scoreboost2], searcher: {indexGen: " + gen + "}}");
-    assertEquals(2, getInt(result, "totalHits"));
-    assertEquals(1, getInt(result, "hits[0].fields.id"));
-    assertEquals(0, getInt(result, "hits[1].fields.id"));
+    send("addDocument", "{fields: {text: 'I am one with the wind and sky', id: 1, boost: 2.0}}");
+    send("search", "{queryText: wind, sort: {fields: [{field: scoreboost2, reverse: true}]}, retrieveFields: [id, scoreboost2]}");
+    assertEquals(2, getInt("totalHits"));
+    assertEquals(1, getInt("hits[0].fields.id"));
+    assertEquals(0, getInt("hits[1].fields.id"));
 
-    assertEquals(1.60721f, getFloat(result, "hits[0].fields.scoreboost2"), .0001f);
-    assertEquals(0.22092f, getFloat(result, "hits[1].fields.scoreboost2"), .0001f);
+    assertEquals(1.60721f, getFloat("hits[0].fields.scoreboost2"), .0001f);
+    assertEquals(0.22092f, getFloat("hits[1].fields.scoreboost2"), .0001f);
 
-    assertEquals(1.60721f, getFloat(result, "hits[0].fields.sortFields.scoreboost2"), .0001f);
-    assertEquals(0.22092f, getFloat(result, "hits[1].fields.sortFields.scoreboost2"), .0001f);
+    assertEquals(1.60721f, getFloat("hits[0].fields.sortFields.scoreboost2"), .0001f);
+    assertEquals(0.22092f, getFloat("hits[1].fields.sortFields.scoreboost2"), .0001f);
   }
 
   public void testWithScore1() throws Exception {
     deleteAllDocs();
     send("addDocument", "{fields: {text: 'the wind is howling like this swirling storm inside', id: 0, boost: 1.0}}");
-    long gen = getLong(send("addDocument", "{fields: {text: 'I am one with the wind and sky', id: 1, boost: 2.0}}"), "indexGen");
-    JSONObject result = send("search", "{queryText: wind, sort: {fields: [{field: scoreboost, reverse: true}]}, retrieveFields: [id, logboost], searcher: {indexGen: " + gen + "}}");
-    assertEquals(2, getInt(result, "totalHits"));
-    assertEquals(1, getInt(result, "hits[0].fields.id"));
-    assertEquals(0, getInt(result, "hits[1].fields.id"));
+    send("addDocument", "{fields: {text: 'I am one with the wind and sky', id: 1, boost: 2.0}}");
+    send("search", "{queryText: wind, sort: {fields: [{field: scoreboost, reverse: true}]}, retrieveFields: [id, logboost]}");
+    assertEquals(2, getInt("totalHits"));
+    assertEquals(1, getInt("hits[0].fields.id"));
+    assertEquals(0, getInt("hits[1].fields.id"));
 
-    assertEquals(.6931f, getFloat(result, "hits[0].fields.logboost"), .0001f);
-    assertEquals(0.0f, getFloat(result, "hits[1].fields.logboost"), .0001f);
+    assertEquals(.6931f, getFloat("hits[0].fields.logboost"), .0001f);
+    assertEquals(0.0f, getFloat("hits[1].fields.logboost"), .0001f);
   }
 
   /** Also tries to retrieve the scoreboost */
   public void testWithScore2() throws Exception {
     deleteAllDocs();
     send("addDocument", "{fields: {text: 'the wind is howling like this swirling storm inside', id: 0, boost: 1.0}}");
-    long gen = getLong(send("addDocument", "{fields: {text: 'I am one with the wind and sky', id: 1, boost: 2.0}}"), "indexGen");
-    JSONObject result = send("search", "{queryText: wind, sort: {fields: [{field: scoreboost, reverse: true}]}, retrieveFields: [id, scoreboost, logboost], searcher: {indexGen: " + gen + "}}");
-    assertEquals(2, getInt(result, "totalHits"));
-    assertEquals(1, getInt(result, "hits[0].fields.id"));
-    assertEquals(0, getInt(result, "hits[1].fields.id"));
+    send("addDocument", "{fields: {text: 'I am one with the wind and sky', id: 1, boost: 2.0}}");
+    send("search", "{queryText: wind, sort: {fields: [{field: scoreboost, reverse: true}]}, retrieveFields: [id, scoreboost, logboost]}");
+    assertEquals(2, getInt("totalHits"));
+    assertEquals(1, getInt("hits[0].fields.id"));
+    assertEquals(0, getInt("hits[1].fields.id"));
 
-    assertEquals(.80361f, getFloat(result, "hits[0].fields.scoreboost"), .0001f);
-    assertEquals(.11046f, getFloat(result, "hits[1].fields.scoreboost"), .0001f);
+    assertEquals(.80361f, getFloat("hits[0].fields.scoreboost"), .0001f);
+    assertEquals(.11046f, getFloat("hits[1].fields.scoreboost"), .0001f);
 
-    assertEquals(.6931f, getFloat(result, "hits[0].fields.logboost"), .0001f);
-    assertEquals(0.0f, getFloat(result, "hits[1].fields.logboost"), .0001f);
+    assertEquals(.6931f, getFloat("hits[0].fields.logboost"), .0001f);
+    assertEquals(0.0f, getFloat("hits[1].fields.logboost"), .0001f);
   }
 
   /** Sort by not score, and try to retrieve expression
@@ -161,17 +161,17 @@ public class TestVirtualFields extends S
   public void testWithScore3() throws Exception {
     deleteAllDocs();
     send("addDocument", "{fields: {text: 'the wind is howling like this swirling storm inside', id: 0, boost: 1.0}}");
-    long gen = getLong(send("addDocument", "{fields: {text: 'I am one with the wind and sky', id: 1, boost: 2.0}}"), "indexGen");
-    JSONObject result = send("search", "{queryText: wind, sort: {fields: [{field: id, reverse: true}]}, retrieveFields: [id, scoreboost, logboost], searcher: {indexGen: " + gen + "}}");
-    assertEquals(2, getInt(result, "totalHits"));
-    assertEquals(1, getInt(result, "hits[0].fields.id"));
-    assertEquals(0, getInt(result, "hits[1].fields.id"));
+    send("addDocument", "{fields: {text: 'I am one with the wind and sky', id: 1, boost: 2.0}}");
+    send("search", "{queryText: wind, sort: {fields: [{field: id, reverse: true}]}, retrieveFields: [id, scoreboost, logboost]}");
+    assertEquals(2, getInt("totalHits"));
+    assertEquals(1, getInt("hits[0].fields.id"));
+    assertEquals(0, getInt("hits[1].fields.id"));
 
-    assertEquals(.80361f, getFloat(result, "hits[0].fields.scoreboost"), .0001f);
-    assertEquals(.11046f, getFloat(result, "hits[1].fields.scoreboost"), .0001f);
+    assertEquals(.80361f, getFloat("hits[0].fields.scoreboost"), .0001f);
+    assertEquals(.11046f, getFloat("hits[1].fields.scoreboost"), .0001f);
 
-    assertEquals(.6931f, getFloat(result, "hits[0].fields.logboost"), .0001f);
-    assertEquals(0.0f, getFloat(result, "hits[1].fields.logboost"), .0001f);
+    assertEquals(.6931f, getFloat("hits[0].fields.logboost"), .0001f);
+    assertEquals(0.0f, getFloat("hits[1].fields.logboost"), .0001f);
   }
 
   public void testSyntaxError() throws Exception {
@@ -213,7 +213,7 @@ public class TestVirtualFields extends S
   public void testDynamicFieldSameName() throws Exception {
     deleteAllDocs();
     send("addDocument", "{fields: {text: 'the wind is howling like this swirling storm inside', id: 0, boost: 1.0}}");
-    long gen = getLong(send("addDocument", "{fields: {text: 'I am one with the wind and sky', id: 1, boost: 2.0}}"), "indexGen");
+    send("addDocument", "{fields: {text: 'I am one with the wind and sky', id: 1, boost: 2.0}}");
 
     // It's an error to try to define a dynamic field name
     // that already exists:
@@ -226,31 +226,42 @@ public class TestVirtualFields extends S
     }
   }
 
+  public void testCycles1() throws Exception {
+    assertFailsWith("registerFields", "{fields: {bad: {type: virtual, expression: ln(bad)}}}",
+                    "registerFields > fields > bad > expression: could not evaluate expression: java.lang.IllegalArgumentException: Invalid reference 'bad'");
+  }
+
+  public void testCycles2() throws Exception {
+    assertFailsWith("search",
+                    "{queryText: wind, virtualFields: [{name: bad, expression: ln(bad)}]}",
+                    "search > virtualFields[0] > expression: could not evaluate expression: java.lang.IllegalArgumentException: Invalid reference 'bad'");
+  }
+
   public void testRetrievedDynamicField() throws Exception {
     deleteAllDocs();
     send("addDocument", "{fields: {text: 'the wind is howling like this swirling storm inside', id: 0, boost: 1.0}}");
-    long gen = getLong(send("addDocument", "{fields: {text: 'I am one with the wind and sky', id: 1, boost: 2.0}}"), "indexGen");
-    JSONObject result = send("search",
-                             "{queryText: wind, virtualFields: [{name: scoreboost3, expression: 3*scoreboost}], sort: {fields: [{field: id, reverse: true}]}, retrieveFields: [id, scoreboost3], searcher: {indexGen: " + gen + "}}");
-    assertEquals(2, getInt(result, "totalHits"));
-    assertEquals(1, getInt(result, "hits[0].fields.id"));
-    assertEquals(0, getInt(result, "hits[1].fields.id"));
+    send("addDocument", "{fields: {text: 'I am one with the wind and sky', id: 1, boost: 2.0}}");
+    send("search",
+         "{queryText: wind, virtualFields: [{name: scoreboost3, expression: 3*scoreboost}], sort: {fields: [{field: id, reverse: true}]}, retrieveFields: [id, scoreboost3]}");
+    assertEquals(2, getInt("totalHits"));
+    assertEquals(1, getInt("hits[0].fields.id"));
+    assertEquals(0, getInt("hits[1].fields.id"));
 
-    assertEquals(2.41082, getFloat(result, "hits[0].fields.scoreboost3"), .0001f);
-    assertEquals(0.33138, getFloat(result, "hits[1].fields.scoreboost3"), .0001f);
+    assertEquals(2.41082, getFloat("hits[0].fields.scoreboost3"), .0001f);
+    assertEquals(0.33138, getFloat("hits[1].fields.scoreboost3"), .0001f);
   }
 
   public void testSortedDynamicField() throws Exception {
     deleteAllDocs();
     send("addDocument", "{fields: {text: 'the wind is howling like this swirling storm inside', id: 0, boost: 1.0}}");
-    long gen = getLong(send("addDocument", "{fields: {text: 'I am one with the wind and sky', id: 1, boost: 2.0}}"), "indexGen");
-    JSONObject result = send("search",
-                             "{queryText: wind, virtualFields: [{name: scoreboost3, expression: 3*scoreboost}], sort: {fields: [{field: scoreboost3}]}, retrieveFields: [id], searcher: {indexGen: " + gen + "}}");
-    assertEquals(2, getInt(result, "totalHits"));
-    assertEquals(0, getInt(result, "hits[0].fields.id"));
-    assertEquals(1, getInt(result, "hits[1].fields.id"));
+    send("addDocument", "{fields: {text: 'I am one with the wind and sky', id: 1, boost: 2.0}}");
+    send("search",
+         "{queryText: wind, virtualFields: [{name: scoreboost3, expression: 3*scoreboost}], sort: {fields: [{field: scoreboost3}]}, retrieveFields: [id]}");
+    assertEquals(2, getInt("totalHits"));
+    assertEquals(0, getInt("hits[0].fields.id"));
+    assertEquals(1, getInt("hits[1].fields.id"));
 
-    assertEquals(0.33138, getFloat(result, "hits[0].fields.sortFields.scoreboost3"), .0001f);
-    assertEquals(2.41082, getFloat(result, "hits[1].fields.sortFields.scoreboost3"), .0001f);
+    assertEquals(0.33138, getFloat("hits[0].fields.sortFields.scoreboost3"), .0001f);
+    assertEquals(2.41082, getFloat("hits[1].fields.sortFields.scoreboost3"), .0001f);
   }
 }