Search in sources :

Example 16 with TestHighlightRunner

use of org.apache.lucene.search.highlight.SynonymTokenizer.TestHighlightRunner in project lucene-solr by apache.

the class SynonymTokenizer method testGetRangeFragments.

public void testGetRangeFragments() throws Exception {
    TestHighlightRunner helper = new TestHighlightRunner() {

        @Override
        public void run() throws Exception {
            numHighlights = 0;
            // Need to explicitly set the QueryParser property to use TermRangeQuery
            // rather
            // than RangeFilters
            TermRangeQuery rangeQuery = new TermRangeQuery(FIELD_NAME, new BytesRef("kannedy"), new BytesRef("kznnedy"), true, true);
            rangeQuery.setRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_REWRITE);
            query = rangeQuery;
            doSearching(query);
            doStandardHighlights(analyzer, searcher, hits, query, HighlighterTest.this);
            assertTrue("Failed to find correct number of highlights " + numHighlights + " found", numHighlights == 5);
        }
    };
    helper.start();
}
Also used : TestHighlightRunner(org.apache.lucene.search.highlight.SynonymTokenizer.TestHighlightRunner) TermRangeQuery(org.apache.lucene.search.TermRangeQuery) BytesRef(org.apache.lucene.util.BytesRef)

Example 17 with TestHighlightRunner

use of org.apache.lucene.search.highlight.SynonymTokenizer.TestHighlightRunner in project lucene-solr by apache.

the class SynonymTokenizer method testOverlapAnalyzer.

// tests a "complex" analyzer that produces multiple
// overlapping tokens
public void testOverlapAnalyzer() throws Exception {
    TestHighlightRunner helper = new TestHighlightRunner() {

        @Override
        public void run() throws Exception {
            HashMap<String, String> synonyms = new HashMap<>();
            synonyms.put("football", "soccer,footie");
            Analyzer analyzer = new SynonymAnalyzer(synonyms);
            String s = "football-soccer in the euro 2004 footie competition";
            BooleanQuery.Builder query = new BooleanQuery.Builder();
            query.add(new TermQuery(new Term("bookid", "football")), Occur.SHOULD);
            query.add(new TermQuery(new Term("bookid", "soccer")), Occur.SHOULD);
            query.add(new TermQuery(new Term("bookid", "footie")), Occur.SHOULD);
            Highlighter highlighter = getHighlighter(query.build(), null, HighlighterTest.this);
            // Get 3 best fragments and separate with a "..."
            TokenStream tokenStream = analyzer.tokenStream(null, s);
            String result = highlighter.getBestFragments(tokenStream, s, 3, "...");
            String expectedResult = "<B>football</B>-<B>soccer</B> in the euro 2004 <B>footie</B> competition";
            assertTrue("overlapping analyzer should handle highlights OK, expected:" + expectedResult + " actual:" + result, expectedResult.equals(result));
        }
    };
    helper.start();
}
Also used : BooleanQuery(org.apache.lucene.search.BooleanQuery) MultiTermQuery(org.apache.lucene.search.MultiTermQuery) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) TermQuery(org.apache.lucene.search.TermQuery) TestHighlightRunner(org.apache.lucene.search.highlight.SynonymTokenizer.TestHighlightRunner) CannedTokenStream(org.apache.lucene.analysis.CannedTokenStream) TokenStream(org.apache.lucene.analysis.TokenStream) HashMap(java.util.HashMap) Builder(org.apache.lucene.search.PhraseQuery.Builder) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Term(org.apache.lucene.index.Term) MockAnalyzer(org.apache.lucene.analysis.MockAnalyzer) MockPayloadAnalyzer(org.apache.lucene.analysis.MockPayloadAnalyzer) Analyzer(org.apache.lucene.analysis.Analyzer)

Example 18 with TestHighlightRunner

use of org.apache.lucene.search.highlight.SynonymTokenizer.TestHighlightRunner in project lucene-solr by apache.

the class SynonymTokenizer method testGetBestFragmentsPhrase.

