Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
feat(TM): pre-sort TM results by TextFlowTarget timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
seanf committed Jul 28, 2015
1 parent 7a501bd commit bda2738
Showing 1 changed file with 7 additions and 9 deletions.
Expand Up @@ -152,7 +152,7 @@ public Optional<HTextFlowTarget> searchBestMatchTransMemory(

Collection<Object[]> matches =
findMatchingTranslation(targetLocaleId, sourceLocaleId, query,
0, true, HTextFlowTarget.class);
0, HTextFlowTarget.class);

if (matches.isEmpty()) {
return Optional.<HTextFlowTarget> absent();
Expand Down Expand Up @@ -205,7 +205,7 @@ public List<TransMemoryResultItem> searchTransMemory(

Collection<Object[]> matches =
findMatchingTranslation(targetLocaleId, sourceLocaleId,
transMemoryQuery, SEARCH_MAX_RESULTS, false,
transMemoryQuery, SEARCH_MAX_RESULTS,
HTextFlowTarget.class, TransMemoryUnit.class);

Map<TMKey, TransMemoryResultItem> matchesMap =
Expand Down Expand Up @@ -272,15 +272,15 @@ private TransMemoryQuery buildTMQuery(HTextFlow textFlow,
private Collection<Object[]> findMatchingTranslation(
LocaleId targetLocaleId, LocaleId sourceLocaleId,
TransMemoryQuery transMemoryQuery, int maxResults,
boolean sortByDate, Class<?>... entities) {
Class<?>... entities) {
try {
if (entities == null || entities.length < 1) {
throw new RuntimeException(
"Need entity type (HTextFlowTarget.class or TransMemoryUnit.class) for TM search");
}
List<Object[]> matches =
getSearchResult(transMemoryQuery, sourceLocaleId,
targetLocaleId, maxResults, sortByDate, entities);
targetLocaleId, maxResults, entities);

// filter out invalid target
return Collections2.filter(matches,
Expand Down Expand Up @@ -491,7 +491,7 @@ public int hashCode() {

private List<Object[]> getSearchResult(TransMemoryQuery query,
LocaleId sourceLocale, LocaleId targetLocale, int maxResult,
boolean sortByDate, Class<?>... entities) throws ParseException {
Class<?>... entities) throws ParseException {
String queryText = null;
String[] multiQueryText = null;

Expand Down Expand Up @@ -560,9 +560,7 @@ private List<Object[]> getSearchResult(TransMemoryQuery query,
ftQuery.setMaxResults(maxResult);
}

if (sortByDate) {
ftQuery.setSort(lastChangedSort);
}
ftQuery.setSort(lastChangedSort);

List<Object[]> resultList = (List<Object[]>) ftQuery.getResultList();
if (!resultList.isEmpty() && resultList.size() == maxResult) {
Expand Down Expand Up @@ -908,7 +906,7 @@ private void processResultRow(Object[] resultRow) {
*/
private Collection<Object[]> runQuery() {
return findMatchingTranslation(transLocale, srcLocale, query,
SEARCH_MAX_RESULTS, SORT_BY_DATE,
SEARCH_MAX_RESULTS,
HTextFlowTarget.class, TransMemoryUnit.class);
}

Expand Down

0 comments on commit bda2738

Please sign in to comment.