mirror of https://github.com/apache/lucene.git
SOLR-4076: fuzzy support for MultiTermAwareComponent in SolrQueryParser
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1409517 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
899f74978f
commit
102b0b8f61
|
@ -194,6 +194,12 @@ Bug Fixes
|
|||
that start with /zookeeper, as this can fail and stop the removal of
|
||||
further nodes. (Mark Miller)
|
||||
|
||||
* SOLR-4076: SolrQueryParser should run fuzzy terms through
|
||||
MultiTermAwareComponents to ensure that (for example) a fuzzy query of
|
||||
foobar~2 is equivalent to FooBar~2 on a field that includes lowercasing.
|
||||
(yonik)
|
||||
|
||||
|
||||
Other Changes
|
||||
----------------------
|
||||
|
||||
|
|
|
@ -246,4 +246,12 @@ public class SolrQueryParser extends QueryParser {
|
|||
termStr = analyzeIfMultitermTermText(field, termStr, schema.getFieldType(field));
|
||||
return newRegexpQuery(new Term(field, termStr));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Query getFuzzyQuery(String field, String termStr, float minSimilarity) throws ParseException {
|
||||
termStr = analyzeIfMultitermTermText(field, termStr, schema.getFieldType(field));
|
||||
Term t = new Term(field, termStr);
|
||||
return newFuzzyQuery(t, minSimilarity, getFuzzyPrefixLength());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -185,26 +185,37 @@ public class TestFoldingMultitermQuery extends SolrTestCaseJ4 {
|
|||
assertQ(req("q", "content_lower_token:hȉ*l?*"), "//result[@numFound='1']");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFuzzy() throws Exception {
|
||||
assertQ(req("q", "content:ZiLLx~1"),
|
||||
"//result[@numFound='1']");
|
||||
assertQ(req("q", "content_straight:ZiLLx~1"), // case preserving field shouldn't match
|
||||
"//result[@numFound='0']");
|
||||
assertQ(req("q", "content_folding:ZiLLx~1"), // case preserving field shouldn't match
|
||||
"//result[@numFound='0']");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegex() throws Exception {
|
||||
assertQ(req("q", "content:/Zill[a-z]/"),
|
||||
"//result[@numFound='1']");
|
||||
"//result[@numFound='1']");
|
||||
assertQ(req("q", "content:/Zill[A-Z]/"), // everything in the regex gets lowercased?
|
||||
"//result[@numFound='1']");
|
||||
"//result[@numFound='1']");
|
||||
assertQ(req("q", "content_keyword:/.*Zill[A-Z]/"),
|
||||
"//result[@numFound='1']");
|
||||
"//result[@numFound='1']");
|
||||
|
||||
assertQ(req("q", "content_straight:/Zill[a-z]/"), // case preserving field shouldn't match
|
||||
"//result[@numFound='0']");
|
||||
"//result[@numFound='0']");
|
||||
assertQ(req("q", "content_folding:/Zill[a-z]/"), // case preserving field shouldn't match
|
||||
"//result[@numFound='0']");
|
||||
"//result[@numFound='0']");
|
||||
|
||||
assertQ(req("q", "content_keyword:/Abcdefg1 Finger/"), // test spaces
|
||||
"//result[@numFound='1']");
|
||||
"//result[@numFound='1']");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testGeneral() throws Exception {
|
||||
assertQ(req("q", "content_stemming:fings*"), "//result[@numFound='0']"); // should not match (but would if fings* was stemmed to fing*
|
||||
|
|
Loading…
Reference in New Issue