Java 类org.apache.lucene.search.BooleanQuery.BooleanWeight 实例源码

项目:search    文件:TestMinShouldMatch2.java   
SlowMinShouldMatchScorer(BooleanWeight weight, AtomicReader reader, IndexSearcher searcher) throws IOException {
  super(weight);
  this.dv = reader.getSortedSetDocValues("dv");
  this.maxDoc = reader.maxDoc();
  BooleanQuery bq = (BooleanQuery) weight.getQuery();
  this.minNrShouldMatch = bq.getMinimumNumberShouldMatch();
  this.sims = new SimScorer[(int)dv.getValueCount()];
  for (BooleanClause clause : bq.getClauses()) {
    assert !clause.isProhibited();
    assert !clause.isRequired();
    Term term = ((TermQuery)clause.getQuery()).getTerm();
    long ord = dv.lookupTerm(term.bytes());
    if (ord >= 0) {
      boolean success = ords.add(ord);
      assert success; // no dups
      TermContext context = TermContext.build(reader.getContext(), term);
      SimWeight w = weight.similarity.computeWeight(1f, 
                    searcher.collectionStatistics("field"),
                    searcher.termStatistics(term, context));
      w.getValueForNormalization(); // ignored
      w.normalize(1F, 1F);
      sims[(int)ord] = weight.similarity.simScorer(w, reader.getContext());
    }
  }
}
项目:Maskana-Gestor-de-Conocimiento    文件:TestMinShouldMatch2.java   
SlowMinShouldMatchScorer(BooleanWeight weight, AtomicReader reader, IndexSearcher searcher) throws IOException {
  super(weight);
  this.dv = reader.getSortedSetDocValues("dv");
  this.maxDoc = reader.maxDoc();
  BooleanQuery bq = (BooleanQuery) weight.getQuery();
  this.minNrShouldMatch = bq.getMinimumNumberShouldMatch();
  this.sims = new SimScorer[(int)dv.getValueCount()];
  for (BooleanClause clause : bq.getClauses()) {
    assert !clause.isProhibited();
    assert !clause.isRequired();
    Term term = ((TermQuery)clause.getQuery()).getTerm();
    long ord = dv.lookupTerm(term.bytes());
    if (ord >= 0) {
      boolean success = ords.add(ord);
      assert success; // no dups
      TermContext context = TermContext.build(reader.getContext(), term);
      SimWeight w = weight.similarity.computeWeight(1f, 
                    searcher.collectionStatistics("field"),
                    searcher.termStatistics(term, context));
      w.getValueForNormalization(); // ignored
      w.normalize(1F, 1F);
      sims[(int)ord] = weight.similarity.simScorer(w, reader.getContext());
    }
  }
}
项目:search    文件:TestMinShouldMatch2.java   
private Scorer scorer(String values[], int minShouldMatch, boolean slow) throws Exception {
  BooleanQuery bq = new BooleanQuery();
  for (String value : values) {
    bq.add(new TermQuery(new Term("field", value)), BooleanClause.Occur.SHOULD);
  }
  bq.setMinimumNumberShouldMatch(minShouldMatch);

  BooleanWeight weight = (BooleanWeight) searcher.createNormalizedWeight(bq);

  if (slow) {
    return new SlowMinShouldMatchScorer(weight, reader, searcher);
  } else {
    return weight.scorer(reader.getContext(), null);
  }
}
项目:Maskana-Gestor-de-Conocimiento    文件:TestMinShouldMatch2.java   
private Scorer scorer(String values[], int minShouldMatch, boolean slow) throws Exception {
  BooleanQuery bq = new BooleanQuery();
  for (String value : values) {
    bq.add(new TermQuery(new Term("field", value)), BooleanClause.Occur.SHOULD);
  }
  bq.setMinimumNumberShouldMatch(minShouldMatch);

  BooleanWeight weight = (BooleanWeight) searcher.createNormalizedWeight(bq);

  if (slow) {
    return new SlowMinShouldMatchScorer(weight, reader, searcher);
  } else {
    return weight.scorer(reader.getContext(), true, false, null);
  }
}
项目:NYBC    文件:BooleanScorer2.java   
Coordinator(int maxCoord, boolean disableCoord) {
  coordFactors = new float[optionalScorers.size() + requiredScorers.size() + 1];
  for (int i = 0; i < coordFactors.length; i++) {
    coordFactors[i] = disableCoord ? 1.0f : ((BooleanWeight)weight).coord(i, maxCoord);
  }
}
项目:NYBC    文件:BooleanScorer2.java   
/**
 * Creates a {@link Scorer} with the given similarity and lists of required,
 * prohibited and optional scorers. In no required scorers are added, at least
 * one of the optional scorers will have to match during the search.
 * 
 * @param weight
 *          The BooleanWeight to be used.
 * @param disableCoord
 *          If this parameter is true, coordination level matching 
 *          ({@link Similarity#coord(int, int)}) is not used.
 * @param minNrShouldMatch
 *          The minimum number of optional added scorers that should match
 *          during the search. In case no required scorers are added, at least
 *          one of the optional scorers will have to match during the search.
 * @param required
 *          the list of required scorers.
 * @param prohibited
 *          the list of prohibited scorers.
 * @param optional
 *          the list of optional scorers.
 */
