lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject lucene-solr:branch_6x: LUCENE-7484: FastVectorHighlighter failed to highlight SynonymQuery
Date Mon, 10 Oct 2016 13:13:16 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/branch_6x 2b5fc01a5 -> 6f3eb1453


LUCENE-7484: FastVectorHighlighter failed to highlight SynonymQuery


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

Branch: refs/heads/branch_6x
Commit: 6f3eb145344520cfa5c3609f637583841211550d
Parents: 2b5fc01
Author: Mike McCandless <mikemccand@apache.org>
Authored: Mon Oct 10 09:12:31 2016 -0400
Committer: Mike McCandless <mikemccand@apache.org>
Committed: Mon Oct 10 09:12:52 2016 -0400

----------------------------------------------------------------------
 lucene/CHANGES.txt                              |  3 ++
 .../search/vectorhighlight/FieldQuery.java      |  7 ++++
 .../FastVectorHighlighterTest.java              | 38 ++++++++++++++++++++
 3 files changed, 48 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/6f3eb145/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index d6372b3..b3bcc85 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -26,6 +26,9 @@ Bug Fixes
 * LUCENE-7468: ASCIIFoldingFilter should not emit duplicated tokens when
   preserve original is on. (David Causse via Adrien Grand)
 
+* LUCENE-7484: FastVectorHighlighter failed to highlight SynonymQuery
+  (Jim Ferenczi via Mike McCandless)
+
 Improvements
 
 * LUCENE-7439: FuzzyQuery now matches all terms within the specified

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/6f3eb145/lucene/highlighter/src/java/org/apache/lucene/search/vectorhighlight/FieldQuery.java
----------------------------------------------------------------------
diff --git a/lucene/highlighter/src/java/org/apache/lucene/search/vectorhighlight/FieldQuery.java
b/lucene/highlighter/src/java/org/apache/lucene/search/vectorhighlight/FieldQuery.java
index 8abeaff..0fd336a 100644
--- a/lucene/highlighter/src/java/org/apache/lucene/search/vectorhighlight/FieldQuery.java
+++ b/lucene/highlighter/src/java/org/apache/lucene/search/vectorhighlight/FieldQuery.java
@@ -36,6 +36,7 @@ import org.apache.lucene.search.DisjunctionMaxQuery;
 import org.apache.lucene.search.MultiTermQuery;
 import org.apache.lucene.search.PhraseQuery;
 import org.apache.lucene.search.Query;
+import org.apache.lucene.search.SynonymQuery;
 import org.apache.lucene.search.TermQuery;
 import org.apache.lucene.search.join.ToParentBlockJoinQuery;
 import org.apache.lucene.search.vectorhighlight.FieldTermStack.TermInfo;
@@ -120,6 +121,12 @@ public class FieldQuery {
       if( !flatQueries.contains( sourceQuery ) )
         flatQueries.add( sourceQuery );
     }
+    else if ( sourceQuery instanceof SynonymQuery ){
+      SynonymQuery synQuery = (SynonymQuery) sourceQuery;
+      for( Term term : synQuery.getTerms()) {
+        flatten( new TermQuery(term), reader, flatQueries, boost);
+      }
+    }
     else if( sourceQuery instanceof PhraseQuery ){
       PhraseQuery pq = (PhraseQuery)sourceQuery;
       if( pq.getTerms().length == 1 )

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/6f3eb145/lucene/highlighter/src/test/org/apache/lucene/search/vectorhighlight/FastVectorHighlighterTest.java
----------------------------------------------------------------------
diff --git a/lucene/highlighter/src/test/org/apache/lucene/search/vectorhighlight/FastVectorHighlighterTest.java
b/lucene/highlighter/src/test/org/apache/lucene/search/vectorhighlight/FastVectorHighlighterTest.java
index 5a2d5a0..89f46af 100644
--- a/lucene/highlighter/src/test/org/apache/lucene/search/vectorhighlight/FastVectorHighlighterTest.java
+++ b/lucene/highlighter/src/test/org/apache/lucene/search/vectorhighlight/FastVectorHighlighterTest.java
@@ -46,6 +46,7 @@ import org.apache.lucene.search.BoostQuery;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.PhraseQuery;
 import org.apache.lucene.search.Query;
+import org.apache.lucene.search.SynonymQuery;
 import org.apache.lucene.search.TermQuery;
 import org.apache.lucene.search.TopDocs;
 import org.apache.lucene.search.highlight.DefaultEncoder;
@@ -521,6 +522,43 @@ public class FastVectorHighlighterTest extends LuceneTestCase {
     writer.close();
     dir.close();
   }
+
+  public void testWithSynonym() throws IOException {
+    Directory dir = newDirectory();
+    IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random())));
+    FieldType type = new FieldType(TextField.TYPE_STORED);
+    type.setStoreTermVectorOffsets(true);
+    type.setStoreTermVectorPositions(true);
+    type.setStoreTermVectors(true);
+    type.freeze();
+
+    Document doc = new Document();
+    doc.add( new Field("field", "the quick brown fox", type ));
+    writer.addDocument(doc);
+    FastVectorHighlighter highlighter = new FastVectorHighlighter();
+
+    IndexReader reader = DirectoryReader.open(writer);
+    int docId = 0;
+
+    // query1: simple synonym query
+    SynonymQuery synQuery = new SynonymQuery(new Term("field", "quick"), new Term("field",
"fast"));
+    FieldQuery fieldQuery  = highlighter.getFieldQuery(synQuery, reader);
+    String[] bestFragments = highlighter.getBestFragments(fieldQuery, reader, docId, "field",
54, 1);
+    assertEquals("the <b>quick</b> brown fox", bestFragments[0]);
+
+    // query2: boolean query with synonym query
+    BooleanQuery.Builder bq =
+        new BooleanQuery.Builder()
+            .add(new BooleanClause(synQuery, Occur.MUST))
+            .add(new BooleanClause(new TermQuery(new Term("field", "fox")), Occur.MUST));
+    fieldQuery  = highlighter.getFieldQuery(bq.build(), reader);
+    bestFragments = highlighter.getBestFragments(fieldQuery, reader, docId, "field", 54,
1);
+    assertEquals("the <b>quick</b> brown <b>fox</b>", bestFragments[0]);
+
+    reader.close();
+    writer.close();
+    dir.close();
+  }
   
   public void testBooleanPhraseWithSynonym() throws IOException {
     Directory dir = newDirectory();


Mime
View raw message