mirror of https://github.com/apache/lucene.git
LUCENE-5530 Allow the ComplexPhraseQueryParser to search order or un-order proximity queries.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1578148 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e3779cf420
commit
bcedf1bba1
|
@ -100,6 +100,9 @@ New Features
|
|||
|
||||
* LUCENE-3758: Allow the ComplexPhraseQueryParser to search order or
|
||||
un-order proximity queries. (Ahmet Arslan via Erick Erickson)
|
||||
|
||||
* LUCENE-5530: ComplexPhraseQueryParser throws ParseException for fielded queries.
|
||||
(Erick Erickson via Tomas Fernandez Lobbe and Ahmet Arslan)
|
||||
|
||||
API Changes
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ public abstract class QueryParserBase extends QueryBuilder implements CommonQuer
|
|||
MultiTermQuery.RewriteMethod multiTermRewriteMethod = MultiTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULT;
|
||||
boolean allowLeadingWildcard = false;
|
||||
|
||||
String field;
|
||||
protected String field;
|
||||
int phraseSlop = 0;
|
||||
float fuzzyMinSim = FuzzyQuery.defaultMinSimilarity;
|
||||
int fuzzyPrefixLength = FuzzyQuery.defaultPrefixLength;
|
||||
|
|
|
@ -230,13 +230,22 @@ public class ComplexPhraseQueryParser extends QueryParser {
|
|||
// Called by ComplexPhraseQueryParser for each phrase after the main
|
||||
// parse
|
||||
// thread is through
|
||||
protected void parsePhraseElements(QueryParser qp) throws ParseException {
|
||||
protected void parsePhraseElements(ComplexPhraseQueryParser qp) throws ParseException {
|
||||
// TODO ensure that field-sensitivity is preserved ie the query
|
||||
// string below is parsed as
|
||||
// field+":("+phrasedQueryStringContents+")"
|
||||
// but this will need code in rewrite to unwrap the first layer of
|
||||
// boolean query
|
||||
contents = qp.parse(phrasedQueryStringContents);
|
||||
|
||||
String oldDefaultParserField = qp.field;
|
||||
try {
|
||||
//temporarily set the QueryParser to be parsing the default field for this phrase e.g author:"fred* smith"
|
||||
qp.field = this.field;
|
||||
contents = qp.parse(phrasedQueryStringContents);
|
||||
}
|
||||
finally {
|
||||
qp.field = oldDefaultParserField;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -38,11 +38,12 @@ import org.apache.lucene.util.LuceneTestCase;
|
|||
public class TestComplexPhraseQuery extends LuceneTestCase {
|
||||
Directory rd;
|
||||
Analyzer analyzer;
|
||||
|
||||
DocData docsContent[] = { new DocData("john smith", "1"),
|
||||
new DocData("johathon smith", "2"),
|
||||
new DocData("john percival smith", "3"),
|
||||
new DocData("jackson waits tom", "4") };
|
||||
DocData docsContent[] = {
|
||||
new DocData("john smith", "1", "developer"),
|
||||
new DocData("johathon smith", "2", "developer"),
|
||||
new DocData("john percival smith", "3", "designer"),
|
||||
new DocData("jackson waits tom", "4", "project manager")
|
||||
};
|
||||
|
||||
private IndexSearcher searcher;
|
||||
private IndexReader reader;
|
||||
|
@ -126,7 +127,19 @@ public class TestComplexPhraseQuery extends LuceneTestCase {
|
|||
assertEquals(qString + " missing some matches ", 0, expecteds.size());
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void testFieldedQuery() throws Exception {
|
||||
checkMatches("name:\"john smith\"", "1");
|
||||
checkMatches("name:\"j* smyth~\"", "1,2");
|
||||
checkMatches("role:\"developer\"", "1,2");
|
||||
checkMatches("role:\"p* manager\"", "4");
|
||||
checkMatches("role:de*", "1,2,3");
|
||||
checkMatches("name:\"j* smyth~\"~5", "1,2,3");
|
||||
checkMatches("role:\"p* manager\" AND name:jack*", "4");
|
||||
checkMatches("+role:developer +name:jack*", "");
|
||||
checkMatches("name:\"john smith\"~2 AND role:designer AND id:3", "3");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
@ -138,6 +151,7 @@ public class TestComplexPhraseQuery extends LuceneTestCase {
|
|||
Document doc = new Document();
|
||||
doc.add(newTextField("name", docsContent[i].name, Field.Store.YES));
|
||||
doc.add(newTextField("id", docsContent[i].id, Field.Store.YES));
|
||||
doc.add(newTextField("role", docsContent[i].role, Field.Store.YES));
|
||||
w.addDocument(doc);
|
||||
}
|
||||
w.close();
|
||||
|
@ -156,11 +170,14 @@ public class TestComplexPhraseQuery extends LuceneTestCase {
|
|||
String name;
|
||||
|
||||
String id;
|
||||
|
||||
String role;
|
||||
|
||||
public DocData(String name, String id) {
|
||||
public DocData(String name, String id, String role) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.id = id;
|
||||
this.role = role;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue