Search in sources :

Example 6 with EntitySearchOptions

use of com.khartec.waltz.model.entity_search.EntitySearchOptions in project waltz by khartec.

the class SqlServerMeasurableSearch method search.

@Override
public List<Measurable> search(DSLContext dsl, String query, EntitySearchOptions options) {
    List<String> terms = mkTerms(query);
    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)));
    List<Measurable> measurablesViaExternalId = dsl.selectDistinct(MEASURABLE.fields()).from(MEASURABLE).where(externalIdCondition).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).orderBy(MEASURABLE.NAME).limit(options.limit()).fetch(MeasurableDao.TO_DOMAIN_MAPPER);
    List<Measurable> measurablesViaFullText = dsl.selectFrom(MEASURABLE).where(JooqUtilities.MSSQL.mkContainsPrefix(terms)).limit(options.limit()).fetch(MeasurableDao.TO_DOMAIN_MAPPER);
    return new ArrayList<>(orderedUnion(measurablesViaExternalId, measurablesViaName, measurablesViaFullText));
}
Also used : Condition(org.jooq.Condition) Measurable(com.khartec.waltz.model.measurable.Measurable) DSL(org.jooq.impl.DSL) Collections.emptyList(java.util.Collections.emptyList) MEASURABLE(com.khartec.waltz.schema.tables.Measurable.MEASURABLE) Collectors(java.util.stream.Collectors) Condition(org.jooq.Condition) ArrayList(java.util.ArrayList) List(java.util.List) DSLContext(org.jooq.DSLContext) 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) SetUtilities.orderedUnion(com.khartec.waltz.common.SetUtilities.orderedUnion) FullTextSearch(com.khartec.waltz.data.FullTextSearch) MeasurableDao(com.khartec.waltz.data.measurable.MeasurableDao) Measurable(com.khartec.waltz.model.measurable.Measurable) ArrayList(java.util.ArrayList)

Example 7 with EntitySearchOptions

use of com.khartec.waltz.model.entity_search.EntitySearchOptions in project waltz by khartec.

the class SqlServerOrganisationalUnitSearch method search.

@Override
public List<OrganisationalUnit> search(DSLContext dsl, String query, EntitySearchOptions options) {
    List<String> terms = mkTerms(query);
    if (terms.isEmpty()) {
        return Collections.emptyList();
    }
    Condition nameCondition = terms.stream().map(term -> ORGANISATIONAL_UNIT.NAME.like("%" + term + "%")).collect(Collectors.reducing(DSL.trueCondition(), (acc, frag) -> acc.and(frag)));
    List<OrganisationalUnit> orgUnitsViaName = dsl.selectDistinct(ORGANISATIONAL_UNIT.fields()).from(ORGANISATIONAL_UNIT).where(nameCondition).orderBy(ORGANISATIONAL_UNIT.NAME).limit(options.limit()).fetch(OrganisationalUnitDao.TO_DOMAIN_MAPPER);
    List<OrganisationalUnit> orgUnitsViaFullText = dsl.select(ORGANISATIONAL_UNIT.fields()).from(ORGANISATIONAL_UNIT).where(JooqUtilities.MSSQL.mkContainsPrefix(terms)).limit(options.limit()).fetch(OrganisationalUnitDao.TO_DOMAIN_MAPPER);
    return new ArrayList<>(orderedUnion(orgUnitsViaName, orgUnitsViaFullText));
}
Also used : Condition(org.jooq.Condition) DSL(org.jooq.impl.DSL) OrganisationalUnit(com.khartec.waltz.model.orgunit.OrganisationalUnit) OrganisationalUnitDao(com.khartec.waltz.data.orgunit.OrganisationalUnitDao) Collectors(java.util.stream.Collectors) Condition(org.jooq.Condition) ArrayList(java.util.ArrayList) List(java.util.List) ORGANISATIONAL_UNIT(com.khartec.waltz.schema.tables.OrganisationalUnit.ORGANISATIONAL_UNIT) DSLContext(org.jooq.DSLContext) 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) OrganisationalUnit(com.khartec.waltz.model.orgunit.OrganisationalUnit)

Aggregations

EntitySearchOptions (com.khartec.waltz.model.entity_search.EntitySearchOptions)7 List (java.util.List)6 DSLContext (org.jooq.DSLContext)6 SearchUtilities.mkTerms (com.khartec.waltz.data.SearchUtilities.mkTerms)5 Condition (org.jooq.Condition)5 SetUtilities.orderedUnion (com.khartec.waltz.common.SetUtilities.orderedUnion)4 DatabaseVendorSpecific (com.khartec.waltz.data.DatabaseVendorSpecific)4 FullTextSearch (com.khartec.waltz.data.FullTextSearch)4 JooqUtilities (com.khartec.waltz.data.JooqUtilities)4 ArrayList (java.util.ArrayList)4 Collectors (java.util.stream.Collectors)4 DSL (org.jooq.impl.DSL)4 Collections (java.util.Collections)3 SearchUtilities.mkRelevancyComparator (com.khartec.waltz.data.SearchUtilities.mkRelevancyComparator)2 EntityKind (com.khartec.waltz.model.EntityKind)2 Application (com.khartec.waltz.model.application.Application)2 ImmutableEntitySearchOptions (com.khartec.waltz.model.entity_search.ImmutableEntitySearchOptions)2 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 Checks.checkNotNull (com.khartec.waltz.common.Checks.checkNotNull)1 ListUtilities (com.khartec.waltz.common.ListUtilities)1