org.elasticsearch.index.query.OrFilterBuilder Java Examples
The following examples show how to use
org.elasticsearch.index.query.OrFilterBuilder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SiteElasticSearchIndexBuilder.java From sakai with Educational Community License v2.0 | 6 votes |
@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); }
Example #2
Source File: SiteElasticSearchIndexBuilder.java From sakai with Educational Community License v2.0 | 6 votes |
@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()); }
Example #3
Source File: SiteElasticSearchIndexBuilder.java From sakai with Educational Community License v2.0 | 6 votes |
@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); }
Example #4
Source File: SiteElasticSearchIndexBuilder.java From sakai with Educational Community License v2.0 | 6 votes |
@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()); }
Example #5
Source File: ProductQueryServiceImpl.java From elasticsearch-tutorial with MIT License | 4 votes |
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; }
Example #6
Source File: ProductQueryServiceImpl.java From searchanalytics-bigdata with MIT License | 4 votes |
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; }