SOLR-9900: fix false positives on range queries with ReversedWildcardFilterFactory

This commit is contained in:
Mikhail Khludnev 2016-12-30 00:42:51 +03:00
parent 6b00ee5175
commit 5d042d3a49
3 changed files with 28 additions and 0 deletions

View File

@ -298,6 +298,8 @@ Bug Fixes
* SOLR-9901: Implement move in HdfsDirectoryFactory. (Mark Miller)
* SOLR-9900: fix false positives on range queries with ReversedWildcardFilterFactory (Yonik Seeley via Mikhail Khludnev)
Other Changes
----------------------

View File

@ -24,6 +24,7 @@ import java.util.List;
import java.util.Map;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.reverse.ReverseStringFilter;
import org.apache.lucene.analysis.util.TokenFilterFactory;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.AutomatonQuery;
@ -894,6 +895,19 @@ public abstract class SolrQueryParserBase extends QueryBuilder {
protected Query getRangeQuery(String field, String part1, String part2, boolean startInclusive, boolean endInclusive) throws SyntaxError {
checkNullField(field);
SchemaField sf = schema.getField(field);
if (part1 == null) {
ReversedWildcardFilterFactory factory = getReversedWildcardFilterFactory(sf.getType());
if (factory != null) {
// There will be reversed tokens starting with u0001 that we want to exclude, so
// lets start at u0002 inclusive instead.
char[] buf = new char[1];
buf[0] = ReverseStringFilter.START_OF_HEADING_MARKER + 1;
part1 = new String(buf);
startInclusive = true;
}
}
return sf.getType().getRangeQuery(parser, sf, part1, part2, startInclusive, endInclusive);
}

View File

@ -182,6 +182,18 @@ public class TestReversedWildcardFilterFactory extends SolrTestCaseJ4 {
assertQ("false positive",
req("+id:1 +one:*zemog*"),
"//result[@numFound=0]");
assertQ("no reverse, no false positive",
req("q", "+id:1 +three:[* TO a]",
"debugQuery", "true"),
"//result[@numFound=0]");
{
String reverseField = random().nextBoolean() ? "one":"two";
assertQ("false positive",
req("q", "+id:1 +"+reverseField+":[* TO a]",
"debugQuery", "true"),
"//result[@numFound=0]");
}
assertQ("false positive",
req("+id:1 +two:*zemog*"),
"//result[@numFound=0]");