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

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

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

BooleanQuery.isCoordDisabled介绍

[英]Return whether the coord factor is disabled.
[中]返回是否禁用协调因子。

代码示例

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

/** Expert: merges the clauses of a set of BooleanQuery's into a single
 * BooleanQuery.
 *
 *<p>A utility for use by {@link #combine(Query[])} implementations.
 */
public static Query mergeBooleanQueries(Query[] queries) {
 HashSet allClauses = new HashSet();
 for (int i = 0; i < queries.length; i++) {
  BooleanClause[] clauses = ((BooleanQuery)queries[i]).getClauses();
  for (int j = 0; j < clauses.length; j++) {
   allClauses.add(clauses[j]);
  }
 }
 boolean coordDisabled =
  queries.length==0? false : ((BooleanQuery)queries[0]).isCoordDisabled();
 BooleanQuery result = new BooleanQuery(coordDisabled);
 Iterator i = allClauses.iterator();
 while (i.hasNext()) {
  result.add((BooleanClause)i.next());
 }
 return result;
}

代码示例来源:origin: org.apache.lucene/com.springsource.org.apache.lucene

/** Expert: merges the clauses of a set of BooleanQuery's into a single
 * BooleanQuery.
 *
 *<p>A utility for use by {@link #combine(Query[])} implementations.
 */
public static Query mergeBooleanQueries(Query[] queries) {
 HashSet allClauses = new HashSet();
 for (int i = 0; i < queries.length; i++) {
  BooleanClause[] clauses = ((BooleanQuery)queries[i]).getClauses();
  for (int j = 0; j < clauses.length; j++) {
   allClauses.add(clauses[j]);
  }
 }
 boolean coordDisabled =
  queries.length==0? false : ((BooleanQuery)queries[0]).isCoordDisabled();
 BooleanQuery result = new BooleanQuery(coordDisabled);
 Iterator i = allClauses.iterator();
 while (i.hasNext()) {
  result.add((BooleanClause)i.next());
 }
 return result;
}

代码示例来源:origin: org.codelibs/elasticsearch-querybuilders

private Query parseAndApply(Type type, String fieldName, Object value, String minimumShouldMatch, Float boostValue) throws IOException {
  Query query = parse(type, fieldName, value);
  // If the coordination factor is disabled on a boolean query we don't apply the minimum should match.
  // This is done to make sure that the minimum_should_match doesn't get applied when there is only one word
  // and multiple variations of the same word in the query (synonyms for instance).
  if (query instanceof BooleanQuery && !((BooleanQuery) query).isCoordDisabled()) {
    query = Queries.applyMinimumShouldMatch((BooleanQuery) query, minimumShouldMatch);
  }
  if (query != null && boostValue != null && boostValue != AbstractQueryBuilder.DEFAULT_BOOST) {
    query = new BoostQuery(query, boostValue);
  }
  return query;
}

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

/**
 * Potentially apply minimum should match value if we have a query that it can be applied to,
 * otherwise return the original query.
 */
public static Query maybeApplyMinimumShouldMatch(Query query, @Nullable String minimumShouldMatch) {
  // If the coordination factor is disabled on a boolean query we don't apply the minimum should match.
  // This is done to make sure that the minimum_should_match doesn't get applied when there is only one word
  // and multiple variations of the same word in the query (synonyms for instance).
  if (query instanceof BooleanQuery && !((BooleanQuery) query).isCoordDisabled()) {
    return applyMinimumShouldMatch((BooleanQuery) query, minimumShouldMatch);
  } else if (query instanceof ExtendedCommonTermsQuery) {
    ((ExtendedCommonTermsQuery)query).setLowFreqMinimumNumberShouldMatch(minimumShouldMatch);
  }
  return query;
}

代码示例来源:origin: harbby/presto-connectors

