lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r888096 - in /lucene/solr/trunk: CHANGES.txt src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java src/test/org/apache/solr/highlight/HighlighterTest.java
Date Mon, 07 Dec 2009 19:24:23 GMT
Author: yonik
Date: Mon Dec  7 19:24:15 2009
New Revision: 888096

URL: http://svn.apache.org/viewvc?rev=888096&view=rev
Log:
SOLR-1624: Highlighter bug w/ term positons stored and multi valued field

Modified:
    lucene/solr/trunk/CHANGES.txt
    lucene/solr/trunk/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java
    lucene/solr/trunk/src/test/org/apache/solr/highlight/HighlighterTest.java

Modified: lucene/solr/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/CHANGES.txt?rev=888096&r1=888095&r2=888096&view=diff
==============================================================================
--- lucene/solr/trunk/CHANGES.txt (original)
+++ lucene/solr/trunk/CHANGES.txt Mon Dec  7 19:24:15 2009
@@ -110,6 +110,10 @@
 * SOLR-1628: log contains incorrect number of adds and deletes. 
   (Thijs Vonk via yonik)
 
+* SOLR-1624: Highlighter only highlights values from the first field  value
+  in a multivalued field when term positions (term vectors) are stored.
+  (Chris Harris via yonik)
+
 
 Other Changes
 ----------------------

Modified: lucene/solr/trunk/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java?rev=888096&r1=888095&r2=888096&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/highlight/DefaultSolrHighlighter.java Mon Dec
 7 19:24:15 2009
@@ -284,23 +284,24 @@
 
           String[] summaries = null;
           List<TextFragment> frags = new ArrayList<TextFragment>();
-          TermOffsetsTokenStream tots = null;
-          for (int j = 0; j < docTexts.length; j++) {
-            // create TokenStream
-            try {
-              // attempt term vectors
-              if( tots == null ) {
-                TokenStream tvStream = TokenSources.getTokenStream(searcher.getReader(),
docId, fieldName);
-                if (tvStream != null) {
-                  tots = new TermOffsetsTokenStream(tvStream);
-                  tstream = tots.getMultiValuedTokenStream( docTexts[j].length() );
-                } else {
-                  // fall back to analyzer
-                  tstream = createAnalyzerTStream(schema, fieldName, docTexts[j]);
-                }
+
+          TermOffsetsTokenStream tots = null; // to be non-null iff we're using TermOffsets
optimization
+          try {
+              TokenStream tvStream = TokenSources.getTokenStream(searcher.getReader(), docId,
fieldName);
+              if (tvStream != null) {
+                tots = new TermOffsetsTokenStream(tvStream);
               }
-            }
-            catch (IllegalArgumentException e) {
+          }
+          catch (IllegalArgumentException e) {
+            // No problem. But we can't use TermOffsets optimization.
+          }
+
+          for (int j = 0; j < docTexts.length; j++) {
+            if( tots != null ) {
+              // if we're using TermOffsets optimization, then get the next
+              // field value's TokenStream (i.e. get field j's TokenStream) from tots:
+              tstream = tots.getMultiValuedTokenStream( docTexts[j].length() );
+            } else {
               // fall back to analyzer
               tstream = createAnalyzerTStream(schema, fieldName, docTexts[j]);
             }

Modified: lucene/solr/trunk/src/test/org/apache/solr/highlight/HighlighterTest.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/test/org/apache/solr/highlight/HighlighterTest.java?rev=888096&r1=888095&r2=888096&view=diff
==============================================================================
--- lucene/solr/trunk/src/test/org/apache/solr/highlight/HighlighterTest.java (original)
+++ lucene/solr/trunk/src/test/org/apache/solr/highlight/HighlighterTest.java Mon Dec  7 19:24:15
2009
@@ -190,6 +190,33 @@
             );
   }
 
+  // Variant of testTermVecMultiValuedHighlight to make sure that
+  // more than just the first value of a multi-valued field is
+  // considered for highlighting.
+  public void testTermVecMultiValuedHighlight2() throws Exception {
+
+    // do summarization using term vectors on multivalued field
+    HashMap<String,String> args = new HashMap<String,String>();
+    args.put("hl", "true");
+    args.put("hl.fl", "tv_mv_text");
+    args.put("hl.snippets", "2");
+    TestHarness.LocalRequestFactory sumLRF = h.getRequestFactory(
+      "standard",0,200,args);
+
+    String shortText = "short";
+    assertU(adoc("tv_mv_text", shortText,
+                 "tv_mv_text", LONG_TEXT,
+                 "id", "1"));
+    assertU(commit());
+    assertU(optimize());
+    assertQ("Basic summarization",
+            sumLRF.makeRequest("tv_mv_text:long"),
+            "//lst[@name='highlighting']/lst[@name='1']",
+            "//lst[@name='1']/arr[@name='tv_mv_text']/str[.='a <em>long</em>
days night this should be a piece of text which']",
+            "//arr[@name='tv_mv_text']/str[.=' <em>long</em> fragments.']"
+            );
+  }
+
   public void testDisMaxHighlight() {
 
     // same test run through dismax handler



Mime
View raw message