Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#945 fix queries with values containing colons #946

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/main/java/au/org/ala/biocache/util/QueryFormatUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ public String formatString(String text, boolean isQuery) {

// Queries containing OR, AND or Intersects( must already be correctly escaped for SOLR
// Note: if escaping is required, extract expressions from nested () [] "" for escaping with formatString.
if (isQuery && text.contains(" OR ") || text.contains(" AND ") || text.contains("Intersects(")) return text;
if (isQuery && (text.contains(" OR ") || text.contains(" AND ") || text.contains("Intersects("))) return text;

try {
String formatted = "";
Expand Down Expand Up @@ -1036,12 +1036,13 @@ public String formatString(String text, boolean isQuery) {
extractedValue = extractedValue.substring(0, extractedValue.indexOf(" OR "));
}

// search for term in the extractedValue and clip
// NOTE: the if the quoted term value contains content that looks like a term "name" then it will be
// treated as a new term.
Matcher termMatcher = termPattern.matcher(extractedValue);
if (termMatcher.find()) {
extractedValue = extractedValue.substring(0, termMatcher.start());
// search for term in the extractedValue and clip, this will be after the second unescaped ".
// Note that it already confirmed that the first character is an unescaped double quote.
for (int i = 1; i < extractedValue.length(); i++) {
if (extractedValue.charAt(i) == '"' && extractedValue.charAt(i - 1) != '\\') {
extractedValue = extractedValue.substring(0, i);
break;
}
}

// below code fragment extracts the filter value and try to format for solr query or get display value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.junit.Assert.*;

//TODO: update hubs, then remove fqs[0].substring(0, fqs[0].indexOf(':'))
@RunWith(MockitoJUnitRunner.class)
public class FilterQueryParserTest {

Expand Down
1 change: 1 addition & 0 deletions src/test/java/au/org/ala/biocache/dao/QueryFormatTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ public static SearchQueryTester[] data() {
new SearchQueryTester("spatial_list:dr123", "", "", false),
new SearchQueryTester("month:03 month:04", "month:03 month:04", "Month:March Month:April", true),
new SearchQueryTester("month:\"03\" month:\"04\"", "month:\"03\" month:\"04\"", "Month:\"March\" Month:\"April\"", true),
new SearchQueryTester("collection:\"ABC:def:123:456\"", "collection:\"ABC\\:def\\:123\\:456\"", "collection:\"ABC:def:123:456\"", true),
};
}

Expand Down