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

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

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

BooleanQuery.getClauses介绍

[英]Returns the set of clauses in this query.
[中]返回此查询中的子句集。

代码示例

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

/**
 * If the query is a BooleanQuery and it contains a single Occur.MUST_NOT
 * clause it will be returned as is. Otherwise it will be wrapped in a
 * BooleanClause with the given Occur.
 */
private BooleanClause createBooleanClause(Query query, Occur occur) {
  if (query instanceof BooleanQuery) {
    BooleanClause[] clauses = ((BooleanQuery) query).getClauses();
    if (clauses.length == 1 && clauses[0].getOccur().equals(Occur.MUST_NOT)) {
      return clauses[0];
    }
  }
  return new BooleanClause(query, occur);
}

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

/**
 * If the query is a BooleanQuery and it contains a single Occur.MUST_NOT
 * clause it will be returned as is. Otherwise it will be wrapped in a
 * BooleanClause with the given Occur.
 */
private BooleanClause createBooleanClause(Query query, Occur occur) {
  if (query instanceof BooleanQuery) {
    BooleanClause[] clauses = ((BooleanQuery) query).getClauses();
    if (clauses.length == 1 && clauses[0].getOccur().equals(Occur.MUST_NOT)) {
      return clauses[0];
    }
  }
  return new BooleanClause(query, occur);
}

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

/**
 * If the query is a BooleanQuery and it contains a single Occur.MUST_NOT
 * clause it will be returned as is. Otherwise it will be wrapped in a
 * BooleanClause with the given Occur.
 */
private BooleanClause createBooleanClause(Query query, Occur occur) {
  if (query instanceof BooleanQuery) {
    BooleanClause[] clauses = ((BooleanQuery) query).getClauses();
    if (clauses.length == 1
        && clauses[0].getOccur().equals(Occur.MUST_NOT)) {
      return clauses[0];
    }
  }
  return new BooleanClause(query, occur);
}

代码示例来源:origin: org.apache.lucene/lucene-core

final int numOptionalClauses = query.getClauses(Occur.SHOULD).size();
final int numRequiredClauses = query.getClauses(Occur.MUST).size() + query.getClauses(Occur.FILTER).size();

代码示例来源:origin: linkedin/indextank-engine

public org.apache.lucene.search.Query getLuceneQuery() {
  BooleanQuery bq = new BooleanQuery();
  if (leftQuery instanceof OrQuery) {
    for (BooleanClause bc : ((BooleanQuery)leftQuery.getLuceneQuery()).getClauses()) {
      bq.add(bc);
    }
  } else {
    bq.add(leftQuery.getLuceneQuery(), BooleanClause.Occur.SHOULD);
  }
  if (rightQuery instanceof OrQuery) {
    for (BooleanClause bc : ((BooleanQuery)rightQuery.getLuceneQuery()).getClauses()) {
      bq.add(bc);
    }            
  } else {
    bq.add(rightQuery.getLuceneQuery(), BooleanClause.Occur.SHOULD);
  }
  return bq;
}

代码示例来源:origin: linkedin/indextank-engine

@Override
public org.apache.lucene.search.Query getLuceneQuery() {
  BooleanQuery bq = new BooleanQuery();
  if (leftQuery instanceof AndQuery) {
    for (BooleanClause bc : ((BooleanQuery)leftQuery.getLuceneQuery()).getClauses()) {
      bq.add(bc);
    }
  } else {
    bq.add(leftQuery.getLuceneQuery(), BooleanClause.Occur.MUST);
  }
  if (rightQuery instanceof AndQuery) {
    for (BooleanClause bc : ((BooleanQuery)rightQuery.getLuceneQuery()).getClauses()) {
      bq.add(bc);
    }            
  } else {
    bq.add(rightQuery.getLuceneQuery(), BooleanClause.Occur.MUST);
  }
  return bq;
}

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

