lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jpou...@apache.org
Subject [1/3] lucene-solr:master: LUCENE-7286: Added support for highlighting SynonymQuery.
Date Fri, 10 Jun 2016 07:12:59 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/branch_6_1 e0c6762de -> 5e87c2b31
  refs/heads/branch_6x 74d94ec26 -> ef707f05a
  refs/heads/master 387143997 -> e418bd0eb


LUCENE-7286: Added support for highlighting 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/e418bd0e
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/e418bd0e
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/e418bd0e

Branch: refs/heads/master
Commit: e418bd0eb33eb058c0403dfcdaef8733bd6f4fc1
Parents: 3871439
Author: Adrien Grand <jpountz@gmail.com>
Authored: Fri Jun 10 09:11:15 2016 +0200
Committer: Adrien Grand <jpountz@gmail.com>
Committed: Fri Jun 10 09:11:15 2016 +0200

----------------------------------------------------------------------
 lucene/CHANGES.txt                              |  2 ++
 .../highlight/WeightedSpanTermExtractor.java    |  3 ++-
 .../search/highlight/HighlighterTest.java       | 21 +++++++++++++++++++-
 3 files changed, 24 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/e418bd0e/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 20df7b2..279fc4d 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -134,6 +134,8 @@ Bug Fixes
   other ranges had more than one clause matching (Ahmet Arslan,
   hossman, Mike McCandless)
 
+* LUCENE-7286: Added support for highlighting SynonymQuery. (Adrien Grand)
+
 Other
 
 * LUCENE-7295: TermAutomatonQuery.hashCode calculates Automaton.toDot().hash,

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/e418bd0e/lucene/highlighter/src/java/org/apache/lucene/search/highlight/WeightedSpanTermExtractor.java
----------------------------------------------------------------------
diff --git a/lucene/highlighter/src/java/org/apache/lucene/search/highlight/WeightedSpanTermExtractor.java
b/lucene/highlighter/src/java/org/apache/lucene/search/highlight/WeightedSpanTermExtractor.java
index 43f75cc..7507bdd 100644
--- a/lucene/highlighter/src/java/org/apache/lucene/search/highlight/WeightedSpanTermExtractor.java
+++ b/lucene/highlighter/src/java/org/apache/lucene/search/highlight/WeightedSpanTermExtractor.java
@@ -53,6 +53,7 @@ import org.apache.lucene.search.MultiPhraseQuery;
 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.ToChildBlockJoinQuery;
 import org.apache.lucene.search.join.ToParentBlockJoinQuery;
@@ -138,7 +139,7 @@ public class WeightedSpanTermExtractor {
         SpanNearQuery sp = new SpanNearQuery(clauses, phraseQuery.getSlop() + positionGaps,
inorder);
         extractWeightedSpanTerms(terms, sp, boost);
       }
-    } else if (query instanceof TermQuery) {
+    } else if (query instanceof TermQuery || query instanceof SynonymQuery) {
       extractWeightedTerms(terms, query, boost);
     } else if (query instanceof SpanQuery) {
       extractWeightedSpanTerms(terms, (SpanQuery) query, boost);

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/e418bd0e/lucene/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java
----------------------------------------------------------------------
diff --git a/lucene/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java
b/lucene/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java
index 3c6f108..cf727d7 100644
--- a/lucene/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java
+++ b/lucene/highlighter/src/test/org/apache/lucene/search/highlight/HighlighterTest.java
@@ -71,6 +71,7 @@ import org.apache.lucene.search.PhraseQuery.Builder;
 import org.apache.lucene.search.PrefixQuery;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.RegexpQuery;
+import org.apache.lucene.search.SynonymQuery;
 import org.apache.lucene.search.TermQuery;
 import org.apache.lucene.search.TermRangeQuery;
 import org.apache.lucene.search.TopDocs;
@@ -223,6 +224,24 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements
Formatte
     assertEquals("This piece of text refers to Kennedy at the beginning then has a longer
piece of text that is <B>very</B>", fragment);
   }
 
+  public void testHighlightingSynonymQuery() throws Exception {
+    searcher = newSearcher(reader);
+    Query query = new SynonymQuery(new Term(FIELD_NAME, "jfk"), new Term(FIELD_NAME, "kennedy"));
+    QueryScorer scorer = new QueryScorer(query, FIELD_NAME);
+    Highlighter highlighter = new Highlighter(scorer);
+    TokenStream stream = getAnyTokenStream(FIELD_NAME, 2);
+    Fragmenter fragmenter = new SimpleSpanFragmenter(scorer);
+    highlighter.setTextFragmenter(fragmenter);
+    String storedField = searcher.doc(2).get(FIELD_NAME);
+    String fragment = highlighter.getBestFragment(stream, storedField);
+    assertEquals("<B>JFK</B> has been shot", fragment);
+
+    stream = getAnyTokenStream(FIELD_NAME, 3);
+    storedField = searcher.doc(3).get(FIELD_NAME);
+    fragment = highlighter.getBestFragment(stream, storedField);
+    assertEquals("John <B>Kennedy</B> has been shot", fragment);
+  }
+
   public void testHighlightUnknownQueryAfterRewrite() throws IOException, InvalidTokenOffsetsException
{
     Query query = new Query() {
       
@@ -2093,7 +2112,7 @@ public class HighlighterTest extends BaseTokenStreamTestCase implements
Formatte
     analyzer = new MockAnalyzer(random(), MockTokenizer.SIMPLE, true, MockTokenFilter.ENGLISH_STOPSET);
     ramDir = newDirectory();
     fieldType = random().nextBoolean() ? FIELD_TYPE_TV : TextField.TYPE_STORED;
-    IndexWriter writer = new IndexWriter(ramDir, newIndexWriterConfig(analyzer));
+    IndexWriter writer = new IndexWriter(ramDir, newIndexWriterConfig(analyzer).setMergePolicy(newLogMergePolicy()));
 
     for (String text : texts) {
       writer.addDocument(doc(FIELD_NAME, text));


Mime
View raw message