private Query parseAndApply(Type type, String fieldName, Object value, String minimumShouldMatch, Float boostValue) throws IOException {
  Query query = parse(type, fieldName, value);
  // If the coordination factor is disabled on a boolean query we don't apply the minimum should match.
  // This is done to make sure that the minimum_should_match doesn't get applied when there is only one word
  // and multiple variations of the same word in the query (synonyms for instance).
  if (query instanceof BooleanQuery && !((BooleanQuery) query).isCoordDisabled()) {
    query = Queries.applyMinimumShouldMatch((BooleanQuery) query, minimumShouldMatch);
  }
  if (boostValue != null && query != null) {
    query.setBoost(boostValue);
  }
  return query;
}

代码示例来源:origin: org.infinispan/infinispan-query

@Override
public void writeObject(final ObjectOutput output, final BooleanQuery query) throws IOException {
 output.writeBoolean(query.isCoordDisabled());
 output.writeFloat(query.getBoost());
 UnsignedNumeric.writeUnsignedInt(output, query.getMinimumNumberShouldMatch());
 final List<BooleanClause> booleanClauses = query.clauses();
 final int numberOfClauses = booleanClauses.size();
 UnsignedNumeric.writeUnsignedInt(output, numberOfClauses);
 for (BooleanClause booleanClause : booleanClauses) {
   writeClause(output, booleanClause);
 }
}

代码示例来源:origin: org.infinispan/infinispan-embedded-query

@Override
public void writeObject(final ObjectOutput output, final BooleanQuery query) throws IOException {
 output.writeBoolean(query.isCoordDisabled());
 output.writeFloat(query.getBoost());
 UnsignedNumeric.writeUnsignedInt(output, query.getMinimumNumberShouldMatch());
 final List<BooleanClause> booleanClauses = query.clauses();
 final int numberOfClauses = booleanClauses.size();
 UnsignedNumeric.writeUnsignedInt(output, numberOfClauses);
 for (BooleanClause booleanClause : booleanClauses) {
   writeClause(output, booleanClause);
 }
}

代码示例来源:origin: org.infinispan/infinispan-embedded-query

BooleanQuery bq = (BooleanQuery) query;
BooleanQuery.Builder builder = new BooleanQuery.Builder();
builder.setDisableCoord(bq.isCoordDisabled());
builder.setMinimumNumberShouldMatch((int) (fraction * bq.clauses().size()));
for (BooleanClause clause : bq) {

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

private Query boolToExtendedCommonTermsQuery(BooleanQuery bq, Occur highFreqOccur, Occur lowFreqOccur, float
    maxTermFrequency, MappedFieldType fieldType) {
    ExtendedCommonTermsQuery query = new ExtendedCommonTermsQuery(highFreqOccur, lowFreqOccur, maxTermFrequency,
      bq.isCoordDisabled(), fieldType);
    for (BooleanClause clause : bq.clauses()) {
      if (!(clause.getQuery() instanceof TermQuery)) {
        return bq;
      }
      query.add(((TermQuery) clause.getQuery()).getTerm());
    }
    return query;
  }
}

代码示例来源:origin: harbby/presto-connectors

private static BooleanQuery addClause(BooleanQuery bq, Query query, BooleanClause.Occur occur) {
 BooleanQuery.Builder newBq = new BooleanQuery.Builder();
 newBq.setDisableCoord(bq.isCoordDisabled());
 newBq.setMinimumNumberShouldMatch(bq.getMinimumNumberShouldMatch());
 for (BooleanClause clause : bq) {
  newBq.add(clause);
 }
 newBq.add(query, occur);
 return newBq.build();
}

代码示例来源:origin: org.infinispan/infinispan-embedded-query

private static BooleanQuery addClause(BooleanQuery bq, Query query, BooleanClause.Occur occur) {
 BooleanQuery.Builder newBq = new BooleanQuery.Builder();
 newBq.setDisableCoord(bq.isCoordDisabled());
 newBq.setMinimumNumberShouldMatch(bq.getMinimumNumberShouldMatch());
 for (BooleanClause clause : bq) {
  newBq.add(clause);
 }
 newBq.add(query, occur);
 return newBq.build();
}

