Skip to content

Commit 43a276f

Browse files
ahornaceVladimir Kotal
authored andcommitted
Fix problem when suggestions for wildcards ending with * did not work properly
1 parent f96b2fc commit 43a276f

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/org/opensolaris/opengrok/web/api/v1/suggester/query/SuggesterQueryParser.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ protected Query newPrefixQuery(final Term prefix) {
197197
protected Query newWildcardQuery(final Term t) {
198198
if (t.text().contains(identifier)) {
199199
String term = t.text().replace(identifier, "");
200-
if (term.endsWith("*")) {
200+
if (term.endsWith("*") && !containsWildcardCharacter(term.substring(0, term.length() - 1))) {
201+
// the term ends with "*" but contains no other wildcard characters so faster method can be used
201202
replaceIdentifier(t.field(), t.text());
202203
term = term.substring(0, term.length() - 1);
203204
SuggesterPrefixQuery q = new SuggesterPrefixQuery(new Term(t.field(), term));
@@ -214,6 +215,10 @@ protected Query newWildcardQuery(final Term t) {
214215
return super.newWildcardQuery(t);
215216
}
216217

218+
private boolean containsWildcardCharacter(final String s) {
219+
return s.contains("?") || s.contains("*");
220+
}
221+
217222
@Override
218223
protected Query newFuzzyQuery(final Term term, final float minimumSimilarity, final int prefixLength) {
219224
if (term.text().contains(identifier)) {

test/org/opensolaris/opengrok/web/api/v1/controller/SuggesterControllerTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,4 +602,17 @@ public void testGetPopularityDataDifferentField() {
602602
assertThat(res, contains(new SimpleEntry<>("greet", 4)));
603603
}
604604

605+
@Test
606+
public void testWildcardQueryEndingWithAsterisk() {
607+
Result res = target(SuggesterController.PATH)
608+
.queryParam(AuthorizationFilter.PROJECTS_PARAM, "c")
609+
.queryParam("field", QueryBuilder.FULL)
610+
.queryParam(QueryBuilder.FULL, "pr?nt*")
611+
.request()
612+
.get(Result.class);
613+
614+
assertThat(res.suggestions.stream().map(r -> r.phrase).collect(Collectors.toList()),
615+
contains("printf"));
616+
}
617+
605618
}

0 commit comments

Comments
 (0)