if (Strings.isNullOrEmpty(action.getSearchString())) {
// TODO empty searches shouldn't be requested, consider replacing
// this
// with an error, or making behaviour return all targets for the
// project (consider performance).
return new GetProjectTransUnitListsResult(action, docPaths,
matchingTUs);
}
FilterConstraints filterConstraints =
FilterConstraints.builder().filterBy(action.getSearchString())
.caseSensitive(action.isCaseSensitive())
.checkInSource(action.isSearchInSource())
.checkInTarget(action.isSearchInTarget()).build();
List<HTextFlow> matchingFlows =
textFlowSearchServiceImpl.findTextFlows(
action.getWorkspaceId(), action.getDocumentPaths(),
filterConstraints);
log.info("Returned {} results for search", matchingFlows.size());
// FIXME remove when analyzer handles leading & trailing whitespace
boolean needsWhitespaceCheck =
!action.getSearchString().equals(
action.getSearchString().trim());
Iterable<HTextFlow> result = matchingFlows;
if (needsWhitespaceCheck) {
// FIXME temporary check for leading and trailing whitespace to
// compensate
// for NGramAnalyzer trimming strings before tokenization. This
// should
// be removed when updating to a lucene version with the whitespace
// issue resolved.
result =
Iterables.filter(
matchingFlows,
new WhitespaceMatchPredicate(action, hLocale
.getId()));
}
for (HTextFlow textFlow : result) {
List<TransUnit> listForDoc =
matchingTUs.get(textFlow.getDocument().getId());
if (listForDoc == null) {
listForDoc = new ArrayList<TransUnit>();
}
TransUnit transUnit =
transUnitTransformer.transform(textFlow, hLocale);
listForDoc.add(transUnit);
matchingTUs.put(textFlow.getDocument().getId(), listForDoc);
docPaths.put(textFlow.getDocument().getId(), textFlow.getDocument()
.getDocId());
}
return new GetProjectTransUnitListsResult(action, docPaths, matchingTUs);
}