Skip to content

Commit

Permalink
Merge branch 'master' of github.com:romanchyla/montysolr
Browse files Browse the repository at this point in the history
  • Loading branch information
romanchyla committed Jul 9, 2019
2 parents 37ef602 + daf5c1a commit a74da3f
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public AqpAdsabsQueryConfigHandler() {
set(ConfigurationKeys.DEFAULT_DATE_RANGE_FIELD, "date");
set(ConfigurationKeys.DEFAULT_IDENTIFIER_FIELD, "identifier");

set(StandardQueryConfigHandler.ConfigurationKeys.ALLOW_LEADING_WILDCARD, true);
set(StandardQueryConfigHandler.ConfigurationKeys.ALLOW_LEADING_WILDCARD, false);



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ private Float getDisjunctTieBreaker() {
Object obj = _getConfigVal("aqp.unfielded.tokens.tiebreaker");
if (obj == null)
return 0.0f;
return (Float) obj;
return Float.valueOf((String) obj);
}

private Set<String> aqpIgnorableFields = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@ public AqpAdsabsQParser(AqpQueryParser parser, String qstr, SolrParams localPara

config.get(AqpAdsabsQueryConfigHandler.ConfigurationKeys.VIRTUAL_FIELDS).putAll(defaultConfig.virtualFields);

if (params.get("aqp.allow.leading_wildcard", null) != null) {
config.set(StandardQueryConfigHandler.ConfigurationKeys.ALLOW_LEADING_WILDCARD,
params.getBool("aqp.allow.leading_wildcard", false));
}

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ private void resolveIfNecessary(String fieldName, Set<FormattedQuery> seen) thro
SolrParams oldParams = req.getParams();
ModifiableSolrParams newParams = new ModifiableSolrParams(oldParams);
newParams.set(CommonParams.DF, fieldName);
newParams.set("aqp.allow.leading_wildcard", "true");
req.setParams(newParams);

String defType = req.getParams().get(QueryParsing.DEFTYPE, QParserPlugin.DEFAULT_QTYPE);
Expand Down
7 changes: 4 additions & 3 deletions contrib/adsabs/src/test/org/adsabs/TestAdsAllFields.java
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,8 @@ public void test() throws Exception {
assertQ(req("q", "bibgroup:CFA"), "//*[@numFound='1']");
assertQ(req("q", "bibgroup:cf*"), "//*[@numFound='1']");
assertQ(req("q", "bibgroup:CF*"), "//*[@numFound='1']");
assertQ(req("q", "bibgroup:?FA"), "//*[@numFound='1']");
assertQ(req("q", "bibgroup:?FA", "qt", "/query", "aqp.allow.leading_wildcard", "true"),
"//*[@numFound='1']");

// facets are case sensitive and you must get the exact wording
// TODO: shall we be consistent and turn *everything* to lowercase?
Expand Down Expand Up @@ -1332,10 +1333,10 @@ public void test() throws Exception {


// test we can search for all docs that have certain field
assertQ(req("q", "reference:*"),
assertQ(req("q", "reference:*", "qt", "/query", "aqp.allow.leading_wildcard", "true"),
"//doc[1]/int[@name='recid'][.='100']"
);
assertQ(req("q", "id:?"), // but works only for text fields
assertQ(req("q", "id:?", "qt", "/query", "aqp.allow.leading_wildcard", "true"), // but works only for text fields
"//*[@numFound='8']"
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,9 @@ public void testWildCards() throws Exception {
assertEquals(MultiTermQuery.CONSTANT_SCORE_REWRITE, ((MultiTermQuery) q).getRewriteMethod());

assertQueryEquals("te*t", null, "te*t", WildcardQuery.class);
assertQueryEquals("*te*t", null, "*te*t", WildcardQuery.class);
assertQueryEquals("*te*t*", null, "*te*t*", WildcardQuery.class);
assertQueryEquals("?te*t?", null, "?te*t?", WildcardQuery.class);
assertQueryEqualsAllowLeadingWildcard("*te*t", null, "*te*t");
assertQueryEqualsAllowLeadingWildcard("*te*t*", null, "*te*t*");
assertQueryEqualsAllowLeadingWildcard("?te*t?", null, "?te*t?");
assertQueryEquals("te?t", null, "te?t", WildcardQuery.class);
assertQueryEquals("te??t", null, "te??t", WildcardQuery.class);

Expand All @@ -328,9 +328,9 @@ public void testWildCards() throws Exception {
assertQueryEquals("\"te*t phrase\"", null, "te*t phrase", WildcardQuery.class);
assertQueryEquals("\"test* phrase\"", null, "test* phrase", WildcardQuery.class);
assertQueryEquals("\"te*t phrase\"", null, "te*t phrase", WildcardQuery.class);
assertQueryEquals("\"*te*t phrase\"", null, "*te*t phrase", WildcardQuery.class);
assertQueryEquals("\"*te*t* phrase\"", null, "*te*t* phrase", WildcardQuery.class);
assertQueryEquals("\"?te*t? phrase\"", null, "?te*t? phrase", WildcardQuery.class);
assertQueryEqualsAllowLeadingWildcard("\"*te*t phrase\"", null, "*te*t phrase");
assertQueryEqualsAllowLeadingWildcard("\"*te*t* phrase\"", null, "*te*t* phrase");
assertQueryEqualsAllowLeadingWildcard("\"?te*t? phrase\"", null, "?te*t? phrase");
assertQueryEquals("\"te?t phrase\"", null, "te?t phrase", WildcardQuery.class);
assertQueryEquals("\"te??t phrase\"", null, "te??t phrase", WildcardQuery.class);
assertQueryEquals("\"te*?t phrase\"", null, "te*?t phrase", WildcardQuery.class);
Expand All @@ -339,22 +339,22 @@ public void testWildCards() throws Exception {
assertQueryEquals("*", null, "*:*", MatchAllDocsQuery.class);
assertQueryEquals("*:*", null, "*:*", MatchAllDocsQuery.class);

assertQueryEquals("?", null, "?", WildcardQuery.class);
assertQueryEqualsAllowLeadingWildcard("?", null, "?");


// XXX: in fact, in the WildcardQuery, even escaped start \* will become *
// so it is not possible to search for words that contain * as a literal
// character, to have it differently, WildcardTermEnum class would have
// to think of skipping \* and \?

q = assertQueryEquals("*t\\*a", null, "*t*a", WildcardQuery.class);
assertQueryEqualsAllowLeadingWildcard("*t\\*a", null, "*t*a");

assertQueryEquals("*t*a\\*", null, "*t*a*", WildcardQuery.class);
assertQueryEquals("*t*a\\?", null, "*t*a?", WildcardQuery.class);
assertQueryEquals("*t*\\a", null, "*t*a", WildcardQuery.class);
assertQueryEqualsAllowLeadingWildcard("*t*a\\*", null, "*t*a*");
assertQueryEqualsAllowLeadingWildcard("*t*a\\?", null, "*t*a?");
assertQueryEqualsAllowLeadingWildcard("*t*\\a", null, "*t*a");

assertQueryEquals("title:*", null, "title:*", PrefixQuery.class);
assertQueryEquals("doi:*", null, "doi:*", PrefixQuery.class);
assertQueryEqualsAllowLeadingWildcard("title:*", null, "title:*", PrefixQuery.class);
assertQueryEqualsAllowLeadingWildcard("doi:*", null, "doi:*", PrefixQuery.class);

}

Expand All @@ -379,7 +379,7 @@ public void testBasics() throws Exception{
KeywordAnalyzer kwa = new KeywordAnalyzer();
assertQueryEquals("keyword:\"planets and satellites\"", wsa, "keyword:\"planets and satellites\"", PhraseQuery.class);

assertQueryEquals("full:*", null, "full:*", PrefixQuery.class);
assertQueryEqualsAllowLeadingWildcard("full:*", null, "full:*", PrefixQuery.class);

assertQueryEquals("weak lensing", null, "+weak +lensing");
assertQueryEquals("+contact +binaries -eclipsing", null, "+contact +binaries -eclipsing");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,9 @@ public void testOtherCases() throws Exception {
"//doc/str[@name='id'][.='11']"
);

assertQ(req("q", "title" + ":*sky"), "//*[@numFound='4']",
assertQ(req("qt", "/query",
"aqp.allow.leading_wildcard", "true",
"q", "title" + ":*sky"), "//*[@numFound='4']",
"//doc/str[@name='id'][.='10']",
"//doc/str[@name='id'][.='11']",
"//doc/str[@name='id'][.='12']",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ public void test() throws Exception {
assertQ(req("q", f + ":\"fivejets\""), "//*[@numFound='0']");
assertQ(req("q", f + ":\"onejets\""), "//*[@numFound='1']", "//doc[1]/str[@name='id'][.='6']");
assertQ(req("q", f + ":\"one-jets\""), "//*[@numFound='1']", "//doc[1]/str[@name='id'][.='6']");
assertQ(req("q", f + ":\"*jets\""), "//*[@numFound='2']", "//doc[1]/str[@name='id'][.='6']"); // curiously also finds 'jets' (id 5.)
assertQ(req("q", f + ":\"*jets\"", "qt", "/query", "aqp.allow.leading_wildcard", "true"), "//*[@numFound='2']", "//doc[1]/str[@name='id'][.='6']"); // curiously also finds 'jets' (id 5.)
assertQ(req("q", f + ":\"jets\""), "//*[@numFound='1']", "//doc[1]/str[@name='id'][.='9']");
assertQ(req("q", f + ":\"jets*\""), "//*[@numFound='2']", "//doc[1]/str[@name='id'][.='7']"); // also 'jets' (id 5.)
assertQ(req("q", f + ":\"*jets*\""), "//*[@numFound='4']");
assertQ(req("q", f + ":\"*jets*\"", "qt", "/query", "aqp.allow.leading_wildcard", "true"), "//*[@numFound='4']");

// find only 'jets' (where the word stood alone)
assertQ(req("q", f + ":\"jets\""), "//*[@numFound='1']", "//doc[1]/str[@name='id'][.='9']");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,17 @@ public void testUnfieldedSearch() throws Exception {
"((+((keyword:r)^0.7 | (title:r)^0.9) +((keyword:s)^0.7 | (title:s)^0.9) +((keyword:t)^0.7 | (title:t)^0.9)) "
+ "| (((keyword:\"r s t\" | Synonym(keyword:acr::rst keyword:syn::r s t)))^0.7 | ((title:\"r s t\" | Synonym(title:acr::rst title:syn::r s t)))^0.9))",
DisjunctionMaxQuery.class);
assertQueryEquals(req("defType", "aqp",
"q", "r s t",
"aqp.unfielded.tokens.strategy", "disjuncts",
"aqp.unfielded.tokens.tiebreaker", "0.5",
"aqp.unfielded.tokens.new.type", "simple",
"aqp.unfielded.phrase.edismax.synonym.workaround", "false",
"qf", "title^0.9 keyword^0.7"),
"((+((keyword:r)^0.7 | (title:r)^0.9) +((keyword:s)^0.7 | (title:s)^0.9) +((keyword:t)^0.7 | (title:t)^0.9)) "
+ "| (((keyword:\"r s t\" | Synonym(keyword:acr::rst keyword:syn::r s t)))^0.7 | ((title:\"r s t\" | Synonym(title:acr::rst title:syn::r s t)))^0.9))~0.5",
DisjunctionMaxQuery.class);

assertQueryEquals(req("defType", "aqp",
"q", "r s t",
"aqp.unfielded.tokens.strategy", "multiply",
Expand Down Expand Up @@ -972,10 +983,12 @@ public void testSearch() throws Exception {


// search for all docs with a field
assertQueryEquals(req("defType", "aqp", "q", "title:*"),
assertQueryEquals(req("defType", "aqp", "q", "title:*",
"aqp.allow.leading_wildcard", "true"),
"title:*",
PrefixQuery.class);
assertQueryEquals(req("defType", "aqp", "q", "title:?"),
assertQueryEquals(req("defType", "aqp", "q", "title:?",
"aqp.allow.leading_wildcard", "true"),
"title:?",
WildcardQuery.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,22 @@ public Query assertQueryEquals(String query, Analyzer a, String result,
return q;
}

public void assertQueryEqualsAllowLeadingWildcard(String query, Analyzer a,
String result, Class<?> clazz) throws Exception {
Query q = getQueryAllowLeadingWildcard(query, a);
String s = q.toString("field");
if (!s.equals(result)) {
fail("Query /" + query + "/ yielded /" + s + "/, expecting /" + result
+ "/");
}
if (clazz != null) {
if (!q.getClass().isAssignableFrom(clazz)) {
debugFail(q.toString(), result,
"Query is not: " + clazz + " but: " + q.getClass());
}
}
}

public void assertQueryEqualsAllowLeadingWildcard(String query, Analyzer a,
String result) throws Exception {
Query q = getQueryAllowLeadingWildcard(query, a);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@
</lst>
<lst name="invariants">
<str name="echoParams">explicit</str>
<str name="aqp.allow.leading_wildcard">false</str>
</lst>
<arr name="last-components">
<str>wordcloud</str>
Expand All @@ -339,6 +340,7 @@
</lst>
<lst name="invariants">
<str name="echoParams">explicit</str>
<str name="aqp.allow.leading_wildcard">false</str>
</lst>
<arr name="last-components">
<str>tvComponent</str>
Expand All @@ -356,6 +358,7 @@
</lst>
<lst name="invariants">
<str name="echoParams">explicit</str>
<str name="aqp.allow.leading_wildcard">false</str>
</lst>
</requestHandler>

Expand All @@ -381,6 +384,8 @@
<str name="aqp.unfielded.ignore.fields">entdate pubdate year</str>
<str name="aqp.unfielded.tokens.function.name">edismax_combined_aqp</str>
<str name="useFastVectorHighlighter">true</str>
<str name="aqp.allow.leading_wildcard">true</str>

</lst>
<lst name="invariants">
<str name="echoParams">explicit</str>
Expand Down

0 comments on commit a74da3f

Please sign in to comment.