Package org.elasticsearch.index.query

Examples of org.elasticsearch.index.query.BoolFilterBuilder


        for (Map.Entry<Float, Collection<String>> invTypeEl: invTypeWeights.asMap().entrySet()) {
          if (null == score.sourceWeights) { // Easy case
            manualWeights.add(FilterBuilders.termsFilter(DocumentPojo.mediaType_, invTypeEl.getValue().toArray()), invTypeEl.getKey());
          }
          else { // Need to filter out sources they are matched with higher prio
            BoolFilterBuilder typesNotSources = FilterBuilders.boolFilter();
            typesNotSources = typesNotSources.must(FilterBuilders.termsFilter(DocumentPojo.mediaType_, invTypeEl.getValue().toArray())).
                              mustNot(FilterBuilders.termsFilter(DocumentPojo.sourceKey_, score.sourceWeights.keySet().toArray()));
           
            manualWeights.add(typesNotSources, invTypeEl.getKey());
          }
        }
      }//TESTED
      if (null != score.tagWeights) {
        // Find all weightings with the same score:
        ArrayListMultimap<Float, String> invTagWeights = ArrayListMultimap.create();
        for (Map.Entry<String, Double> tagEl: score.tagWeights.entrySet()) {
          invTagWeights.put((float)(double)tagEl.getValue(), tagEl.getKey());
        }
        for (Map.Entry<Float, Collection<String>> invTagEl: invTagWeights.asMap().entrySet()) {
          if ((null == score.sourceWeights) && (null == score.typeWeights)) { // Easy case
            manualWeights.add(FilterBuilders.termsFilter(DocumentPojo.tags_, invTagEl.getValue().toArray()), invTagEl.getKey());
          }
          else { // need to exclude types or sources
            BoolFilterBuilder typesNotSources = FilterBuilders.boolFilter();
            BoolFilterBuilder tagsAndNothingElse = typesNotSources.must(FilterBuilders.termsFilter(DocumentPojo.tags_, invTagEl.getValue().toArray()));
            if (null != score.sourceWeights) {
              tagsAndNothingElse = tagsAndNothingElse.mustNot(FilterBuilders.termsFilter(DocumentPojo.sourceKey_, score.sourceWeights.keySet().toArray()));
            }
            if (null != score.typeWeights) {
              tagsAndNothingElse = tagsAndNothingElse.mustNot(FilterBuilders.termsFilter(DocumentPojo.mediaType_, score.typeWeights.keySet().toArray()));
            }
            manualWeights.add(tagsAndNothingElse, invTagEl.getKey());
          }
        }
      }//TESTED
View Full Code Here


  *@return the wrapped query enforcing ManifoldCF security.
  */
  public FilterBuilder buildAuthorizationFilter(List<String> userAccessTokens)
    throws AuthorizerException
  {
    BoolFilterBuilder bq = new BoolFilterBuilder();
   
    FilterBuilder allowShareOpen = new TermFilterBuilder(fieldAllowShare,NOSECURITY_TOKEN);
    FilterBuilder denyShareOpen = new TermFilterBuilder(fieldDenyShare,NOSECURITY_TOKEN);
    FilterBuilder allowDocumentOpen = new TermFilterBuilder(fieldAllowDocument,NOSECURITY_TOKEN);
    FilterBuilder denyDocumentOpen = new TermFilterBuilder(fieldDenyDocument,NOSECURITY_TOKEN);
   
    if (userAccessTokens == null || userAccessTokens.size() == 0)
    {
      // Only open documents can be included.
      // That query is:
      // (fieldAllowShare is empty AND fieldDenyShare is empty AND fieldAllowDocument is empty AND fieldDenyDocument is empty)
      // We're trying to map to:  -(fieldAllowShare:*) , which should be pretty efficient in Solr because it is negated.  If this turns out not to be so, then we should
      // have the SolrConnector inject a special token into these fields when they otherwise would be empty, and we can trivially match on that token.
      bq.must(allowShareOpen);
      bq.must(denyShareOpen);
      bq.must(allowDocumentOpen);
      bq.must(denyDocumentOpen);
    }
    else
    {
      // Extend the query appropriately for each user access token.
      bq.must(calculateCompleteSubquery(fieldAllowShare,fieldDenyShare,allowShareOpen,denyShareOpen,userAccessTokens));
      bq.must(calculateCompleteSubquery(fieldAllowDocument,fieldDenyDocument,allowDocumentOpen,denyDocumentOpen,userAccessTokens));
    }

    return bq;
  }