public void testGetBestFragmentsPhrase() throws Exception {
    TestHighlightRunner helper = new TestHighlightRunner() {

        @Override
        public void run() throws Exception {
            numHighlights = 0;
            PhraseQuery phraseQuery = new PhraseQuery(FIELD_NAME, "john", "kennedy");
            doSearching(phraseQuery);
            doStandardHighlights(analyzer, searcher, hits, query, HighlighterTest.this);
            // Currently highlights "John" and "Kennedy" separately
            assertTrue("Failed to find correct number of highlights " + numHighlights + " found", numHighlights == 2);
        }
    };
    helper.start();
}
Also used : TestHighlightRunner(org.apache.lucene.search.highlight.SynonymTokenizer.TestHighlightRunner) PhraseQuery(org.apache.lucene.search.PhraseQuery) MultiPhraseQuery(org.apache.lucene.search.MultiPhraseQuery)

Example 19 with TestHighlightRunner

use of org.apache.lucene.search.highlight.SynonymTokenizer.TestHighlightRunner in project lucene-solr by apache.

the class SynonymTokenizer method testGetFuzzyFragments.

public void testGetFuzzyFragments() throws Exception {
    TestHighlightRunner helper = new TestHighlightRunner() {

        @Override
        public void run() throws Exception {
            numHighlights = 0;
            FuzzyQuery fuzzyQuery = new FuzzyQuery(new Term(FIELD_NAME, "kinnedy"), 2);
            fuzzyQuery.setRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_REWRITE);
            doSearching(fuzzyQuery);
            doStandardHighlights(analyzer, searcher, hits, query, HighlighterTest.this, true);
            assertTrue("Failed to find correct number of highlights " + numHighlights + " found", numHighlights == 4);
        }
    };
    helper.start();
}
Also used : TestHighlightRunner(org.apache.lucene.search.highlight.SynonymTokenizer.TestHighlightRunner) FuzzyQuery(org.apache.lucene.search.FuzzyQuery) Term(org.apache.lucene.index.Term)

Example 20 with TestHighlightRunner

use of org.apache.lucene.search.highlight.SynonymTokenizer.TestHighlightRunner in project lucene-solr by apache.

the class SynonymTokenizer method testGetMidWildCardFragments.

public void testGetMidWildCardFragments() throws Exception {
    TestHighlightRunner helper = new TestHighlightRunner() {

        @Override
        public void run() throws Exception {
            numHighlights = 0;
            WildcardQuery wildcardQuery = new WildcardQuery(new Term(FIELD_NAME, "k*dy"));
            wildcardQuery.setRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_REWRITE);
            doSearching(wildcardQuery);
            doStandardHighlights(analyzer, searcher, hits, query, HighlighterTest.this);
            assertTrue("Failed to find correct number of highlights " + numHighlights + " found", numHighlights == 5);
        }
    };
    helper.start();
}
Also used : WildcardQuery(org.apache.lucene.search.WildcardQuery) TestHighlightRunner(org.apache.lucene.search.highlight.SynonymTokenizer.TestHighlightRunner) Term(org.apache.lucene.index.Term)

Aggregations

TestHighlightRunner (org.apache.lucene.search.highlight.SynonymTokenizer.TestHighlightRunner)28 Term (org.apache.lucene.index.Term)24 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)20 MultiTermQuery (org.apache.lucene.search.MultiTermQuery)16 TermQuery (org.apache.lucene.search.TermQuery)16 DocumentBuilder (javax.xml.parsers.DocumentBuilder)10 BooleanQuery (org.apache.lucene.search.BooleanQuery)10 Builder (org.apache.lucene.search.PhraseQuery.Builder)10 CannedTokenStream (org.apache.lucene.analysis.CannedTokenStream)8 TokenStream (org.apache.lucene.analysis.TokenStream)8 SpanNearQuery (org.apache.lucene.search.spans.SpanNearQuery)6 IntPoint (org.apache.lucene.document.IntPoint)5 WildcardQuery (org.apache.lucene.search.WildcardQuery)5 SpanQuery (org.apache.lucene.search.spans.SpanQuery)5 MultiPhraseQuery (org.apache.lucene.search.MultiPhraseQuery)4 PhraseQuery (org.apache.lucene.search.PhraseQuery)4 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)3 Document (org.apache.lucene.document.Document)3 ConstantScoreQuery (org.apache.lucene.search.ConstantScoreQuery)3 FuzzyQuery (org.apache.lucene.search.FuzzyQuery)3