On Thursday 21 October 2004 23:03, Doug Cutting wrote:

> Idf's are already computed globally across all indexes. ÂTf's are local
> to the document. ÂIn short, scores from a MultiSearcher are the same as
> when searching an IndexReader with the same documents.

That doesn't seem to be the case in the attached test -- am I using 
MultiSearcher in the wrong way or what might be the problem?
The output of the attached test is:

1+2 searched with Multisearcher:
two blah three score=0.70273256
one blah three score=0.35615897
one foo three score=0.35615897
one foobar three score=0.35615897

1+2 indexed together:
one blah three score=0.5911608
one foo three score=0.5911608
one foobar three score=0.5911608
two blah three score=0.5911608

-- 
http://www.danielnaber.de
import java.io.IOException;

import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.*;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.RAMDirectory;

/*
 * Created on 21.10.2004
 */

/**
 * @author dnaber
 */
public class RankingTest {

  IndexWriter iw;
  
  public static void main(String[] args) throws IOException {
    new RankingTest();
  }
  
  private RankingTest() throws IOException {
    multi();
    together();
  }
  
  private void multi() throws IOException {
    Directory d = new RAMDirectory();
    iw = new IndexWriter(d, new StandardAnalyzer(), true);
    addCollection1();
    iw.close();

    Directory d2 = new RAMDirectory();
    iw = new IndexWriter(d2, new StandardAnalyzer(), true);
    addCollection2();
    iw.close();
    
    System.out.println("1+2 searched with Multisearcher:");
    Searchable[] s = new Searchable[2];
    s[0] = new IndexSearcher(d);
    s[1] = new IndexSearcher(d2);
    //MultiSearcher ms = new ParallelMultiSearcher(s);
    MultiSearcher ms = new MultiSearcher(s);
    Query q = new TermQuery(new Term("body", "three"));
    Hits h = ms.search(q);
    for(int i = 0; i < h.length(); i++) {
      Document doc = h.doc(i);
      System.out.println(doc.get("body") + " score=" + h.score(i));
    }
  }
  
  private void together() throws IOException {
    System.out.println("\n1+2 indexed together:");
    Directory d = new RAMDirectory();
    iw = new IndexWriter(d, new StandardAnalyzer(), true);
    addCollection1();
    addCollection2();
    iw.close();
    search("three", d);
  }

  private void search(String string, Directory d) throws IOException {
    IndexSearcher is = new IndexSearcher(d);
    Query q = new TermQuery(new Term("body", string));
    Hits h = is.search(q);
    for(int i = 0; i < h.length(); i++) {
      Document doc = h.doc(i);
      System.out.println(doc.get("body") + " score=" + h.score(i));
    }
    is.close();
  }

  private void addCollection1() throws IOException {
    add("one blah three");
    add("one foo three");
    add("one foobar three");
  }
  
  private void addCollection2() throws IOException {
    add("two blah three");
    add("two foo xxx");
    add("two foobar xxx");
  }

  private void add(String string) throws IOException {
    Document d = new Document();
    d.add(new Field("body", string, Field.Store.YES, Field.Index.TOKENIZED));
    iw.addDocument(d);
  }
  
}

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to