本文整理了Java中org.apache.lucene.search.BooleanQuery.add()
方法的一些代码示例,展示了BooleanQuery.add()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BooleanQuery.add()
方法的具体详情如下:
包路径:org.apache.lucene.search.BooleanQuery
类名称:BooleanQuery
方法名:add
[英]Adds a clause to a 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: larsga/Duke
Query termQuery;
if (fuzzy_search && isFuzzy(fieldName))
termQuery = new FuzzyQuery(new Term(fieldName, term));
else
termQuery = new TermQuery(new Term(fieldName, term));
parent.add(termQuery, required ? Occur.MUST : Occur.SHOULD);
代码示例来源:origin: com.atlassian.jira/jira-core
void add(final Term term, final BooleanClause.Occur occurance)
{
if (term != null)
{
result.add(new TermQuery(term), occurance);
}
}
代码示例来源: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: org.netbeans.api/org-netbeans-modules-java-source-base
private static Query createClassWithEnclosedQuery (final String resourceName, final String sourceName) {
final BooleanQuery query = createFQNQuery(resourceName);
if (sourceName != null) {
query.add (new TermQuery(new Term (DocumentUtil.FIELD_SOURCE,sourceName)), Occur.MUST);
}
return query;
}
代码示例来源: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: 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: org.apache.lucene/lucene-spellchecker
/**
* Add a clause to a boolean query.
*/
private static void add(BooleanQuery q, String name, String value) {
q.add(new BooleanClause(new TermQuery(new Term(name, value)), BooleanClause.Occur.SHOULD));
}
代码示例来源: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: org.compass-project/compass
/**
* Add a clause to a boolean query.
*/
private static void add(BooleanQuery q, String name, String value) {
q.add(new BooleanClause(new TermQuery(new Term(name, value)), BooleanClause.Occur.SHOULD));
}
代码示例来源:origin: stackoverflow.com
BooleanQuery query = new BooleanQuery();
query.add(new TermQuery("attributeId", 7), BooleanClause.Occur.MUST);
query.add(new TermQuery("value", "hindi"), BooleanClause.Occur.MUST);
TopDocs docs = searcher.search(query, null, searchLimit);
内容来源于网络,如有侵权,请联系作者删除!