public BooleanScorer2(BooleanWeight weight, boolean disableCoord, int minNrShouldMatch,
    List<Scorer> required, List<Scorer> prohibited, List<Scorer> optional, int maxCoord) throws IOException {
  super(weight);
  if (minNrShouldMatch < 0) {
    throw new IllegalArgumentException("Minimum number of optional scorers should not be negative");
  }
  this.minNrShouldMatch = minNrShouldMatch;

  optionalScorers = optional;
  requiredScorers = required;    
  prohibitedScorers = prohibited;
  coordinator = new Coordinator(maxCoord, disableCoord);

  countingSumScorer = makeCountingSumScorer(disableCoord);
}
项目:read-open-source-code    文件:BooleanScorer2.java   
Coordinator(int maxCoord, boolean disableCoord) {
  coordFactors = new float[optionalScorers.size() + requiredScorers.size() + 1];
  for (int i = 0; i < coordFactors.length; i++) {
    coordFactors[i] = disableCoord ? 1.0f : ((BooleanWeight)weight).coord(i, maxCoord);
  }
}
项目:read-open-source-code    文件:BooleanScorer2.java   
/**
 * Creates a {@link Scorer} with the given similarity and lists of required,
 * prohibited and optional scorers. In no required scorers are added, at least
 * one of the optional scorers will have to match during the search.
 * 
 * @param weight
 *          The BooleanWeight to be used.
 * @param disableCoord
 *          If this parameter is true, coordination level matching 
 *          ({@link Similarity#coord(int, int)}) is not used.
 * @param minNrShouldMatch
 *          The minimum number of optional added scorers that should match
 *          during the search. In case no required scorers are added, at least
 *          one of the optional scorers will have to match during the search.
 * @param required
 *          the list of required scorers.
 * @param prohibited
 *          the list of prohibited scorers.
 * @param optional
 *          the list of optional scorers.
 */