BooleanQuery query = (BooleanQuery)parser.parse;
BooleanClause[] clauses = query.getClauses();
if (clauses.length == 1 && clauses[0].getOccur() == BooleanClause.Occur.MUST_NOT) {
  booleanQuery.add(clauses[0]);
} else {
  booleanQuery.add(query, BooleanClause.Occur.MUST);
}

代码示例来源:origin: apache/incubator-atlas

public BooleanQueryExpression(BooleanQuery query, ResourceDefinition resourceDefinition, QueryFactory queryFactory) {
  super(null, null, resourceDefinition);
  clauses = query.getClauses();
  this.queryFactory = queryFactory;
}

代码示例来源:origin: com.atlassian.jira/jira-core

public QueryBucket(BooleanQuery booleanQuery)
{
  this.booleanQuery = booleanQuery;
  this.notQueries = new ArrayList<Query>();
  this.mustQueries = new ArrayList<Query>();
  this.shouldQueries = new ArrayList<Query>();
  init(booleanQuery.getClauses());
}

代码示例来源:origin: ajermakovics/eclipse-instasearch

@Override
public BooleanQuery visit(BooleanQuery boolQuery) {
  clauseCount += boolQuery.getClauses().length;
  return super.visit(boolQuery);
}

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

BooleanQuery bq = new BooleanQuery();
bq.add(new TermQuery(new Term("field1","a")), BooleanClause.Occur.SHOULD)
bq.add(new TermQuery(new Term("field1","b")), BooleanClause.Occur.SHOULD)

BooleanClause[] clauses = bq.getClauses();

代码示例来源:origin: msokolov/lux

private boolean needsPositions(Query query) {
  if ((query instanceof PhraseQuery)) {
    return true;
  }
  if (query instanceof BooleanQuery) {
    for (BooleanClause clause : ((BooleanQuery)query).getClauses()) {
      if (needsPositions (clause.getQuery())) {
        return true;
      }
    }
  }
  return false;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-maven-indexer

private static Query setBooleanRewrite (final Query q) {
  if (q instanceof MultiTermQuery) {
    ((MultiTermQuery)q).setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE);
  } else if (q instanceof BooleanQuery) {
    for (BooleanClause c : ((BooleanQuery)q).getClauses()) {
      setBooleanRewrite(c.getQuery());
    }
  }
  return q;
}

代码示例来源:origin: msokolov/lux

private Query maybeConvert (Query q) {
  if (! (q instanceof BooleanQuery)) {
    return q;
  }
  BooleanQuery bq = (BooleanQuery) q;
  if (bq.getClauses().length == 0) {
    return bq;
  }
  Query q1 = bq.getClauses()[0].getQuery();
  if (q1 instanceof TermQuery) {
    Term term = ((TermQuery) q1).getTerm();
    if (term.field().equals("lux_within") || term.field().equals("lux_near")) {
      return toSpanQuery (bq);
    }
  }
  // else (we didn't convert this query, but maybe some nested queries is marked as a span) :)
  convertNestedSpans (bq);
  return bq;
}

代码示例来源:origin: com.mysema.querydsl/querydsl-lucene

/**
 * If the query is a BooleanQuery and it contains a single Occur.MUST_NOT
 * clause it will be returned as is. Otherwise it will be wrapped in a
 * BooleanClause with the given Occur.
 */
private BooleanClause createBooleanClause(Query query, Occur occur) {
  if (query instanceof BooleanQuery) {
    BooleanClause[] clauses = ((BooleanQuery) query).getClauses();
    if (clauses.length == 1 && clauses[0].getOccur().equals(Occur.MUST_NOT)) {
      return clauses[0];
    }
  }
  return new BooleanClause(query, occur);
}

代码示例来源:origin: com.querydsl/querydsl-lucene3

/**
 * If the query is a BooleanQuery and it contains a single Occur.MUST_NOT
 * clause it will be returned as is. Otherwise it will be wrapped in a
 * BooleanClause with the given Occur.
 */
