mirror of https://github.com/apache/lucene.git
enhancement to QueryParser to allow slop factor passed to a new getFieldQuery method
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@150354 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
26e2b49a68
commit
ee00e19246
|
@ -11,6 +11,13 @@ $Id$
|
|||
2. Added new class FieldCache to manage in-memory caches of field term
|
||||
values. (Tim Jones)
|
||||
|
||||
3. Added overloaded getFieldQuery method to QueryParser which
|
||||
accepts the slop factor specified for the phrase (or the default
|
||||
phrase slop for the QueryParser instance). This allows overriding
|
||||
methods to replace a PhraseQuery with a SpanNearQuery instead,
|
||||
keeping the proper slop factor. (Erik Hatcher)
|
||||
|
||||
|
||||
1.4 RC3
|
||||
|
||||
1. Fixed several search bugs introduced by the skipTo() changes in
|
||||
|
@ -265,7 +272,7 @@ $Id$
|
|||
|
||||
7. Modified QueryParser to make it possible to programmatically specify the
|
||||
default Boolean operator (OR or AND).
|
||||
(Péter Halácsy via otis)
|
||||
(P<EFBFBD>ter Hal<61>csy via otis)
|
||||
|
||||
8. Made many search methods and classes non-final, per requests.
|
||||
This includes IndexWriter and IndexSearcher, among others.
|
||||
|
|
|
@ -261,6 +261,26 @@ public class QueryParser implements QueryParserConstants {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Base implementation delegates to {@link #getFieldQuery(String,Analyzer,String)}.
|
||||
* This method may be overridden, for example, to return
|
||||
* a SpanNearQuery instead of a PhraseQuery.
|
||||
*
|
||||
* @exception ParseException throw in overridden method to disallow
|
||||
*/
|
||||
protected Query getFieldQuery(String field,
|
||||
Analyzer analyzer,
|
||||
String queryText,
|
||||
int slop) throws ParseException {
|
||||
Query query = getFieldQuery(field, analyzer, queryText);
|
||||
|
||||
if (query instanceof PhraseQuery) {
|
||||
((PhraseQuery) query).setSlop(slop);
|
||||
}
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @exception ParseException throw in overridden method to disallow
|
||||
*/
|
||||
|
@ -770,15 +790,17 @@ public class QueryParser implements QueryParserConstants {
|
|||
jj_la1[20] = jj_gen;
|
||||
;
|
||||
}
|
||||
q = getFieldQuery(field, analyzer,
|
||||
term.image.substring(1, term.image.length()-1));
|
||||
if (slop != null && q instanceof PhraseQuery) {
|
||||
int s = phraseSlop;
|
||||
|
||||
if (slop != null) {
|
||||
try {
|
||||
int s = Float.valueOf(slop.image.substring(1)).intValue();
|
||||
((PhraseQuery) q).setSlop(s);
|
||||
s = Float.valueOf(slop.image.substring(1)).intValue();
|
||||
}
|
||||
catch (Exception ignored) { }
|
||||
}
|
||||
q = getFieldQuery(field, analyzer,
|
||||
term.image.substring(1, term.image.length()-1),
|
||||
s);
|
||||
break;
|
||||
default:
|
||||
jj_la1[21] = jj_gen;
|
||||
|
|
|
@ -284,6 +284,26 @@ public class QueryParser {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Base implementation delegates to {@link #getFieldQuery(String,Analyzer,String)}.
|
||||
* This method may be overridden, for example, to return
|
||||
* a SpanNearQuery instead of a PhraseQuery.
|
||||
*
|
||||
* @exception ParseException throw in overridden method to disallow
|
||||
*/
|
||||
protected Query getFieldQuery(String field,
|
||||
Analyzer analyzer,
|
||||
String queryText,
|
||||
int slop) throws ParseException {
|
||||
Query query = getFieldQuery(field, analyzer, queryText);
|
||||
|
||||
if (query instanceof PhraseQuery) {
|
||||
((PhraseQuery) query).setSlop(slop);
|
||||
}
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @exception ParseException throw in overridden method to disallow
|
||||
*/
|
||||
|
@ -655,15 +675,17 @@ Query Term(String field) : {
|
|||
[ slop=<SLOP> ]
|
||||
[ <CARAT> boost=<NUMBER> ]
|
||||
{
|
||||
q = getFieldQuery(field, analyzer,
|
||||
term.image.substring(1, term.image.length()-1));
|
||||
if (slop != null && q instanceof PhraseQuery) {
|
||||
int s = phraseSlop;
|
||||
|
||||
if (slop != null) {
|
||||
try {
|
||||
int s = Float.valueOf(slop.image.substring(1)).intValue();
|
||||
((PhraseQuery) q).setSlop(s);
|
||||
s = Float.valueOf(slop.image.substring(1)).intValue();
|
||||
}
|
||||
catch (Exception ignored) { }
|
||||
}
|
||||
q = getFieldQuery(field, analyzer,
|
||||
term.image.substring(1, term.image.length()-1),
|
||||
s);
|
||||
}
|
||||
)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue