Package org.apache.lucene.search

Examples of org.apache.lucene.search.Weight


   * not a direct test of NearSpans, but a demonstration of how/when
   * this causes problems
   */
  public void testSpanNearScorerSkipTo1() throws Exception {
    SpanNearQuery q = makeQuery();
    Weight w = searcher.createNormalizedWeight(q);
    IndexReaderContext topReaderContext = searcher.getTopReaderContext();
    AtomicReaderContext leave = topReaderContext.leaves().get(0);
    Scorer s = w.scorer(leave, true, false, leave.reader().getLiveDocs());
    assertEquals(1, s.advance(1));
  }
View Full Code Here


   * @throws IOException in case a search exception occurs
   */
  private void updateTopDocs(int n) throws IOException {
    int totalMaxDocs = searcher.getSearcher().maxDoc();
    final int maxDocs = Math.min( n, totalMaxDocs );
    final Weight weight = preparedQuery.weight( searcher.getSearcher() );

    final TopDocsCollector<?> topDocCollector;
    final TotalHitCountCollector hitCountCollector;
    Collector collector = null;
    if ( maxDocs != 0 ) {
View Full Code Here

   * @throws IOException in case a search exception occurs
   */
  private void updateTopDocs(int n) throws IOException {
    int totalMaxDocs = searcher.getSearcher().maxDoc();
    final int maxDocs = Math.min( n, totalMaxDocs );
    final Weight weight = preparedQuery.weight( searcher.getSearcher() );

    final TopDocsCollector<?> topDocCollector;
    final TotalHitCountCollector hitCountCollector;
    Collector collector = null;
    if ( maxDocs != 0 ) {
View Full Code Here

   * @throws IOException in case a search exception occurs
   */
  private void updateTopDocs(int n) throws IOException {
    int totalMaxDocs = searcher.getSearcher().maxDoc();
    final int maxDocs = Math.min( n, totalMaxDocs );
    final Weight weight = preparedQuery.weight( searcher.getSearcher() );

    final TopDocsCollector<?> topDocCollector;
    final TotalHitCountCollector hitCountCollector;
    Collector collector = null;
    if ( maxDocs != 0 ) {
View Full Code Here

   * @throws IOException in case a search exception occurs
   */
  private void updateTopDocs(int n) throws IOException {
    int totalMaxDocs = searcher.getSearcher().maxDoc();
    final int maxDocs = Math.min( n, totalMaxDocs );
    final Weight weight = preparedQuery.weight( searcher.getSearcher() );

    TopDocsCollector<?> topDocCollector = createTopDocCollector( maxDocs, weight );
    Collector collector = decorateWithTimeOutCollector( topDocCollector );

    boolean timeoutNow = isImmediateTimeout();
View Full Code Here

    }
  }
 
  @Override
  public Weight createWeight(IndexSearcher searcher) throws IOException {
    final Weight baseWeight = baseQuery.createWeight(searcher);
    final Object[] drillDowns = new Object[drillDownQueries.length];
    for(int dim=0;dim<drillDownQueries.length;dim++) {
      Query query = drillDownQueries[dim];
      Filter filter = DrillDownQuery.getFilter(query);
      if (filter != null) {
        drillDowns[dim] = filter;
      } else {
        // TODO: would be nice if we could say "we will do no
        // scoring" here....
        drillDowns[dim] = searcher.rewrite(query).createWeight(searcher);
      }
    }

    return new Weight() {
      @Override
      public Explanation explain(AtomicReaderContext context, int doc) throws IOException {
        return baseWeight.explain(context, doc);
      }

      @Override
      public Query getQuery() {
        return baseQuery;
      }

      @Override
      public float getValueForNormalization() throws IOException {
        return baseWeight.getValueForNormalization();
      }

      @Override
      public void normalize(float norm, float topLevelBoost) {
        baseWeight.normalize(norm, topLevelBoost);
      }

      @Override
      public boolean scoresDocsOutOfOrder() {
        // TODO: would be nice if AssertingIndexSearcher
        // confirmed this for us
        return false;
      }

      @Override
      public Scorer scorer(AtomicReaderContext context, boolean scoreDocsInOrder,
                           boolean topScorer, Bits acceptDocs) throws IOException {

        // TODO: it could be better if we take acceptDocs
        // into account instead of baseScorer?
        Scorer baseScorer = baseWeight.scorer(context, scoreDocsInOrder, false, acceptDocs);

        DrillSidewaysScorer.DocsAndCost[] dims = new DrillSidewaysScorer.DocsAndCost[drillDowns.length];
        int nullCount = 0;
        for(int dim=0;dim<dims.length;dim++) {
          dims[dim] = new DrillSidewaysScorer.DocsAndCost();
View Full Code Here

    // Delete by query
    IndexSearcher searcher = new IndexSearcher(reader);
    for (Entry<Query, Integer> entry : deletesFlushed.queries.entrySet()) {
      Query query = entry.getKey();
      int limit = entry.getValue().intValue();
      Weight weight = query.weight(searcher);
      Scorer scorer = weight.scorer(reader, true, false);
      if (scorer != null) {
        while(true)  {
          int doc = scorer.nextDoc();
          if (((long) docIDStart) + doc >= limit)
            break;
View Full Code Here

  public Query clone() {
    return new SuperQuery((Query) _query.clone(), scoreType, primeDocTerm, _rewritten);
  }

  public Weight createWeight(IndexSearcher searcher) throws IOException {
    Weight weight = _query.createWeight(searcher);
    return new SuperWeight(weight, _query.toString(), this, scoreType, primeDocTerm);
  }
View Full Code Here

    return new FacetQuery(_query.rewrite(reader), _facets, _executor, true);
  }

  @Override
  public Weight createWeight(IndexSearcher searcher) throws IOException {
    Weight weight = _query.createWeight(searcher);
    return new FacetWeight(weight, getWeights(searcher), _executor);
  }
View Full Code Here

  protected final void search(final Query query, final DocumentFrequencyWritable freqs, final String[] shards,
          final HitsMapWritable result, final int max, Sort sort, long timeout) throws IOException {
    timeout = getCollectorTiemout(timeout);
    final Query rewrittenQuery = rewrite(query, shards);
    final int numDocs = freqs.getNumDocsAsInteger();
    final Weight weight = rewrittenQuery.weight(new CachedDfSource(freqs.getAll(), numDocs, new DefaultSimilarity()));
    int totalHits = 0;
    final int shardsCount = shards.length;

    // Run the search in parallel on the shards with a thread pool.
    CompletionService<SearchResult> csSearch = new ExecutorCompletionService<SearchResult>(_threadPool);
View Full Code Here

TOP

Related Classes of org.apache.lucene.search.Weight

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.