use of org.codice.ddf.catalog.ui.query.delegate.SearchTerm in project ddf by codice.
the class CqlResult method countMatches.
private void countMatches(Set<SearchTerm> searchTerms, Metacard mc) {
List<String> textAttributes = mc.getMetacardType().getAttributeDescriptors().stream().filter(CqlResult::isTextAttribute).filter(Objects::nonNull).map(descriptor -> mc.getAttribute(descriptor.getName())).filter(Objects::nonNull).map(attribute -> Optional.ofNullable(attribute.getValue())).filter(Optional::isPresent).map(Optional::get).map(Object::toString).collect(Collectors.toList());
List<SearchTerm> terms = searchTerms.stream().filter(term -> !"*".equals(term.getTerm())).collect(Collectors.toList());
int totalTokens = 0;
for (String value : textAttributes) {
BufferedReader reader = new BufferedReader(new StringReader(value.toLowerCase()));
String line;
try {
while ((line = reader.readLine()) != null) {
String[] tokens = line.split("[\\s\\p{Punct}]+");
for (String token : tokens) {
totalTokens++;
for (SearchTerm term : terms) {
if (term.match(token)) {
matches.put(term.getTerm(), matches.getOrDefault(term.getTerm(), 0) + 1);
}
}
}
}
} catch (IOException e) {
LOGGER.debug("Unable to read line", e);
}
matches.put("*", totalTokens);
}
}
Aggregations