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 2013/10/08 13:28:51 UTC

svn commit: r1530231 - in /lucene/dev/branches/branch_4x: ./ lucene/ lucene/suggest/ lucene/suggest/src/java/org/apache/lucene/search/suggest/ lucene/suggest/src/test/org/apache/lucene/search/suggest/

Author: mikemccand
Date: Tue Oct  8 11:28:51 2013
New Revision: 1530231

URL: http://svn.apache.org/r1530231
Log:
LUCENE-5251: add DocumentDictionary

Added:
    lucene/dev/branches/branch_4x/lucene/suggest/src/java/org/apache/lucene/search/suggest/DocumentDictionary.java
      - copied, changed from r1530229, lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/suggest/DocumentDictionary.java
    lucene/dev/branches/branch_4x/lucene/suggest/src/test/org/apache/lucene/search/suggest/DocumentDictionaryTest.java
      - copied, changed from r1530229, lucene/dev/trunk/lucene/suggest/src/test/org/apache/lucene/search/suggest/DocumentDictionaryTest.java
Modified:
    lucene/dev/branches/branch_4x/   (props changed)
    lucene/dev/branches/branch_4x/lucene/   (props changed)
    lucene/dev/branches/branch_4x/lucene/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/branch_4x/lucene/suggest/   (props changed)

Modified: lucene/dev/branches/branch_4x/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/CHANGES.txt?rev=1530231&r1=1530230&r2=1530231&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/branch_4x/lucene/CHANGES.txt Tue Oct  8 11:28:51 2013
@@ -42,6 +42,10 @@ New Features
   tail" suggestions, when a primary suggester fails to find a
   suggestion.  (Mike McCandless)
 
+* LUCENE-5251: New DocumentDictionary allows building suggesters via
+  contents of existing field, weight and optionally payload stored
+  fields in an index (Areek Zillur via Mike McCandless)
+
 Bug Fixes
 
 * LUCENE-4998: Fixed a few places to pass IOContext.READONCE instead

Copied: lucene/dev/branches/branch_4x/lucene/suggest/src/java/org/apache/lucene/search/suggest/DocumentDictionary.java (from r1530229, lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/suggest/DocumentDictionary.java)
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/suggest/src/java/org/apache/lucene/search/suggest/DocumentDictionary.java?p2=lucene/dev/branches/branch_4x/lucene/suggest/src/java/org/apache/lucene/search/suggest/DocumentDictionary.java&p1=lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/suggest/DocumentDictionary.java&r1=1530229&r2=1530231&rev=1530231&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/suggest/src/java/org/apache/lucene/search/suggest/DocumentDictionary.java (original)
+++ lucene/dev/branches/branch_4x/lucene/suggest/src/java/org/apache/lucene/search/suggest/DocumentDictionary.java Tue Oct  8 11:28:51 2013
@@ -18,14 +18,15 @@ package org.apache.lucene.search.suggest
  */
 import java.io.IOException;
 import java.util.Arrays;
+import java.util.Comparator;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
+import org.apache.lucene.document.Document;
 import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexableField;
 import org.apache.lucene.index.MultiFields;
-import org.apache.lucene.index.StorableField;
-import org.apache.lucene.index.StoredDocument;
 import org.apache.lucene.search.spell.Dictionary;
 import org.apache.lucene.search.spell.TermFreqPayloadIterator;
 import org.apache.lucene.search.suggest.analyzing.AnalyzingInfixSuggester; // javadoc
@@ -117,7 +118,7 @@ public class DocumentDictionary implemen
       } else {
         relevantFieldList = Arrays.asList(field, weightField);
       }
-      this.relevantFields = new HashSet<>(relevantFieldList);
+      this.relevantFields = new HashSet<String>(relevantFieldList);
     }
 
     @Override
@@ -126,6 +127,11 @@ public class DocumentDictionary implemen
     }
 
     @Override
+    public Comparator<BytesRef> getComparator() {
+      return null;
+    }
+
+    @Override
     public BytesRef next() throws IOException {
       while (currentDocId < docCount) {
         currentDocId++;
@@ -133,10 +139,10 @@ public class DocumentDictionary implemen
           continue;
         }
 
-        StoredDocument doc = reader.document(currentDocId, relevantFields);
+        Document doc = reader.document(currentDocId, relevantFields);
         
         if (withPayload) {
-          StorableField payload = doc.getField(payloadField);
+          IndexableField payload = doc.getField(payloadField);
           if (payload == null) {
             throw new IllegalArgumentException(payloadField + " does not exist");
           } else if (payload.binaryValue() == null) {
@@ -145,7 +151,7 @@ public class DocumentDictionary implemen
           currentPayload = payload.binaryValue();
         }
         
-        StorableField weight = doc.getField(weightField);
+        IndexableField weight = doc.getField(weightField);
         if (weight == null) {
           throw new IllegalArgumentException(weightField + " does not exist");
         } else if (weight.numericValue() == null) {
@@ -153,7 +159,7 @@ public class DocumentDictionary implemen
         }
         currentWeight = weight.numericValue().longValue();
         
-        StorableField fieldVal = doc.getField(field);
+        IndexableField fieldVal = doc.getField(field);
         if (fieldVal == null) {
           throw new IllegalArgumentException(field + " does not exist");
         } else if(fieldVal.stringValue() == null) {

Copied: lucene/dev/branches/branch_4x/lucene/suggest/src/test/org/apache/lucene/search/suggest/DocumentDictionaryTest.java (from r1530229, lucene/dev/trunk/lucene/suggest/src/test/org/apache/lucene/search/suggest/DocumentDictionaryTest.java)
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/suggest/src/test/org/apache/lucene/search/suggest/DocumentDictionaryTest.java?p2=lucene/dev/branches/branch_4x/lucene/suggest/src/test/org/apache/lucene/search/suggest/DocumentDictionaryTest.java&p1=lucene/dev/trunk/lucene/suggest/src/test/org/apache/lucene/search/suggest/DocumentDictionaryTest.java&r1=1530229&r2=1530231&rev=1530231&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/suggest/src/test/org/apache/lucene/search/suggest/DocumentDictionaryTest.java (original)
+++ lucene/dev/branches/branch_4x/lucene/suggest/src/test/org/apache/lucene/search/suggest/DocumentDictionaryTest.java Tue Oct  8 11:28:51 2013
@@ -50,7 +50,7 @@ public class DocumentDictionaryTest exte
   static final String PAYLOAD_FIELD_NAME = "p1";
   
   private Map<String, Document> generateIndexDocuments(int ndocs) {
-    Map<String, Document> docs = new HashMap<>();
+    Map<String, Document> docs = new HashMap<String,Document>();
     for(int i = 0; i < ndocs ; i++) {
       Field field = new TextField(FIELD_NAME, "field_" + i, Field.Store.YES);
       Field payload = new StoredField(PAYLOAD_FIELD_NAME, new BytesRef("payload_" + i));
@@ -126,7 +126,7 @@ public class DocumentDictionaryTest exte
     RandomIndexWriter writer = new RandomIndexWriter(random(), dir, iwc);
     Map<String, Document> docs = generateIndexDocuments(10);
     Random rand = random();
-    List<String> termsToDel = new ArrayList<>();
+    List<String> termsToDel = new ArrayList<String>();
     for(Document doc : docs.values()) {
       if(rand.nextBoolean()) {
         termsToDel.add(doc.get(FIELD_NAME));