Package org.apache.lucene.search

Examples of org.apache.lucene.search.HitCollector


    IndexSearcher searcher = new IndexSearcher(store);
    final float[] scores = new float[NUM_DOCS];
    float lastScore = 0.0f;
   
    // default similarity should put docs with shorter length first
    searcher.search(new TermQuery(new Term("field", "word")), new HitCollector() {
      public final void collect(int doc, float score) {
        scores[doc] = score;
      }
    });
    searcher.close();
   
    lastScore = Float.MAX_VALUE;
    for (int i = 0; i < NUM_DOCS; i++) {
      String msg = "i=" + i + ", " + scores[i] + " <= " + lastScore;
      assertTrue(msg, scores[i] <= lastScore);
      //System.out.println(msg);
      lastScore = scores[i];
    }

    FieldNormModifier fnm = new FieldNormModifier(store, s);
    fnm.reSetNorms("field");
   
    // new norm (with default similarity) should put longer docs first
    searcher = new IndexSearcher(store);
    searcher.search(new TermQuery(new Term("field", "word"))new HitCollector() {
      public final void collect(int doc, float score) {
        scores[doc] = score;
      }
    });
    searcher.close();
View Full Code Here


    IndexSearcher searcher = new IndexSearcher(store);
    final float[] scores = new float[NUM_DOCS];
    float lastScore = 0.0f;
   
    // default similarity should return the same score for all documents for this query
    searcher.search(new TermQuery(new Term("untokfield", "20061212")), new HitCollector() {
      public final void collect(int doc, float score) {
        scores[doc] = score;
      }
    });
    searcher.close();
View Full Code Here

 
  // default similarity should put docs with shorter length first
  searcher = new IndexSearcher(store);
  searcher.search
      (new TermQuery(new Term("field", "word")),
       new HitCollector() {
     public final void collect(int doc, float score) {
         scores[doc] = score;
     }
       });
  searcher.close();
 
  lastScore = Float.MAX_VALUE;
  for (int i = 0; i < NUM_DOCS; i++) {
      String msg = "i=" + i + ", "+scores[i]+" <= "+lastScore;
      assertTrue(msg, scores[i] <= lastScore);
      //System.out.println(msg);
      lastScore = scores[i];
  }

  // override the norms to be inverted
  Similarity s = new DefaultSimilarity() {
    public float lengthNorm(String fieldName, int numTokens) {
        return (float)numTokens;
    }
      };
  LengthNormModifier lnm = new LengthNormModifier(store, s);
  lnm.reSetNorms("field");

  // new norm (with default similarity) should put longer docs first
  searcher = new IndexSearcher(store);
  searcher.search
      (new TermQuery(new Term("field", "word")),
       new HitCollector() {
     public final void collect(int doc, float score) {
         scores[doc] = score;
     }
       });
  searcher.close();
View Full Code Here

   *
   *  This simulates the streaming search use case, where all hits are supposed to
   *  be processed, regardless of their relevance.
   */
  public static void doStreamingSearch(final Searcher searcher, Query query) throws IOException {
    HitCollector streamingHitCollector = new HitCollector() {
     
      // simply print docId and score of every matching document
      public void collect(int doc, float score) {
        System.out.println("doc="+doc+" score="+score);
      }
View Full Code Here

      throw new IllegalArgumentException("query must not be null");
   
    Searcher searcher = createSearcher();
    try {
      final float[] scores = new float[1]; // inits to 0.0f (no match)
      searcher.search(query, new HitCollector() {
        public void collect(int doc, float score) {
          scores[0] = score;
        }
      });
      float score = scores[0];
View Full Code Here

      throw new IllegalArgumentException("query must not be null");
   
    Searcher searcher = createSearcher();
    try {
      final float[] scores = new float[1]; // inits to 0.0f (no match)
      searcher.search(query, new HitCollector() {
        public void collect(int doc, float score) {
          scores[0] = score;
        }
      });
      float score = scores[0];
View Full Code Here

        searcher = new IndexSearcher((Directory)index);
      else
        searcher = ((MemoryIndex) index).createSearcher();

      final float[] scores = new float[1]; // inits to 0.0f
      searcher.search(query, new HitCollector() {
        public void collect(int doc, float score) {
          scores[0] = score;
        }
      });
      float score = scores[0];
View Full Code Here

            final ChildrenCalculator[] calc = new ChildrenCalculator[1];
            if (nameTestScorer == null)
            {
               // always use simple in that case
               calc[0] = new SimpleChildrenCalculator(reader, hResolver);
               contextScorer.score(new HitCollector()
               {
                  public void collect(int doc, float score)
                  {
                     calc[0].collectContextHit(doc);
                  }
               });
            }
            else
            {
               // start simple but switch once threshold is reached
               calc[0] = new SimpleChildrenCalculator(reader, hResolver);
               contextScorer.score(new HitCollector()
               {

                  private List docIds = new ArrayList();

                  public void collect(int doc, float score)
View Full Code Here

        private void calculateParent() throws IOException {
            if (hits == null) {
                hits = new BitSet(reader.maxDoc());

                final IOException[] ex = new IOException[1];
                contextScorer.score(new HitCollector() {

                    private int[] docs = new int[1];

                    public void collect(int doc, float score) {
                        try {
View Full Code Here

        searcher = new IndexSearcher((Directory)index);
      else
        searcher = ((MemoryIndex) index).createSearcher();

      final float[] scores = new float[1]; // inits to 0.0f
      searcher.search(query, new HitCollector() {
        public void collect(int doc, float score) {
          scores[0] = score;
        }
      });
      float score = scores[0];
View Full Code Here

TOP

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

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.