use of org.finos.waltz.schema.Tables.SERVER_INFORMATION in project waltz by khartec.
the class MariaServerInformationSearch method searchFullText.
@Override
public List<ServerInformation> searchFullText(DSLContext dsl, EntitySearchOptions options) {
List<String> terms = SearchUtilities.mkTerms(options.searchQuery());
if (terms.isEmpty()) {
return Collections.emptyList();
}
Condition externalIdCondition = terms.stream().map(term -> SERVER_INFORMATION.EXTERNAL_ID.like(term + "%")).collect(Collectors.reducing(DSL.trueCondition(), (acc, frag) -> acc.and(frag)));
List<ServerInformation> serversViaExternalId = dsl.selectDistinct(SERVER_INFORMATION.fields()).from(SERVER_INFORMATION).where(externalIdCondition).orderBy(SERVER_INFORMATION.HOSTNAME).limit(options.limit()).fetch(ServerInformationDao.TO_DOMAIN_MAPPER);
Condition hostnameCondition = terms.stream().map(term -> SERVER_INFORMATION.HOSTNAME.like("%" + term + "%")).collect(Collectors.reducing(DSL.trueCondition(), (acc, frag) -> acc.and(frag)));
List<ServerInformation> serversViaHostname = dsl.selectDistinct(SERVER_INFORMATION.fields()).from(SERVER_INFORMATION).where(hostnameCondition).orderBy(SERVER_INFORMATION.HOSTNAME).limit(options.limit()).fetch(ServerInformationDao.TO_DOMAIN_MAPPER);
List<ServerInformation> serversViaFullText = dsl.select(SERVER_INFORMATION.fields()).from(SERVER_INFORMATION).where("MATCH(hostname, external_id, operating_system, location) AGAINST (?)", options.searchQuery()).limit(options.limit()).fetch(ServerInformationDao.TO_DOMAIN_MAPPER);
serversViaHostname.sort(SearchUtilities.mkRelevancyComparator(a -> a.hostname(), terms.get(0)));
serversViaExternalId.sort(SearchUtilities.mkRelevancyComparator(a -> a.externalId().orElse(null), terms.get(0)));
return new ArrayList<>(orderedUnion(serversViaExternalId, serversViaHostname, serversViaFullText));
}
use of org.finos.waltz.schema.Tables.SERVER_INFORMATION in project waltz by khartec.
the class ServerInformationSearchDao method search.
@Override
public List<ServerInformation> search(EntitySearchOptions options) {
checkNotNull(options, "options cannot be null");
List<String> terms = SearchUtilities.mkTerms(options.searchQuery());
if (terms.isEmpty()) {
return Collections.emptyList();
}
Condition externalIdCondition = JooqUtilities.mkStartsWithTermSearch(SERVER_INFORMATION.EXTERNAL_ID, terms);
List<ServerInformation> serversViaExternalId = dsl.select(SERVER_INFORMATION.fields()).from(SERVER_INFORMATION).where(externalIdCondition).orderBy(SERVER_INFORMATION.HOSTNAME).limit(options.limit()).fetch(ServerInformationDao.TO_DOMAIN_MAPPER);
Condition hostnameCondition = JooqUtilities.mkBasicTermSearch(SERVER_INFORMATION.HOSTNAME, terms);
List<ServerInformation> serversViaHostname = dsl.select(SERVER_INFORMATION.fields()).from(SERVER_INFORMATION).where(hostnameCondition).orderBy(SERVER_INFORMATION.HOSTNAME).limit(options.limit()).fetch(ServerInformationDao.TO_DOMAIN_MAPPER);
List<ServerInformation> serversViaFullText = searcher.searchFullText(dsl, options);
serversViaHostname.sort(SearchUtilities.mkRelevancyComparator(ServerInformation::hostname, terms.get(0)));
serversViaExternalId.sort(SearchUtilities.mkRelevancyComparator(a -> a.externalId().orElse(null), terms.get(0)));
return new ArrayList<>(orderedUnion(serversViaExternalId, serversViaHostname, serversViaFullText));
}
Aggregations