org.apache.lucene.search.BooleanQuery.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(9.9k)|赞(0)|评价(0)|浏览(157)

本文整理了Java中org.apache.lucene.search.BooleanQuery.<init>()方法的一些代码示例,展示了BooleanQuery.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BooleanQuery.<init>()方法的具体详情如下:
包路径:org.apache.lucene.search.BooleanQuery
类名称:BooleanQuery
方法名:<init>

BooleanQuery.<init>介绍

[英]Constructs an empty boolean query.
[中]构造一个空布尔查询。

代码示例

代码示例来源:origin: stackoverflow.com

BooleanQuery booleanQuery = new BooleanQuery();

TermQuery userQuery = new TermQuery(new Term("user_id", u.getId()+""));

BooleanQuery innerBooleanQuery = new BooleanQuery();
innerBooleanQuery.add(new BooleanClause(name_query, Occur.SHOULD));
innerBooleanQuery.add(new BooleanClause(desc_query, Occur.SHOULD));

booleanQuery.add(new BooleanClause(userQuery , Occur.MUST));
booleanQuery.add(new BooleanClause(innerBooleanQuery, Occur.MUST));

代码示例来源:origin: soabase/exhibitor

public Query            build(Type type)
{
  Preconditions.checkArgument(queries.size() > 0, "Query is empty");
  if ( queries.size() == 1 )
  {
    return queries.iterator().next();
  }
  BooleanQuery        query = new BooleanQuery();
  for ( Query q : queries )
  {
    query.add(q, (type == Type.AND) ? BooleanClause.Occur.MUST : BooleanClause.Occur.SHOULD);
  }
  return query;
}

代码示例来源:origin: apache/nifi

private BooleanQuery buildLineageQuery(final Collection<String> flowFileUuids) {
  // Create a query for all Events related to the FlowFiles of interest. We do this by adding all ID's as
  // "SHOULD" clauses and then setting the minimum required to 1.
  final BooleanQuery lineageQuery;
  if (flowFileUuids == null || flowFileUuids.isEmpty()) {
    lineageQuery = null;
  } else {
    lineageQuery = new BooleanQuery();
    for (final String flowFileUuid : flowFileUuids) {
      lineageQuery.add(new TermQuery(new Term(SearchableFields.FlowFileUUID.getSearchableFieldName(), flowFileUuid)), Occur.SHOULD);
    }
    lineageQuery.setMinimumNumberShouldMatch(1);
  }
  return lineageQuery;
}

代码示例来源:origin: querydsl/querydsl

protected Query stringContains(Operation<?> operation, QueryMetadata metadata, boolean ignoreCase) {
  verifyArguments(operation);
  Path<?> path = getPath(operation.getArg(0));
  String field = toField(path);
  String[] terms = convertEscaped(path, operation.getArg(1), metadata);
  if (terms.length > 1) {
    BooleanQuery bq = new BooleanQuery();
    for (String s : terms) {
      bq.add(new WildcardQuery(new Term(field, "*" + s + "*")), Occur.MUST);
    }
    return bq;
  }
  return new WildcardQuery(new Term(field, "*" + terms[0] + "*"));
}

代码示例来源:origin: stackoverflow.com

TermQuery tq= new TermQuery(new Term("url", url));
// BooleanClauses Enum SHOULD says Use this operator for clauses that should appear in the matching documents.
BooleanQuery bq = new BooleanQuery().add(tq,BooleanClause.Occur.SHOULD);
IndexSearcher searcher = new IndexSearcher(index, true);
TopScoreDocCollector collector = TopScoreDocCollector.create(10, true);
searcher.search(query, collector);

代码示例来源:origin: apache/nifi

