Package org.elasticsearch.index.query

Examples of org.elasticsearch.index.query.BoolFilterBuilder


            return null;
        }
    }

    private BoolFilterBuilder standardFilters(TimeRange range, String filter) throws IndexHelper.InvalidRangeFormatException {
        BoolFilterBuilder bfb = FilterBuilders.boolFilter();

        boolean set = false;

        if (range != null) {
            bfb.must(IndexHelper.getTimestampRangeFilter(range));
            set = true;
        }

        if (filter != null && !filter.isEmpty() && !filter.equals("*")) {
            bfb.must(FilterBuilders.queryFilter(QueryBuilders.queryString(filter)));
            set = true;
        }

        if (!set) {
            throw new RuntimeException("Either range or filter must be set.");
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

  *@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 allowParentOpen = new TermFilterBuilder(fieldAllowParent,NOSECURITY_TOKEN);
    FilterBuilder denyParentOpen = new TermFilterBuilder(fieldDenyParent,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(allowParentOpen);
      bq.must(denyParentOpen);
      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));
      bq.must(calculateCompleteSubquery(fieldAllowParent,fieldDenyParent,allowParentOpen,denyParentOpen,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

                          FilterBuilders.termsFilter(EntityPojo.index_, entIndex, alias.getAlias()));
              if (null == qfb) {
                fb = fb.facetFilter(nfb);
              }//TESTED
              else {
                BoolFilterBuilder bfb = FilterBuilders.boolFilter().should(nfb).should(qfb);
                fb = fb.facetFilter(bfb);
              }//TESTED
            }
            else if (null != qfb) {
              fb = fb.facetFilter(qfb);
View Full Code Here

    String[] assocVerbFilterStrings;
  }
 
  private InternalTempFilterInfo getBaseFilter(AdvancedQueryPojo query, String communityIdStrs[])
  {
    BoolFilterBuilder parentFilterObj =
        FilterBuilders.boolFilter().must(FilterBuilders.termsFilter(DocumentPojo.communityId_, communityIdStrs));
     
    BoolFilterBuilder sourceFilter = this.parseSourceManagement(query.input);
   
    if (null != sourceFilter) {
      parentFilterObj = parentFilterObj.must(sourceFilter);
    }//TESTED
   
  // 0.2] Output filtering 
   
    // Output filters: parse (also used by aggregation, scoring)
   
    String[] entityTypeFilterStrings = null;
    String[] assocVerbFilterStrings = null;
    if ((null != query.output) && (null != query.output.filter)) {
      if (null != query.output.filter.entityTypes) {
        entityTypeFilterStrings = query.output.filter.entityTypes;
        if (0 == entityTypeFilterStrings.length) {
          entityTypeFilterStrings = null;
        }
        else if ((1 == entityTypeFilterStrings.length) && (entityTypeFilterStrings[0].isEmpty())) {
          entityTypeFilterStrings = null;         
        }
        // (note this is important because it means we can always check entityTypeFilterStrings[0].getCharAt(0) for -ve filtering)
      }
      if (null != query.output.filter.assocVerbs) {
        assocVerbFilterStrings = query.output.filter.assocVerbs;       
        if (0 == assocVerbFilterStrings.length) {
          assocVerbFilterStrings = null;
        }
        else if ((1 == assocVerbFilterStrings.length) && (assocVerbFilterStrings[0].isEmpty())) {
          assocVerbFilterStrings = null;         
        }
        // (note this is important because it means we can always check assocVerbFilterStrings[0].getCharAt(0) for -ve filtering)
      }
    }
   
    // Now apply output filters to query
   
    BoolFilterBuilder outputFilter = this.parseOutputFiltering(entityTypeFilterStrings, assocVerbFilterStrings);
    if (null != outputFilter) {
      parentFilterObj = parentFilterObj.must(outputFilter);
    }
    //TESTED
View Full Code Here

// 1.1] Source management utility
 
  BoolFilterBuilder parseSourceManagement(AdvancedQueryPojo.QueryInputPojo input) {
   
    BoolFilterBuilder sourceFilter = null;
   
    if ((null != input.tags) || (null != input.typeAndTags)
        || (null != input.sources))
    {
      sourceFilter = FilterBuilders.boolFilter();
    }//TESTED
   
    if (null != input.tags) {
      sourceFilter = sourceFilter.should(FilterBuilders.termsFilter(DocumentPojo.tags_, input.tags.toArray()));
    }//TESTED '{ "input": { "tags": [ "healthcare", "cyber" ] } }'
   
    if (null != input.typeAndTags) {
      BoolFilterBuilder typeAndTagFilter = FilterBuilders.boolFilter();
      for (AdvancedQueryPojo.QueryInputPojo.TypeAndTagTermPojo tt: input.typeAndTags) {
        if (null != tt.tags) {
          typeAndTagFilter = typeAndTagFilter.should(
              FilterBuilders.boolFilter().must(FilterBuilders.termFilter(DocumentPojo.mediaType_, tt.type)).
                            must(FilterBuilders.termsFilter(DocumentPojo.tags_, tt.tags.toArray())));
        }
        else {
          typeAndTagFilter = typeAndTagFilter.should(FilterBuilders.termFilter(DocumentPojo.mediaType_, tt.type));
        }
      }
      sourceFilter = sourceFilter.should(typeAndTagFilter);
    }//TESTED '{ "input": { "typeAndTags": [ { "type": "Social" }, { "type": "Video", "tags": [ "education", "MIT" ] } ] } }'
   
View Full Code Here

    return outputFilter;
  }//TESTED
 
  BoolFilterBuilder parseOutputFiltering(String[] entityTypeFilterStrings, String[] assocVerbFilterStrings)
  {
    BoolFilterBuilder outputFilter = null;
   
    // First off: document discard aliases:
   
    if (null != _aliasLookup) { // Check out the document discard table...     
      EntityFeaturePojo docDiscardAlias = _aliasLookup.getAliases("DOCUMENT_DISCARD");
      if (null != docDiscardAlias) {       
        outputFilter = addNegativeSelectorToFilter(docDiscardAlias, outputFilter, 0);
      }           
    }//TESTED (by hand, nothing repeatable)
   
    // Other simple filter types:
   
    if (null != entityTypeFilterStrings) {
      if ('-' != entityTypeFilterStrings[0].charAt(0)) { // (negative entity type, don't add to filter)
        outputFilter = FilterBuilders.boolFilter();
               
        outputFilter.must(FilterBuilders.nestedFilter(DocumentPojo.entities_,
            FilterBuilders.termsFilter(EntityPojo.docQuery_type_, entityTypeFilterStrings)));
      }
    }
    if (null != assocVerbFilterStrings) {
      if ('-' != assocVerbFilterStrings[0].charAt(0)) { // (negative verb, don't add to filter)
        if (null == outputFilter) {
          outputFilter = FilterBuilders.boolFilter();       
        }
        BoolFilterBuilder verbFilter = FilterBuilders.boolFilter()
        StringBuffer sb = new StringBuffer();
        for (String assocVerb: assocVerbFilterStrings) {
          sb.setLength(0);
          sb.append('"').append(assocVerb).append('"');
          verbFilter.should(FilterBuilders.nestedFilter(DocumentPojo.associations_,
              QueryBuilders.queryString(sb.toString()).field(AssociationPojo.docQuery_verb_category_)));
          //(closest to exact that we can manage, obv verb_cat should actually be not_analyzed)
        }
        outputFilter.must(verbFilter);
      }
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.