use of org.finos.waltz.model.entity_search.EntitySearchOptions in project waltz by khartec.
the class LogicalDataElementSearchDao method search.
@Override
public List<LogicalDataElement> search(EntitySearchOptions options) {
List<String> terms = SearchUtilities.mkTerms(options.searchQuery());
if (terms.isEmpty()) {
return Collections.emptyList();
}
Set<String> validStatusNames = EnumUtilities.names(options.entityLifecycleStatuses());
Condition statusCondition = LOGICAL_DATA_ELEMENT.ENTITY_LIFECYCLE_STATUS.in(validStatusNames);
Condition likeName = JooqUtilities.mkBasicTermSearch(LOGICAL_DATA_ELEMENT.NAME, terms);
Condition likeDesc = JooqUtilities.mkBasicTermSearch(LOGICAL_DATA_ELEMENT.DESCRIPTION, terms);
List<LogicalDataElement> results = dsl.select(LOGICAL_DATA_ELEMENT.fields()).from(LOGICAL_DATA_ELEMENT).where(likeName.and(statusCondition)).union(dsl.select(LOGICAL_DATA_ELEMENT.fields()).from(LOGICAL_DATA_ELEMENT).where(likeDesc.and(statusCondition))).orderBy(LOGICAL_DATA_ELEMENT.NAME).limit(options.limit()).fetch(LogicalDataElementDao.TO_DOMAIN_MAPPER);
List<LogicalDataElement> sortedResults = sort(results, SearchUtilities.mkRelevancyComparator(a -> a.name(), terms.get(0)));
return sortedResults;
}
use of org.finos.waltz.model.entity_search.EntitySearchOptions in project waltz by khartec.
the class MariaMeasurableSearch method searchFullText.
@Override
public List<Measurable> searchFullText(DSLContext dsl, EntitySearchOptions options) {
List<String> terms = mkTerms(options.searchQuery());
if (terms.isEmpty()) {
return emptyList();
}
Condition externalIdCondition = terms.stream().map(term -> MEASURABLE.EXTERNAL_ID.like("%" + term + "%")).collect(Collectors.reducing(DSL.trueCondition(), (acc, frag) -> acc.and(frag)));
Condition entityLifecycleCondition = MEASURABLE.ENTITY_LIFECYCLE_STATUS.in(options.entityLifecycleStatuses());
List<Measurable> measurablesViaExternalId = dsl.selectDistinct(MEASURABLE.fields()).from(MEASURABLE).where(externalIdCondition).and(entityLifecycleCondition).orderBy(MEASURABLE.EXTERNAL_ID).limit(options.limit()).fetch(MeasurableDao.TO_DOMAIN_MAPPER);
Condition nameCondition = terms.stream().map(term -> MEASURABLE.NAME.like("%" + term + "%")).collect(Collectors.reducing(DSL.trueCondition(), (acc, frag) -> acc.and(frag)));
List<Measurable> measurablesViaName = dsl.selectDistinct(MEASURABLE.fields()).from(MEASURABLE).where(nameCondition).and(entityLifecycleCondition).orderBy(MEASURABLE.NAME).limit(options.limit()).fetch(MeasurableDao.TO_DOMAIN_MAPPER);
List<Measurable> measurablesViaFullText = dsl.fetch(FULL_TEXT_QUERY, options.searchQuery(), entityLifecycleCondition, options.limit()).map(MeasurableDao.TO_DOMAIN_MAPPER);
return new ArrayList<>(orderedUnion(measurablesViaExternalId, measurablesViaName, measurablesViaFullText));
}
Aggregations