lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From markrmil...@apache.org
Subject svn commit: r804786 - in /lucene/java/trunk/contrib/fast-vector-highlighter/src: java/org/apache/lucene/search/vectorhighlight/BaseFragmentsBuilder.java test/org/apache/lucene/search/vectorhighlight/SimpleFragmentsBuilderTest.java
Date Sun, 16 Aug 2009 21:56:51 GMT
Author: markrmiller
Date: Sun Aug 16 21:56:51 2009
New Revision: 804786

URL: http://svn.apache.org/viewvc?rev=804786&view=rev
Log:
LUCENE-1522 fix + test

Modified:
    lucene/java/trunk/contrib/fast-vector-highlighter/src/java/org/apache/lucene/search/vectorhighlight/BaseFragmentsBuilder.java
    lucene/java/trunk/contrib/fast-vector-highlighter/src/test/org/apache/lucene/search/vectorhighlight/SimpleFragmentsBuilderTest.java

Modified: lucene/java/trunk/contrib/fast-vector-highlighter/src/java/org/apache/lucene/search/vectorhighlight/BaseFragmentsBuilder.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/fast-vector-highlighter/src/java/org/apache/lucene/search/vectorhighlight/BaseFragmentsBuilder.java?rev=804786&r1=804785&r2=804786&view=diff
==============================================================================
--- lucene/java/trunk/contrib/fast-vector-highlighter/src/java/org/apache/lucene/search/vectorhighlight/BaseFragmentsBuilder.java
(original)
+++ lucene/java/trunk/contrib/fast-vector-highlighter/src/java/org/apache/lucene/search/vectorhighlight/BaseFragmentsBuilder.java
Sun Aug 16 21:56:51 2009
@@ -73,6 +73,7 @@
     
     List<String> fragments = new ArrayList<String>( maxNumFragments );
     String[] values = getFieldValues( reader, docId, fieldName );
+    if( values.length == 0 ) return null;
     StringBuilder buffer = new StringBuilder();
     int[] nextValueIndex = { 0 };
     for( int n = 0; n < maxNumFragments && n < fragInfos.size(); n++ ){
@@ -84,7 +85,7 @@
   
   protected String[] getFieldValues( IndexReader reader, int docId, String fieldName) throws
IOException {
     Document doc = reader.document( docId, new MapFieldSelector( new String[]{ fieldName
} ) );
-    return doc.getValues( fieldName );
+    return doc.getValues( fieldName ); // according to Document class javadoc, this never
returns null
   }
 
   protected String makeFragment( StringBuilder buffer, int[] index, String[] values, WeightedFragInfo
fragInfo ){

Modified: lucene/java/trunk/contrib/fast-vector-highlighter/src/test/org/apache/lucene/search/vectorhighlight/SimpleFragmentsBuilderTest.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/fast-vector-highlighter/src/test/org/apache/lucene/search/vectorhighlight/SimpleFragmentsBuilderTest.java?rev=804786&r1=804785&r2=804786&view=diff
==============================================================================
--- lucene/java/trunk/contrib/fast-vector-highlighter/src/test/org/apache/lucene/search/vectorhighlight/SimpleFragmentsBuilderTest.java
(original)
+++ lucene/java/trunk/contrib/fast-vector-highlighter/src/test/org/apache/lucene/search/vectorhighlight/SimpleFragmentsBuilderTest.java
Sun Aug 16 21:56:51 2009
@@ -17,6 +17,15 @@
  * limitations under the License.
  */
 
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.document.Field.Index;
+import org.apache.lucene.document.Field.Store;
+import org.apache.lucene.document.Field.TermVector;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexWriter;
+import org.apache.lucene.index.IndexWriter.MaxFieldLength;
 import org.apache.lucene.search.Query;
 
 public class SimpleFragmentsBuilderTest extends AbstractTestCase {
@@ -96,4 +105,26 @@
     SimpleFragmentsBuilder sfb = new SimpleFragmentsBuilder();
     assertEquals( "ssing <b>speed</b>, the", sfb.createFragment( reader, 0, F,
ffl ) );
   }
+  
+  public void testUnstoredField() throws Exception {
+    makeUnstoredIndex();
+
+    FieldQuery fq = new FieldQuery( tq( "aaa" ), true, true );
+    FieldTermStack stack = new FieldTermStack( reader, 0, F, fq );
+    FieldPhraseList fpl = new FieldPhraseList( stack, fq );
+    SimpleFragListBuilder sflb = new SimpleFragListBuilder();
+    FieldFragList ffl = sflb.createFieldFragList( fpl, 100 );
+    SimpleFragmentsBuilder sfb = new SimpleFragmentsBuilder();
+    assertNull( sfb.createFragment( reader, 0, F, ffl ) );
+  }
+  
+  protected void makeUnstoredIndex() throws Exception {
+    IndexWriter writer = new IndexWriter( dir, analyzerW, true, MaxFieldLength.LIMITED );
+    Document doc = new Document();
+    doc.add( new Field( F, "aaa", Store.NO, Index.ANALYZED, TermVector.WITH_POSITIONS_OFFSETS
) );
+    writer.addDocument( doc );
+    writer.close();
+
+    reader = IndexReader.open( dir );
+  }
 }



Mime
View raw message