IndexFieldLabels.CONTENT_STATE_FIELD,
ContentState.New.toString()));
targetQuery.add(approvedStateQuery, Occur.MUST_NOT);
}
FullTextQuery ftQuery =
entityManager.createFullTextQuery(targetQuery,
HTextFlowTarget.class);
@SuppressWarnings("unchecked")
List<HTextFlowTarget> matchedTargets =
(List<HTextFlowTarget>) ftQuery.getResultList();
log.info("got {} HTextFLowTarget results", matchedTargets.size());
for (HTextFlowTarget htft : matchedTargets) {
// manually check for case sensitive matches
if (!constraints.isCaseSensitive()
|| (contentIsValid(htft.getContents(), constraints))) {
if (!htft.getTextFlow().getDocument().isObsolete()) {
resultList.add(htft.getTextFlow());
}
}
}
}
if (constraints.isSearchInSource()) {
// Source locale
// NB: Assume the first document's locale, or the same target locale
// if there are no documents
// TODO Move source locale to the Project iteration level
LocaleId sourceLocaleId = localeId;
HProjectIteration projectIteration =
projectIterationDAO.getBySlug(projectSlug, iterationSlug);
if (!projectIteration.getDocuments().isEmpty()) {
sourceLocaleId =
projectIteration.getDocuments().values().iterator()
.next().getLocale().getLocaleId();
}
// Content query for source
String sourceAnalyzerName =
TextContainerAnalyzerDiscriminator
.getAnalyzerDefinitionName(sourceLocaleId.getId());
Analyzer sourceAnalyzer =
entityManager.getSearchFactory().getAnalyzer(
sourceAnalyzerName);
Query srcContentPhraseQuery;
QueryParser srcContentQueryParser =
new MultiFieldQueryParser(Version.LUCENE_29,
IndexFieldLabels.CONTENT_FIELDS, sourceAnalyzer);
try {
srcContentPhraseQuery =
srcContentQueryParser.parse("\""
+ QueryParser.escape(constraints
.getSearchString()) + "\"");
} catch (ParseException e) {
throw new ZanataServiceException("Failed to parse query", e);
}
// Source Query
BooleanQuery sourceQuery = new BooleanQuery();
sourceQuery.add(projectQuery, Occur.MUST);
sourceQuery.add(iterationQuery, Occur.MUST);
sourceQuery.add(srcContentPhraseQuery, Occur.MUST);
if (documentsQuery.getTermArrays().size() > 0) {
sourceQuery.add(documentsQuery, Occur.MUST);
}
FullTextQuery ftQuery =
entityManager.createFullTextQuery(sourceQuery,
HTextFlow.class);
@SuppressWarnings("unchecked")
List<HTextFlow> matchedSources =
(List<HTextFlow>) ftQuery.getResultList();
log.info("got {} HTextFLow results", matchedSources.size());
for (HTextFlow htf : matchedSources) {
if (!resultList.contains(htf)) {
// manually check for case sensitive matches
if (!constraints.isCaseSensitive()