Search in sources :

Example 6 with EntitySearchOptions

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;
}
Also used : Condition(org.jooq.Condition) JooqUtilities(org.finos.waltz.data.JooqUtilities) LOGICAL_DATA_ELEMENT(org.finos.waltz.schema.tables.LogicalDataElement.LOGICAL_DATA_ELEMENT) Autowired(org.springframework.beans.factory.annotation.Autowired) Set(java.util.Set) CollectionUtilities.sort(org.finos.waltz.common.CollectionUtilities.sort) LogicalDataElementDao(org.finos.waltz.data.logical_data_element.LogicalDataElementDao) EnumUtilities(org.finos.waltz.common.EnumUtilities) SearchUtilities(org.finos.waltz.data.SearchUtilities) EntitySearchOptions(org.finos.waltz.model.entity_search.EntitySearchOptions) LogicalDataElement(org.finos.waltz.model.logical_data_element.LogicalDataElement) Condition(org.jooq.Condition) List(java.util.List) Checks.checkNotNull(org.finos.waltz.common.Checks.checkNotNull) DSLContext(org.jooq.DSLContext) SearchDao(org.finos.waltz.data.SearchDao) Repository(org.springframework.stereotype.Repository) Collections(java.util.Collections) LogicalDataElement(org.finos.waltz.model.logical_data_element.LogicalDataElement)

Example 7 with EntitySearchOptions

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));
}
Also used : Condition(org.jooq.Condition) DSL(org.jooq.impl.DSL) MeasurableDao(org.finos.waltz.data.measurable.MeasurableDao) Collections.emptyList(java.util.Collections.emptyList) DatabaseVendorSpecific(org.finos.waltz.data.DatabaseVendorSpecific) Collectors(java.util.stream.Collectors) EntitySearchOptions(org.finos.waltz.model.entity_search.EntitySearchOptions) Condition(org.jooq.Condition) ArrayList(java.util.ArrayList) List(java.util.List) Measurable(org.finos.waltz.model.measurable.Measurable) MEASURABLE(org.finos.waltz.schema.tables.Measurable.MEASURABLE) FullTextSearch(org.finos.waltz.data.FullTextSearch) DSLContext(org.jooq.DSLContext) SetUtilities.orderedUnion(org.finos.waltz.common.SetUtilities.orderedUnion) SearchUtilities.mkTerms(org.finos.waltz.data.SearchUtilities.mkTerms) Measurable(org.finos.waltz.model.measurable.Measurable) ArrayList(java.util.ArrayList)

Aggregations

EntitySearchOptions (org.finos.waltz.model.entity_search.EntitySearchOptions)7 List (java.util.List)6 DSLContext (org.jooq.DSLContext)5 Condition (org.jooq.Condition)4 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 SetUtilities.orderedUnion (org.finos.waltz.common.SetUtilities.orderedUnion)3 ImmutableEntitySearchOptions (org.finos.waltz.model.entity_search.ImmutableEntitySearchOptions)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 Collections.emptyList (java.util.Collections.emptyList)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Checks.checkNotNull (org.finos.waltz.common.Checks.checkNotNull)2 DatabaseVendorSpecific (org.finos.waltz.data.DatabaseVendorSpecific)2 FullTextSearch (org.finos.waltz.data.FullTextSearch)2 SearchUtilities (org.finos.waltz.data.SearchUtilities)2 ServerInformationDao (org.finos.waltz.data.server_information.ServerInformationDao)2 EntityKind (org.finos.waltz.model.EntityKind)2 ServerInformation (org.finos.waltz.model.server_information.ServerInformation)2 SERVER_INFORMATION (org.finos.waltz.schema.Tables.SERVER_INFORMATION)2