Search in sources :

Example 1 with ENTITY_ALIAS

use of com.khartec.waltz.schema.tables.EntityAlias.ENTITY_ALIAS in project waltz by khartec.

the class SqlServerAppSearch method search.

@Override
public List<Application> search(DSLContext dsl, String query, EntitySearchOptions options) {
    List<String> terms = mkTerms(query);
    if (terms.isEmpty()) {
        return Collections.emptyList();
    }
    Condition lifecycleCondition = APPLICATION.ENTITY_LIFECYCLE_STATUS.in(options.entityLifecycleStatuses());
    Condition assetCodeCondition = terms.stream().map(term -> APPLICATION.ASSET_CODE.like(term + "%")).collect(Collectors.reducing(DSL.trueCondition(), (acc, frag) -> acc.and(frag)));
    List<Application> appsViaAssetCode = dsl.selectDistinct(APPLICATION.fields()).from(APPLICATION).where(assetCodeCondition).and(lifecycleCondition).orderBy(APPLICATION.NAME).limit(options.limit()).fetch(ApplicationDao.TO_DOMAIN_MAPPER);
    Condition aliasCondition = terms.stream().map(term -> ENTITY_ALIAS.ALIAS.like("%" + term + "%")).collect(Collectors.reducing(ENTITY_ALIAS.KIND.eq(EntityKind.APPLICATION.name()), (acc, frag) -> acc.and(frag)));
    List<Application> appsViaAlias = dsl.selectDistinct(APPLICATION.fields()).from(APPLICATION).innerJoin(ENTITY_ALIAS).on(ENTITY_ALIAS.ID.eq(APPLICATION.ID)).where(aliasCondition).and(lifecycleCondition).orderBy(APPLICATION.NAME).limit(options.limit()).fetch(ApplicationDao.TO_DOMAIN_MAPPER);
    Condition nameCondition = terms.stream().map(term -> APPLICATION.NAME.like("%" + term + "%")).collect(Collectors.reducing(DSL.trueCondition(), (acc, frag) -> acc.and(frag)));
    List<Application> appsViaName = dsl.selectDistinct(APPLICATION.fields()).from(APPLICATION).where(nameCondition).and(lifecycleCondition).orderBy(APPLICATION.NAME).limit(options.limit()).fetch(ApplicationDao.TO_DOMAIN_MAPPER);
    List<Application> appsViaFullText = dsl.select(APPLICATION.fields()).from(APPLICATION).where(JooqUtilities.MSSQL.mkContainsPrefix(terms)).and(lifecycleCondition).limit(options.limit()).fetch(ApplicationDao.TO_DOMAIN_MAPPER);
    appsViaName.sort(mkRelevancyComparator(a -> a.name(), terms.get(0)));
    return new ArrayList<>(orderedUnion(appsViaAssetCode, appsViaName, appsViaAlias, appsViaFullText));
}
Also used : Condition(org.jooq.Condition) Application(com.khartec.waltz.model.application.Application) DSL(org.jooq.impl.DSL) ApplicationDao(com.khartec.waltz.data.application.ApplicationDao) ENTITY_ALIAS(com.khartec.waltz.schema.tables.EntityAlias.ENTITY_ALIAS) Collectors(java.util.stream.Collectors) Condition(org.jooq.Condition) EntityKind(com.khartec.waltz.model.EntityKind) ArrayList(java.util.ArrayList) SearchUtilities.mkRelevancyComparator(com.khartec.waltz.data.SearchUtilities.mkRelevancyComparator) List(java.util.List) DSLContext(org.jooq.DSLContext) APPLICATION(com.khartec.waltz.schema.tables.Application.APPLICATION) EntitySearchOptions(com.khartec.waltz.model.entity_search.EntitySearchOptions) SearchUtilities.mkTerms(com.khartec.waltz.data.SearchUtilities.mkTerms) JooqUtilities(com.khartec.waltz.data.JooqUtilities) DatabaseVendorSpecific(com.khartec.waltz.data.DatabaseVendorSpecific) Collections(java.util.Collections) SetUtilities.orderedUnion(com.khartec.waltz.common.SetUtilities.orderedUnion) FullTextSearch(com.khartec.waltz.data.FullTextSearch) ArrayList(java.util.ArrayList) Application(com.khartec.waltz.model.application.Application)

Aggregations

SetUtilities.orderedUnion (com.khartec.waltz.common.SetUtilities.orderedUnion)1 DatabaseVendorSpecific (com.khartec.waltz.data.DatabaseVendorSpecific)1 FullTextSearch (com.khartec.waltz.data.FullTextSearch)1 JooqUtilities (com.khartec.waltz.data.JooqUtilities)1 SearchUtilities.mkRelevancyComparator (com.khartec.waltz.data.SearchUtilities.mkRelevancyComparator)1 SearchUtilities.mkTerms (com.khartec.waltz.data.SearchUtilities.mkTerms)1 ApplicationDao (com.khartec.waltz.data.application.ApplicationDao)1 EntityKind (com.khartec.waltz.model.EntityKind)1 Application (com.khartec.waltz.model.application.Application)1 EntitySearchOptions (com.khartec.waltz.model.entity_search.EntitySearchOptions)1 APPLICATION (com.khartec.waltz.schema.tables.Application.APPLICATION)1 ENTITY_ALIAS (com.khartec.waltz.schema.tables.EntityAlias.ENTITY_ALIAS)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Condition (org.jooq.Condition)1 DSLContext (org.jooq.DSLContext)1 DSL (org.jooq.impl.DSL)1