private BooleanClause createBooleanClause(Query query, Occur occur) {
  if (query instanceof BooleanQuery) {
    BooleanClause[] clauses = ((BooleanQuery) query).getClauses();
    if (clauses.length == 1 && clauses[0].getOccur().equals(Occur.MUST_NOT)) {
      return clauses[0];
    }
  }
  return new BooleanClause(query, occur);
}

代码示例来源:origin: net.di2e.ecdr.libs/cdr-libs-result-relevance-normalizer

protected org.apache.lucene.search.Query getQuery( QueryParser parser, Map<String, String> filterParameters ) throws ParseException {
  String searchPhrase = getSearchPhrase( filterParameters );
  org.apache.lucene.search.Query query = parser.parse( searchPhrase );
  if ( filterParameters.containsKey( SearchConstants.FUZZY_PARAMETER ) && StringUtils.equals( filterParameters.get( SearchConstants.FUZZY_PARAMETER ), "1" ) ) {
    // should get a boolean query for keyword-based searches
    if ( query instanceof BooleanQuery ) {
      BooleanQuery booleanQuery = (BooleanQuery) query;
      for ( BooleanClause clause : booleanQuery.getClauses() ) {
        if ( clause.getQuery() instanceof TermQuery ) {
          TermQuery oldQuery = (TermQuery) clause.getQuery();
          FuzzyQuery newQuery = new FuzzyQuery( oldQuery.getTerm() );
          clause.setQuery( newQuery );
        }
      }
    } else {
      LOGGER.debug( "Query was too complex for adding fuzzy. Expected BooleanQuery but ended up being of type {}", query.getClass().getName() );
    }
  }
  return query;
}

代码示例来源:origin: jdmp/java-data-mining-package

public Set<String> extractTerms(Query query) {
  Set<String> terms = new HashSet<String>();
  if (query instanceof BooleanQuery) {
    BooleanQuery b = (BooleanQuery) query;
    for (BooleanClause bc : b.getClauses()) {
      Query q = bc.getQuery();
      terms.addAll(extractTerms(q));
    }
  } else if (query instanceof TermQuery) {
    TermQuery tq = (TermQuery) query;
    terms.add(tq.getTerm().text());
  } else if (query instanceof WildcardQuery) {
    WildcardQuery wq = (WildcardQuery) query;
    terms.add(wq.getTerm().text());
  }
  return terms;
}

代码示例来源:origin: com.atlassian.jira/jira-core

private Collection<Clause> transformMultiClauseExecutingWorklogConditions(MultiClause multiClause, BooleanClause.Occur operator)
{
  ImmutableList.Builder<Clause> newSubClauses = ImmutableList.builder();
  BooleanQuery luceneWorklogsQuery = new BooleanQuery();
  for (Clause clause : multiClause.getClauses())
  {
    Option<Query> maybeWorklogQuery = convertClauseToWorklogQuery(clause);
    if (maybeWorklogQuery.isDefined())
    {
      luceneWorklogsQuery.add(maybeWorklogQuery.get(), operator);
    }
    else
    {
      newSubClauses.add(clause.accept(this));
    }
  }
  if (luceneWorklogsQuery.getClauses().length > 0)
  {
    newSubClauses.add(toIssueSet(luceneWorklogsQuery));
  }
  return newSubClauses.build();
}

代码示例来源:origin: sirensolutions/siren

@Test
public void testTopLevelBooleanWithMissingOccurInClause() throws QueryNodeException {
 final ExtendedTreeQueryParser parser = new ExtendedTreeQueryParser();
 final String query = "{ \"boolean\" : { \"clause\" : [ " +
   "{ \"node\" : { \"query\" : \"aaa\" } } " +
   "] } }";
 Query q = parser.parse(query, ""); // should not throw exception
 assertTrue(q instanceof org.apache.lucene.search.BooleanQuery);
 BooleanClause.Occur occur = ((org.apache.lucene.search.BooleanQuery) q).getClauses()[0].getOccur();
 assertEquals(parser.getDefaultOperator() == StandardQueryConfigHandler.Operator.AND ?
  BooleanClause.Occur.MUST : BooleanClause.Occur.SHOULD, occur);
}

相关文章