// if there is no location to query, return no results
if ("".equals(sanitizedLocationName)) {
return Collections.EMPTY_LIST;
}
LocationOccurrence location = query.getOccurrence();
int maxResults = query.getMaxResults() > 0 ? query.getMaxResults() : DEFAULT_MAX_RESULTS;
Filter filter = buildFilter(query);
List<ResolvedLocation> matches;
try {
// attempt to find an exact match for the query
matches = executeQuery(location, sanitizedLocationName, filter, maxResults, false, query.isFilterDupes(), null);
if (LOG.isDebugEnabled()) {
for (ResolvedLocation loc : matches) {
LOG.debug("{}", loc);
}
}
// check to see if we should run a fuzzy query based on the configured FuzzyMode
if (query.getFuzzyMode().useFuzzyMatching(maxResults, matches.size())) {
// provide any exact matches if we are running a fuzzy query so they can be considered for deduplication
// and result count
matches = executeQuery(location, sanitizedLocationName, filter, maxResults, true, query.isFilterDupes(), matches);
if (LOG.isDebugEnabled()) {
for (ResolvedLocation loc : matches) {
LOG.debug("{}[fuzzy]", loc);
}
}
}
if (matches.isEmpty()) {
LOG.debug("No match found for: '{}'", location.getText());
}
} catch (ParseException pe) {
throw new ClavinException(String.format("Error parsing query for: '%s'}", location.getText()), pe);
} catch (IOException ioe) {
throw new ClavinException(String.format("Error executing query for: '%s'}", location.getText()), ioe);
}
return matches;
}