View Full Code Here

  * ((fieldAllowShare is empty AND fieldDenyShare is empty) OR fieldAllowShare HAS token1 OR fieldAllowShare HAS token2 ...)
  *     AND fieldDenyShare DOESN'T_HAVE token1 AND fieldDenyShare DOESN'T_HAVE token2 ...
  */
  protected static FilterBuilder calculateCompleteSubquery(String allowField, String denyField, FilterBuilder allowOpen, FilterBuilder denyOpen, List<String> userAccessTokens)
  {
    BoolFilterBuilder bq = new BoolFilterBuilder();
    // No ES equivalent - hope this is done right inside
    //bq.setMaxClauseCount(1000000);
   
    // Add the empty-acl case
    BoolFilterBuilder subUnprotectedClause = new BoolFilterBuilder();
    subUnprotectedClause.must(allowOpen);
    subUnprotectedClause.must(denyOpen);
    bq.should(subUnprotectedClause);
    for (String accessToken : userAccessTokens)
    {
      bq.should(new TermFilterBuilder(allowField,accessToken));
      bq.mustNot(new TermFilterBuilder(denyField,accessToken));
View Full Code Here

      String[] tags, Pager... pager) {
    if (tags == null || tags.length == 0 || StringUtils.isBlank(appid)) {
      return new ArrayList<P>();
    }

    BoolFilterBuilder tagFilter = FilterBuilders.boolFilter();
    //assuming clean & safe tags here
    for (String tag : tags) {
      tagFilter.must(FilterBuilders.termFilter(Config._TAGS, tag));
    }
    QueryBuilder qb = QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(), tagFilter);
    // The filter looks like this: ("tag1" OR "tag2" OR "tag3") AND "type"
    return searchQuery(appid, type, qb, pager);
  }
View Full Code Here

  public AggregationBuilder buildStickyFacet(String fieldName, String facetName, Object... selected) {
    return buildStickyFacet(fieldName, facetName, FACET_DEFAULT_SIZE, selected);
  }

  public AggregationBuilder buildStickyFacet(String fieldName, String facetName, int size, Object... selected) {
    BoolFilterBuilder facetFilter = getStickyFacetFilter(fieldName);
    FilterAggregationBuilder facetTopAggregation = buildTopFacetAggregation(fieldName, facetName, facetFilter, size);
    facetTopAggregation = addSelectedItemsToFacet(fieldName, facetName, facetTopAggregation, selected);

    return AggregationBuilders
      .global(facetName)
View Full Code Here

      .global(facetName)
      .subAggregation(facetTopAggregation);
  }

  public BoolFilterBuilder getStickyFacetFilter(String fieldName) {
    BoolFilterBuilder facetFilter = FilterBuilders.boolFilter().must(FilterBuilders.queryFilter(query));
    for (Map.Entry<String, FilterBuilder> filter : filters.entrySet()) {
      if (filter.getValue() != null && !StringUtils.equals(filter.getKey(), fieldName)) {
        facetFilter.must(filter.getValue());
      }
    }
    return facetFilter;
  }
View Full Code Here

      String[] tags, Pager... pager) {
    if (tags == null || tags.length == 0 || StringUtils.isBlank(appid)) {
      return new ArrayList<P>();
    }

    BoolFilterBuilder tagFilter = FilterBuilders.boolFilter();
    //assuming clean & safe tags here
    for (String tag : tags) {
      tagFilter.must(FilterBuilders.termFilter(Config._TAGS, tag));
    }
    QueryBuilder qb = QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(), tagFilter);
    // The filter looks like this: ("tag1" OR "tag2" OR "tag3") AND "type"
    return searchQuery(appid, type, qb, pager);
  }
View Full Code Here

      String[] tags, Pager... pager) {
    if (tags == null || tags.length == 0 || StringUtils.isBlank(appid)) {
      return new ArrayList<P>();
    }

    BoolFilterBuilder tagFilter = FilterBuilders.boolFilter();
    //assuming clean & safe tags here
    for (String tag : tags) {
      tagFilter.must(FilterBuilders.termFilter(Config._TAGS, tag));
    }
    QueryBuilder qb = QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(), tagFilter);
    // The filter looks like this: ("tag1" OR "tag2" OR "tag3") AND "type"
    return searchQuery(appid, type, qb, pager);
  }
View Full Code Here

      String[] tags, Pager... pager) {
    if (tags == null || tags.length == 0 || StringUtils.isBlank(appid)) {
      return new ArrayList<P>();
    }

    BoolFilterBuilder tagFilter = FilterBuilders.boolFilter();
    //assuming clean & safe tags here
    for (String tag : tags) {
      tagFilter.must(FilterBuilders.termFilter(Config._TAGS, tag));
    }
    QueryBuilder qb = QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(), tagFilter);
    // The filter looks like this: ("tag1" OR "tag2" OR "tag3") AND "type"
    return searchQuery(appid, type, qb, pager);
  }
View Full Code Here

                // get all types that need to be deleted.
                ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> result = clusterService.state().metaData().findMappings(
                        concreteIndices, request.types()
                );
                // create OrFilter with type filters within to account for different types
                BoolFilterBuilder filterBuilder = new BoolFilterBuilder();
                Set<String> types = new HashSet<>();
                for (ObjectObjectCursor<String, ImmutableOpenMap<String, MappingMetaData>> typesMeta : result) {
                    for (ObjectObjectCursor<String, MappingMetaData> type : typesMeta.value) {
                        filterBuilder.should(new TypeFilterBuilder(type.key));
                        types.add(type.key);
                    }
                }
                if (types.size() == 0) {
                    throw new TypeMissingException(new Index("_all"), request.types(), "No index has the type.");
View Full Code Here

TOP

Related Classes of org.elasticsearch.index.query.BoolFilterBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.