public BooleanScorer2(BooleanWeight weight, boolean disableCoord, int minNrShouldMatch,
    List<Scorer> required, List<Scorer> prohibited, List<Scorer> optional, int maxCoord) throws IOException {
  super(weight);
  if (minNrShouldMatch < 0) {
    throw new IllegalArgumentException("Minimum number of optional scorers should not be negative");
  }
  this.minNrShouldMatch = minNrShouldMatch;

  optionalScorers = optional;
  requiredScorers = required;    
  prohibitedScorers = prohibited;
  coordinator = new Coordinator(maxCoord, disableCoord);

  countingSumScorer = makeCountingSumScorer(disableCoord);
}
项目:read-open-source-code    文件:BooleanScorer2.java   
Coordinator(int maxCoord, boolean disableCoord) {
  coordFactors = new float[optionalScorers.size() + requiredScorers.size() + 1];
  for (int i = 0; i < coordFactors.length; i++) {
    coordFactors[i] = disableCoord ? 1.0f : ((BooleanWeight)weight).coord(i, maxCoord);
  }
}
项目:read-open-source-code    文件:BooleanScorer2.java   
/**
 * Creates a {@link Scorer} with the given similarity and lists of required,
 * prohibited and optional scorers. In no required scorers are added, at least
 * one of the optional scorers will have to match during the search.
 * 
 * @param weight
 *          The BooleanWeight to be used.
 * @param disableCoord
 *          If this parameter is true, coordination level matching 
 *          ({@link Similarity#coord(int, int)}) is not used.
 * @param minNrShouldMatch
 *          The minimum number of optional added scorers that should match
 *          during the search. In case no required scorers are added, at least
 *          one of the optional scorers will have to match during the search.
 * @param required
 *          the list of required scorers.
 * @param prohibited
 *          the list of prohibited scorers.
 * @param optional
 *          the list of optional scorers.
 */
public BooleanScorer2(BooleanWeight weight, boolean disableCoord, int minNrShouldMatch,
    List<Scorer> required, List<Scorer> prohibited, List<Scorer> optional, int maxCoord) throws IOException {
  super(weight);
  if (minNrShouldMatch < 0) {
    throw new IllegalArgumentException("Minimum number of optional scorers should not be negative");
  }
  this.minNrShouldMatch = minNrShouldMatch;

  optionalScorers = optional;
  requiredScorers = required;    
  prohibitedScorers = prohibited;
  coordinator = new Coordinator(maxCoord, disableCoord);

  countingSumScorer = makeCountingSumScorer(disableCoord);
}
项目:Maskana-Gestor-de-Conocimiento    文件:BooleanScorer2.java   
Coordinator(int maxCoord, boolean disableCoord) {
  coordFactors = new float[optionalScorers.size() + requiredScorers.size() + 1];
  for (int i = 0; i < coordFactors.length; i++) {
    coordFactors[i] = disableCoord ? 1.0f : ((BooleanWeight)weight).coord(i, maxCoord);
  }
}
项目:Maskana-Gestor-de-Conocimiento    文件:BooleanScorer2.java   
/**
 * Creates a {@link Scorer} with the given similarity and lists of required,
 * prohibited and optional scorers. In no required scorers are added, at least
 * one of the optional scorers will have to match during the search.
 * 
 * @param weight
 *          The BooleanWeight to be used.
 * @param disableCoord
 *          If this parameter is true, coordination level matching 
 *          ({@link Similarity#coord(int, int)}) is not used.
 * @param minNrShouldMatch
 *          The minimum number of optional added scorers that should match
 *          during the search. In case no required scorers are added, at least
 *          one of the optional scorers will have to match during the search.
 * @param required
 *          the list of required scorers.
 * @param prohibited
 *          the list of prohibited scorers.
 * @param optional
 *          the list of optional scorers.
 */
public BooleanScorer2(BooleanWeight weight, boolean disableCoord, int minNrShouldMatch,
    List<Scorer> required, List<Scorer> prohibited, List<Scorer> optional, int maxCoord) throws IOException {
  super(weight);
  if (minNrShouldMatch < 0) {
    throw new IllegalArgumentException("Minimum number of optional scorers should not be negative");
  }
  this.minNrShouldMatch = minNrShouldMatch;

  optionalScorers = optional;
  requiredScorers = required;    
  prohibitedScorers = prohibited;
  coordinator = new Coordinator(maxCoord, disableCoord);

  countingSumScorer = makeCountingSumScorer(disableCoord);
}