代码示例来源:origin: harbby/presto-connectors

public static Query fixNegativeQueryIfNeeded(Query q) {
  if (isNegativeQuery(q)) {
    BooleanQuery bq = (BooleanQuery) q;
    BooleanQuery.Builder builder = new BooleanQuery.Builder();
    builder.setDisableCoord(bq.isCoordDisabled());
    for (BooleanClause clause : bq) {
      builder.add(clause);
    }
    builder.add(newMatchAllQuery(), BooleanClause.Occur.MUST);
    return builder.build();
  }
  return q;
}

代码示例来源:origin: org.codelibs/elasticsearch-querybuilders

public static Query fixNegativeQueryIfNeeded(Query q) {
  if (isNegativeQuery(q)) {
    BooleanQuery bq = (BooleanQuery) q;
    BooleanQuery.Builder builder = new BooleanQuery.Builder();
    builder.setDisableCoord(bq.isCoordDisabled());
    for (BooleanClause clause : bq) {
      builder.add(clause);
    }
    builder.add(newMatchAllQuery(), BooleanClause.Occur.MUST);
    return builder.build();
  }
  return q;
}

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

public static Query fixNegativeQueryIfNeeded(Query q) {
  if (isNegativeQuery(q)) {
    BooleanQuery bq = (BooleanQuery) q;
    BooleanQuery.Builder builder = new BooleanQuery.Builder();
    builder.setDisableCoord(bq.isCoordDisabled());
    for (BooleanClause clause : bq) {
      builder.add(clause);
    }
    builder.add(newMatchAllQuery(), BooleanClause.Occur.MUST);
    return builder.build();
  }
  return q;
}

代码示例来源:origin: harbby/presto-connectors

public Query createCommonTermsQuery(String field, String queryText, Occur highFreqOccur, Occur lowFreqOccur, float maxTermFrequency, MappedFieldType fieldType) {
    Query booleanQuery = createBooleanQuery(field, queryText, lowFreqOccur);
    if (booleanQuery != null && booleanQuery instanceof BooleanQuery) {
      BooleanQuery bq = (BooleanQuery) booleanQuery;
      ExtendedCommonTermsQuery query = new ExtendedCommonTermsQuery(highFreqOccur, lowFreqOccur, maxTermFrequency, ((BooleanQuery)booleanQuery).isCoordDisabled(), fieldType);
      for (BooleanClause clause : bq.clauses()) {
        if (!(clause.getQuery() instanceof TermQuery)) {
          return booleanQuery;
        }
        query.add(((TermQuery) clause.getQuery()).getTerm());
      }
      return query;
    }
    return booleanQuery;
  }
}

代码示例来源:origin: harbby/presto-connectors

@Override
public Query rewrite(IndexReader reader) throws IOException {
 if (getBoost() != 1f) {
  return super.rewrite(reader);
 }
 MoreLikeThis mlt = new MoreLikeThis(reader);
 mlt.setFieldNames(moreLikeFields);
 mlt.setAnalyzer(analyzer);
 mlt.setMinTermFreq(minTermFrequency);
 if (minDocFreq >= 0) {
  mlt.setMinDocFreq(minDocFreq);
 }
 mlt.setMaxQueryTerms(maxQueryTerms);
 mlt.setStopWords(stopWords);
 BooleanQuery bq = (BooleanQuery) mlt.like(fieldName, new StringReader(likeText));
 BooleanQuery.Builder newBq = new BooleanQuery.Builder();
 newBq.setDisableCoord(bq.isCoordDisabled());
 for (BooleanClause clause : bq) {
  newBq.add(clause);
 }
 //make at least half the terms match
 newBq.setMinimumNumberShouldMatch((int) (bq.clauses().size() * percentTermsToMatch));
 return newBq.build();
}

