mirror of https://github.com/apache/lucene.git
LUCENE-2243: Add DisjunctionMaxQuery support for FastVectorHighlighter
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@904776 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
537bb742cd
commit
65e1223ac4
|
@ -96,6 +96,9 @@ New features
|
||||||
and Swedish. These can be loaded with WordListLoader.getSnowballWordSet.
|
and Swedish. These can be loaded with WordListLoader.getSnowballWordSet.
|
||||||
(Robert Muir, Simon Willnauer)
|
(Robert Muir, Simon Willnauer)
|
||||||
|
|
||||||
|
* LUCENE-2243: Add DisjunctionMaxQuery support for FastVectorHighlighter.
|
||||||
|
(Koji Sekiguchi)
|
||||||
|
|
||||||
Build
|
Build
|
||||||
|
|
||||||
* LUCENE-2124: Moved the JDK-based collation support from contrib/collation
|
* LUCENE-2124: Moved the JDK-based collation support from contrib/collation
|
||||||
|
|
|
@ -27,6 +27,7 @@ import java.util.Set;
|
||||||
import org.apache.lucene.index.Term;
|
import org.apache.lucene.index.Term;
|
||||||
import org.apache.lucene.search.BooleanClause;
|
import org.apache.lucene.search.BooleanClause;
|
||||||
import org.apache.lucene.search.BooleanQuery;
|
import org.apache.lucene.search.BooleanQuery;
|
||||||
|
import org.apache.lucene.search.DisjunctionMaxQuery;
|
||||||
import org.apache.lucene.search.PhraseQuery;
|
import org.apache.lucene.search.PhraseQuery;
|
||||||
import org.apache.lucene.search.Query;
|
import org.apache.lucene.search.Query;
|
||||||
import org.apache.lucene.search.TermQuery;
|
import org.apache.lucene.search.TermQuery;
|
||||||
|
@ -78,6 +79,12 @@ public class FieldQuery {
|
||||||
flatten( clause.getQuery(), flatQueries );
|
flatten( clause.getQuery(), flatQueries );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if( sourceQuery instanceof DisjunctionMaxQuery ){
|
||||||
|
DisjunctionMaxQuery dmq = (DisjunctionMaxQuery)sourceQuery;
|
||||||
|
for( Query query : dmq ){
|
||||||
|
flatten( query, flatQueries );
|
||||||
|
}
|
||||||
|
}
|
||||||
else if( sourceQuery instanceof TermQuery ){
|
else if( sourceQuery instanceof TermQuery ){
|
||||||
if( !flatQueries.contains( sourceQuery ) )
|
if( !flatQueries.contains( sourceQuery ) )
|
||||||
flatQueries.add( sourceQuery );
|
flatQueries.add( sourceQuery );
|
||||||
|
|
|
@ -40,6 +40,7 @@ import org.apache.lucene.index.IndexWriter;
|
||||||
import org.apache.lucene.index.Term;
|
import org.apache.lucene.index.Term;
|
||||||
import org.apache.lucene.index.IndexWriter.MaxFieldLength;
|
import org.apache.lucene.index.IndexWriter.MaxFieldLength;
|
||||||
import org.apache.lucene.queryParser.QueryParser;
|
import org.apache.lucene.queryParser.QueryParser;
|
||||||
|
import org.apache.lucene.search.DisjunctionMaxQuery;
|
||||||
import org.apache.lucene.search.PhraseQuery;
|
import org.apache.lucene.search.PhraseQuery;
|
||||||
import org.apache.lucene.search.Query;
|
import org.apache.lucene.search.Query;
|
||||||
import org.apache.lucene.search.TermQuery;
|
import org.apache.lucene.search.TermQuery;
|
||||||
|
@ -141,6 +142,18 @@ public abstract class AbstractTestCase extends TestCase {
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected Query dmq( Query... queries ){
|
||||||
|
return dmq( 0.0F, queries );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Query dmq( float tieBreakerMultiplier, Query... queries ){
|
||||||
|
DisjunctionMaxQuery query = new DisjunctionMaxQuery( tieBreakerMultiplier );
|
||||||
|
for( Query q : queries ){
|
||||||
|
query.add( q );
|
||||||
|
}
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
|
||||||
protected void assertCollectionQueries( Collection<Query> actual, Query... expected ){
|
protected void assertCollectionQueries( Collection<Query> actual, Query... expected ){
|
||||||
assertEquals( expected.length, actual.size() );
|
assertEquals( expected.length, actual.size() );
|
||||||
for( Query query : expected ){
|
for( Query query : expected ){
|
||||||
|
|
|
@ -38,6 +38,14 @@ public class FieldQueryTest extends AbstractTestCase {
|
||||||
assertCollectionQueries( flatQueries, tq( "A" ), tq( "B" ), tq( "C" ) );
|
assertCollectionQueries( flatQueries, tq( "A" ), tq( "B" ), tq( "C" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testFlattenDisjunctionMaxQuery() throws Exception {
|
||||||
|
Query query = dmq( tq( "A" ), tq( "B" ), pqF( "C", "D" ) );
|
||||||
|
FieldQuery fq = new FieldQuery( query, true, true );
|
||||||
|
Set<Query> flatQueries = new HashSet<Query>();
|
||||||
|
fq.flatten( query, flatQueries );
|
||||||
|
assertCollectionQueries( flatQueries, tq( "A" ), tq( "B" ), pqF( "C", "D" ) );
|
||||||
|
}
|
||||||
|
|
||||||
public void testFlattenTermAndPhrase() throws Exception {
|
public void testFlattenTermAndPhrase() throws Exception {
|
||||||
Query query = paW.parse( "A AND \"B C\"" );
|
Query query = paW.parse( "A AND \"B C\"" );
|
||||||
FieldQuery fq = new FieldQuery( query, true, true );
|
FieldQuery fq = new FieldQuery( query, true, true );
|
||||||
|
|
Loading…
Reference in New Issue