flowFileIdQuery = null;
} else {
  flowFileIdQuery = new BooleanQuery();
  for (final String flowFileUuid : flowFileUuids) {
    flowFileIdQuery.add(new TermQuery(new Term(SearchableFields.FlowFileUUID.getSearchableFieldName(), flowFileUuid)), Occur.SHOULD);

代码示例来源:origin: querydsl/querydsl

protected Query like(Operation<?> operation, QueryMetadata metadata) {
  verifyArguments(operation);
  Path<?> path = getPath(operation.getArg(0));
  String field = toField(path);
  String[] terms = convert(path, operation.getArg(1));
  if (terms.length > 1) {
    BooleanQuery bq = new BooleanQuery();
    for (String s : terms) {
      bq.add(new WildcardQuery(new Term(field, "*" + s + "*")), Occur.MUST);
    }
    return bq;
  }
  return new WildcardQuery(new Term(field, terms[0]));
}

代码示例来源:origin: openmrs/openmrs-core

@Factory
  public Filter getFilter() {
    BooleanQuery query = new BooleanQuery();

    if (includeTerms.isEmpty()) {
      query.add(new MatchAllDocsQuery(), Occur.MUST);
    } else {
      for (Set<Term> terms : includeTerms) {

        if (terms.size() == 1) {
          query.add(new TermQuery(terms.iterator().next()), Occur.MUST);
        } else if (terms.size() > 1) {
          BooleanQuery subquery = new BooleanQuery();
          for (Term term : terms) {
            subquery.add(new TermQuery(term), Occur.SHOULD);
          }
          query.add(subquery, Occur.MUST);
        }
      }
    }

    for (Term term : excludeTerms) {
      query.add(new TermQuery(term), Occur.MUST_NOT);
    }
    
    return new CachingWrapperFilter(new QueryWrapperFilter(query));
  }
}

代码示例来源:origin: querydsl/querydsl

private Filter getFilter() {
  if (filter == null && !filters.isEmpty()) {
    BooleanQuery filterQuery = new BooleanQuery();
    for (Filter filter : filters) {
      filterQuery.add(filter, Occur.SHOULD);
    }
    filter = new QueryWrapperFilter(filterQuery);
  }
  return filter;
}

代码示例来源:origin: stackoverflow.com

int docCount = indexReader.numDocs();
IndexSearcher searcher = new IndexSearcher(indexReader);

Query queryI = new TermQuery(new Term(fieldName, termI));
Query queryJ = new TermQuery(new Term(fieldName, termJ));

Query queryIJ = new BooleanQuery();
queryIJ.add(new BooleanClause(queryI, BooleanClause.Occur.SHOULD));
queryIJ.add(new BooleanClause(queryJ, BooleanClause.Occur.SHOULD));

int countI = searcher.search(nqueryI, maxDocs).totalHits;
int countIJ = searcher.search(, maxDocs).totalHits;

float confidence = (float)countIJ / (float)countI;
float support = (float)countIJ / (float)docCount;

代码示例来源:origin: querydsl/querydsl

protected Query in(Operation<?> operation, QueryMetadata metadata, boolean ignoreCase) {
  Path<?> path = getPath(operation.getArg(0));
  String field = toField(path);
  @SuppressWarnings("unchecked") //this is the expected type
  Constant<Collection<?>> expectedConstant = (Constant<Collection<?>>) operation.getArg(1);
  Collection<?> values = expectedConstant.getConstant();
  BooleanQuery bq = new BooleanQuery();
  if (Number.class.isAssignableFrom(path.getType())) {
    for (Object value : values) {
      TermQuery eq = new TermQuery(new Term(field, convertNumber((Number) value)));
      bq.add(eq, Occur.SHOULD);
    }
  } else {
    for (Object value : values) {
      String[] str = convert(path, value);
      bq.add(eq(field, str, ignoreCase), Occur.SHOULD);
    }
  }
  return bq;
}

代码示例来源:origin: querydsl/querydsl

protected Query stringContains(Operation<?> operation, QueryMetadata metadata, boolean ignoreCase) {
  verifyArguments(operation);
  Path<?> path = getPath(operation.getArg(0));
  String field = toField(path);
  String[] terms = convertEscaped(path, operation.getArg(1), metadata);
  if (terms.length > 1) {
    BooleanQuery bq = new BooleanQuery();
    for (String s : terms) {
      bq.add(new WildcardQuery(new Term(field, "*" + s + "*")), Occur.MUST);
    }
    return bq;
  }
  return new WildcardQuery(new Term(field, "*" + terms[0] + "*"));
}

代码示例来源:origin: stackoverflow.com

BooleanQuery query = new BooleanQuery();

query.add(new TermQuery("attributeId", 10), BooleanClause.Occur.MUST); 
query.add(new TermQuery("value", "Romance"), BooleanClause.Occur.MUST); 

// build "IN" clause
BooleanQuery pidQuery = new BooleanQuery();
for( long productId : productIds ){
  pidQuery.add(new TermQuery("productId", productId), BooleanClause.Occur.SHOULD); 
}
query.add(pidQuery, BooleanClause.Occur.MUST); 
TopDocs docs = searcher.search(query, null, searchLimit);

代码示例来源:origin: querydsl/querydsl

protected Query notIn(Operation<?> operation, QueryMetadata metadata,
    boolean ignoreCase) {
  BooleanQuery bq = new BooleanQuery();
  bq.add(new BooleanClause(in(operation, metadata, false), Occur.MUST_NOT));
  bq.add(new BooleanClause(new MatchAllDocsQuery(), Occur.MUST));
  return bq;
}

代码示例来源:origin: querydsl/querydsl

protected Query in(Operation<?> operation, QueryMetadata metadata, boolean ignoreCase) {
  Path<?> path = getPath(operation.getArg(0));
  String field = toField(path);
  @SuppressWarnings("unchecked") //This is the second argument type
  Constant<Collection<?>> collConstant = (Constant<Collection<?>>) operation.getArg(1);
  Collection<?> values = collConstant.getConstant();
  BooleanQuery bq = new BooleanQuery();
  if (Number.class.isAssignableFrom(path.getType())) {
    for (Object value : values) {
      TermQuery eq = new TermQuery(new Term(field, convertNumber((Number) value)));
      bq.add(eq, Occur.SHOULD);
    }
  } else {
    for (Object value : values) {
      String[] str = convert(path, value);
      bq.add(eq(field, str, ignoreCase), Occur.SHOULD);
    }
  }
  return bq;
}

代码示例来源:origin: querydsl/querydsl

protected Query like(Operation<?> operation, QueryMetadata metadata) {
  verifyArguments(operation);
  Path<?> path = getPath(operation.getArg(0));
  String field = toField(path);
  String[] terms = convert(path, operation.getArg(1));
  if (terms.length > 1) {
    BooleanQuery bq = new BooleanQuery();
    for (String s : terms) {
      bq.add(new WildcardQuery(new Term(field, "*" + s + "*")), Occur.MUST);
    }
    return bq;
  }
  return new WildcardQuery(new Term(field, terms[0]));
}

代码示例来源:origin: stackoverflow.com

BooleanQuery topQuery = new BooleanQuery();
topQuery.add(new TermQuery(...), BooleanClause.Occur.Must);
etc.

代码示例来源:origin: querydsl/querydsl

protected Query ne(Operation<?> operation, QueryMetadata metadata,
    boolean ignoreCase) {
  BooleanQuery bq = new BooleanQuery();
  bq.add(new BooleanClause(eq(operation, metadata, ignoreCase),
      Occur.MUST_NOT));
  bq.add(new BooleanClause(new MatchAllDocsQuery(), Occur.MUST));
  return bq;
}

代码示例来源:origin: querydsl/querydsl

protected Query in(Operation<?> operation, QueryMetadata metadata,
    boolean ignoreCase) {
  Path<?> path = getPath(operation.getArg(0));
  String field = toField(path);
  @SuppressWarnings("unchecked")
  // this is the expected type
  Constant<Collection<?>> expectedConstant = (Constant<Collection<?>>) operation
      .getArg(1);
  Collection<?> values = expectedConstant.getConstant();
  BooleanQuery bq = new BooleanQuery();
  if (Number.class.isAssignableFrom(path.getType())) {
    for (Object value : values) {
      TermQuery eq = new TermQuery(new Term(field, convertNumber((Number) value)));
      bq.add(eq, Occur.SHOULD);
    }
  } else {
    for (Object value : values) {
      String[] str = convert(path, value);
      bq.add(eq(field, str, ignoreCase), Occur.SHOULD);
    }
  }
  return bq;
}

代码示例来源:origin: querydsl/querydsl

protected Query endsWith(Operation<?> operation, QueryMetadata metadata, boolean ignoreCase) {
  verifyArguments(operation);
  Path<?> path = getPath(operation.getArg(0));
  String field = toField(path);
  String[] terms = convertEscaped(path, operation.getArg(1), metadata);
  if (terms.length > 1) {
    BooleanQuery bq = new BooleanQuery();
    for (int i = 0; i < terms.length; ++i) {
      String s = i == terms.length - 1 ? "*" + terms[i] : "*" + terms[i] + "*";
      bq.add(new WildcardQuery(new Term(field, s)), Occur.MUST);
    }
    return bq;
  }
  return new WildcardQuery(new Term(field, "*" + terms[0]));
}

相关文章