代码示例来源:origin: org.infinispan/infinispan-embedded-query

@Override
public Query rewrite(IndexReader reader) throws IOException {
 if (getBoost() != 1f) {
  return super.rewrite(reader);
 }
 MoreLikeThis mlt = new MoreLikeThis(reader);
 mlt.setFieldNames(moreLikeFields);
 mlt.setAnalyzer(analyzer);
 mlt.setMinTermFreq(minTermFrequency);
 if (minDocFreq >= 0) {
  mlt.setMinDocFreq(minDocFreq);
 }
 mlt.setMaxQueryTerms(maxQueryTerms);
 mlt.setStopWords(stopWords);
 BooleanQuery bq = (BooleanQuery) mlt.like(fieldName, new StringReader(likeText));
 BooleanQuery.Builder newBq = new BooleanQuery.Builder();
 newBq.setDisableCoord(bq.isCoordDisabled());
 for (BooleanClause clause : bq) {
  newBq.add(clause);
 }
 //make at least half the terms match
 newBq.setMinimumNumberShouldMatch((int) (bq.clauses().size() * percentTermsToMatch));
 return newBq.build();
}

代码示例来源:origin: org.codelibs/elasticsearch-querybuilders

public static Query applyMinimumShouldMatch(BooleanQuery query, @Nullable String minimumShouldMatch) {
  if (minimumShouldMatch == null) {
    return query;
  }
  int optionalClauses = 0;
  for (BooleanClause c : query.clauses()) {
    if (c.getOccur() == BooleanClause.Occur.SHOULD) {
      optionalClauses++;
    }
  }
  int msm = calculateMinShouldMatch(optionalClauses, minimumShouldMatch);
  if (0 < msm) {
    BooleanQuery.Builder builder = new BooleanQuery.Builder();
    builder.setDisableCoord(query.isCoordDisabled());
    for (BooleanClause clause : query) {
      builder.add(clause);
    }
    builder.setMinimumNumberShouldMatch(msm);
    return builder.build();
  } else {
    return query;
  }
}

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

public static Query applyMinimumShouldMatch(BooleanQuery query, @Nullable String minimumShouldMatch) {
  if (minimumShouldMatch == null) {
    return query;
  }
  int optionalClauses = 0;
  for (BooleanClause c : query.clauses()) {
    if (c.getOccur() == BooleanClause.Occur.SHOULD) {
      optionalClauses++;
    }
  }
  int msm = calculateMinShouldMatch(optionalClauses, minimumShouldMatch);
  if (0 < msm) {
    BooleanQuery.Builder builder = new BooleanQuery.Builder();
    builder.setDisableCoord(query.isCoordDisabled());
    for (BooleanClause clause : query) {
      builder.add(clause);
    }
    builder.setMinimumNumberShouldMatch(msm);
    return builder.build();
  } else {
    return query;
  }
}

代码示例来源:origin: harbby/presto-connectors

public static BooleanQuery applyMinimumShouldMatch(BooleanQuery query, @Nullable String minimumShouldMatch) {
  if (minimumShouldMatch == null) {
    return query;
  }
  int optionalClauses = 0;
  for (BooleanClause c : query.clauses()) {
    if (c.getOccur() == BooleanClause.Occur.SHOULD) {
      optionalClauses++;
    }
  }
  int msm = calculateMinShouldMatch(optionalClauses, minimumShouldMatch);
  if (0 < msm) {
    BooleanQuery.Builder builder = new BooleanQuery.Builder();
    builder.setDisableCoord(query.isCoordDisabled());
    for (BooleanClause clause : query) {
      builder.add(clause);
    }
    builder.setMinimumNumberShouldMatch(msm);
    BooleanQuery bq = builder.build();
    bq.setBoost(query.getBoost());
    query = bq;
  }
  return query;
}

相关文章