private Optional<OrFilterBuilder> itemTypesFilter() { if (!itemTypesPanes.getSelected().isEmpty()) { List<FilterBuilder> itemTypeFilters = itemTypesPanes.getSelected() .stream() .map(it -> { FilterBuilder itFilter = termFilter("attributes.itemType", it.itemType()); if (it.equipType() != null) { itFilter = andFilter(itFilter, termFilter("attributes.equipType", it.equipType())); } return itFilter; }) .collect(Collectors.toList()); return Optional.of(orFilter(toArray(itemTypeFilters, FilterBuilder.class))); } return Optional.empty(); }
@Override protected Pair<SearchRequestBuilder,QueryBuilder> addSearchSiteIds(Pair<SearchRequestBuilder,QueryBuilder> builders, List<String> siteIds) { SearchRequestBuilder searchRequestBuilder = builders.getLeft(); BoolQueryBuilder queryBuilder = (BoolQueryBuilder)builders.getRight(); // if we have sites filter results to include only the sites included if (siteIds.size() > 0) { searchRequestBuilder = searchRequestBuilder.setRouting(siteIds.toArray(new String[siteIds.size()])); // creating config whether or not to use filter, there are performance and caching differences that // maybe implementation decisions if (useSiteFilters) { OrFilterBuilder siteFilter = orFilter().add( termsFilter(SearchService.FIELD_SITEID, siteIds.toArray(new String[siteIds.size()])).execution("bool")); searchRequestBuilder = searchRequestBuilder.setPostFilter(siteFilter); } else { queryBuilder = queryBuilder.must(termsQuery(SearchService.FIELD_SITEID, siteIds.toArray(new String[siteIds.size()]))); } } return pairOf(searchRequestBuilder,queryBuilder); }
@Override protected Pair<SearchRequestBuilder, QueryBuilder> addSearchSuggestionsSites(Pair<SearchRequestBuilder, QueryBuilder> builders, String currentSite, boolean allMySites) { String currentUser = ""; User user = userDirectoryService.getCurrentUser(); if (user != null) { currentUser = user.getId(); } String[] sites; if (allMySites || currentSite == null) { sites = getAllUsersSites(currentUser); } else { sites = new String[]{currentSite}; } OrFilterBuilder siteFilter = orFilter().add( termsFilter(SearchService.FIELD_SITEID, sites).execution("bool")); SearchRequestBuilder searchRequestBuilder = builders.getLeft() .setRouting(sites) .setPostFilter(siteFilter); return pairOf(searchRequestBuilder, builders.getRight()); }
public static FilterBuilder buildTopicIdFilter( ImmutableList<ImmutableList<InclusionExclusionId>> topicIdSets ) { ImmutableList.Builder<FilterBuilder> topicIdFilters = ImmutableList.builder(); for (List<InclusionExclusionId> idSet : topicIdSets) { BoolFilterBuilder filterForThisSet = FilterBuilders.boolFilter(); for (InclusionExclusionId id : idSet) { addFilterForTopicId(filterForThisSet, id); } topicIdFilters.add(filterForThisSet); } OrFilterBuilder orFilter = FilterBuilders.orFilter(); topicIdFilters.build().forEach(orFilter::add); return orFilter; }
public static FilterBuilder buildActionableFilter( Map<String, String> actionableParams, Optional<Id> maybeRegionId, ChannelGroupResolver channelGroupResolver ) { OrFilterBuilder orFilterBuilder = FilterBuilders.orFilter(); if (actionableParams.get("location.available") != null) { orFilterBuilder.add(buildAvailabilityFilter()); } DateTime broadcastTimeGreaterThan = actionableParams.get("broadcast.time.gt") == null ? null : DateTime.parse(actionableParams.get("broadcast.time.gt")); DateTime broadcastTimeLessThan = actionableParams.get("broadcast.time.lt") == null ? null : DateTime.parse(actionableParams.get("broadcast.time.lt")); if (broadcastTimeGreaterThan != null || broadcastTimeLessThan != null) { orFilterBuilder.add( buildBroadcastRangeFilter( broadcastTimeGreaterThan, broadcastTimeLessThan, maybeRegionId, channelGroupResolver ) ); } return orFilterBuilder; }
private FilterBuilder getSpecificationsFacetFilterBuilder(SearchCriteria searchCriteria) { //This is used in case you want to search based on separate resolution/memory facets Map<String, List<String>> multiSelectFilters = searchCriteria.getMultiSelectFilters(); List<String> resolutionFilters = new ArrayList<String>(); List<String> memoryFilters = new ArrayList<String>(); for (Entry<String, List<String>> entry : multiSelectFilters.entrySet()) { if(entry.getKey().equals(SearchFacetName.SPECIFICATION_RESOLUTION.getCode())) { resolutionFilters.addAll(entry.getValue()); } else if(entry.getKey().equals(SearchFacetName.SPECIFICATION_MEMORY.getCode())) { memoryFilters.addAll(entry.getValue()); } } if(resolutionFilters.size() == 0 && memoryFilters.size() == 0 ) { return FilterBuilders.queryFilter(QueryBuilders.matchAllQuery()); } AndFilterBuilder andResolutionAndMemoryFilterBuilder = FilterBuilders.andFilter(); if(resolutionFilters.size() > 0) { OrFilterBuilder OrResolutionFilterBuilder = FilterBuilders.orFilter(); for (String resolution : resolutionFilters) { OrResolutionFilterBuilder.add(FilterBuilders.termFilter(SearchDocumentFieldName.RESOLUTION.getFieldName(), resolution)); } andResolutionAndMemoryFilterBuilder.add(OrResolutionFilterBuilder); } if(memoryFilters.size() > 0) { OrFilterBuilder OrMemoryFilterBuilder = FilterBuilders.orFilter(); for (String memory : memoryFilters) { OrMemoryFilterBuilder.add(FilterBuilders.termFilter(SearchDocumentFieldName.MEMORY.getFieldName(), memory)); } andResolutionAndMemoryFilterBuilder.add(OrMemoryFilterBuilder); } // else if(specifications.size() == 1) // { // Specification specification = searchCriteria.getSpecifications().get(0); // // FilterBuilder filterBuilder = FilterBuilders.andFilter(FilterBuilders // .termFilter(SearchDocumentFieldName.RESOLUTION.getFieldName(), specification.getResolution()), // FilterBuilders.termFilter(SearchDocumentFieldName.MEMORY.getFieldName(), specification.getMemory())); // // specificationFilterBuilder = filterBuilder; // } // else // { // specificationFilterBuilder = FilterBuilders.matchAllFilter(); // } return andResolutionAndMemoryFilterBuilder; }
private FilterBuilder getSpecificationsFacetFilterBuilder(final SearchCriteria searchCriteria) { // This is used in case you want to search based on separate resolution/memory facets final Map<String, List<String>> multiSelectFilters = searchCriteria.getMultiSelectFilters(); final List<String> resolutionFilters = new ArrayList<String>(); final List<String> memoryFilters = new ArrayList<String>(); for (final Entry<String, List<String>> entry : multiSelectFilters.entrySet()) { if (entry.getKey().equals(SearchFacetName.SPECIFICATION_RESOLUTION.getCode())) { resolutionFilters.addAll(entry.getValue()); } else if (entry.getKey().equals(SearchFacetName.SPECIFICATION_MEMORY.getCode())) { memoryFilters.addAll(entry.getValue()); } } if (resolutionFilters.size() == 0 && memoryFilters.size() == 0) { return FilterBuilders.queryFilter(QueryBuilders.matchAllQuery()); } final AndFilterBuilder andResolutionAndMemoryFilterBuilder = FilterBuilders.andFilter(); if (resolutionFilters.size() > 0) { final OrFilterBuilder OrResolutionFilterBuilder = FilterBuilders.orFilter(); for (final String resolution : resolutionFilters) { OrResolutionFilterBuilder.add(FilterBuilders.termFilter(SearchDocumentFieldName.RESOLUTION.getFieldName(), resolution)); } andResolutionAndMemoryFilterBuilder.add(OrResolutionFilterBuilder); } if (memoryFilters.size() > 0) { final OrFilterBuilder OrMemoryFilterBuilder = FilterBuilders.orFilter(); for (final String memory : memoryFilters) { OrMemoryFilterBuilder.add(FilterBuilders.termFilter(SearchDocumentFieldName.MEMORY.getFieldName(), memory)); } andResolutionAndMemoryFilterBuilder.add(OrMemoryFilterBuilder); } // else if(specifications.size() == 1) // { // Specification specification = searchCriteria.getSpecifications().get(0); // // FilterBuilder filterBuilder = FilterBuilders.andFilter(FilterBuilders // .termFilter(SearchDocumentFieldName.RESOLUTION.getFieldName(), specification.getResolution()), // FilterBuilders.termFilter(SearchDocumentFieldName.MEMORY.getFieldName(), specification.getMemory())); // // specificationFilterBuilder = filterBuilder; // } // else // { // specificationFilterBuilder = FilterBuilders.matchAllFilter(); // } return andResolutionAndMemoryFilterBuilder; }
private FilterBuilder getSpecificationsFacetFilterBuilder( final SearchCriteria searchCriteria) { // This is used in case you want to search based on separate // resolution/memory facets final Map<String, List<String>> multiSelectFilters = searchCriteria .getMultiSelectFilters(); final List<String> resolutionFilters = new ArrayList<String>(); final List<String> memoryFilters = new ArrayList<String>(); for (final Entry<String, List<String>> entry : multiSelectFilters .entrySet()) { if (entry.getKey().equals( SearchFacetName.SPECIFICATION_RESOLUTION.getCode())) { resolutionFilters.addAll(entry.getValue()); } else if (entry.getKey().equals( SearchFacetName.SPECIFICATION_MEMORY.getCode())) { memoryFilters.addAll(entry.getValue()); } } if (resolutionFilters.size() == 0 && memoryFilters.size() == 0) { return FilterBuilders.queryFilter(QueryBuilders.matchAllQuery()); } final AndFilterBuilder andResolutionAndMemoryFilterBuilder = FilterBuilders .andFilter(); if (resolutionFilters.size() > 0) { final OrFilterBuilder OrResolutionFilterBuilder = FilterBuilders .orFilter(); for (final String resolution : resolutionFilters) { OrResolutionFilterBuilder.add(FilterBuilders.termFilter( SearchDocumentFieldName.RESOLUTION.getFieldName(), resolution)); } andResolutionAndMemoryFilterBuilder.add(OrResolutionFilterBuilder); } if (memoryFilters.size() > 0) { final OrFilterBuilder OrMemoryFilterBuilder = FilterBuilders .orFilter(); for (final String memory : memoryFilters) { OrMemoryFilterBuilder.add(FilterBuilders.termFilter( SearchDocumentFieldName.MEMORY.getFieldName(), memory)); } andResolutionAndMemoryFilterBuilder.add(OrMemoryFilterBuilder); } // else if(specifications.size() == 1) // { // Specification specification = // searchCriteria.getSpecifications().get(0); // // FilterBuilder filterBuilder = FilterBuilders.andFilter(FilterBuilders // .termFilter(SearchDocumentFieldName.RESOLUTION.getFieldName(), // specification.getResolution()), // FilterBuilders.termFilter(SearchDocumentFieldName.MEMORY.getFieldName(), // specification.getMemory())); // // specificationFilterBuilder = filterBuilder; // } // else // { // specificationFilterBuilder = FilterBuilders.matchAllFilter(); // } return andResolutionAndMemoryFilterBuilder; }