Index: TestMultiSearcher.java =================================================================== --- TestMultiSearcher.java (revision 345931) +++ TestMultiSearcher.java (working copy) @@ -181,4 +181,113 @@ } mSearcher3.close(); } + + private static Document createDocument(String contents1, String contents2) { + Document document=new Document(); + + document.add(new Field("contents", contents1, Field.Store.YES, Field.Index.UN_TOKENIZED)); + + if (contents2!=null) { + document.add(new Field("contents", contents2, Field.Store.YES, Field.Index.UN_TOKENIZED)); + } + + return document; + } + + private static void initIndex(Directory directory, int nDocs, boolean create, String contents2) throws IOException { + IndexWriter indexWriter=null; + + try { + indexWriter=new IndexWriter(directory, null, create); + + for (int i=0; i scores[1]); + + indexSearcher1.close(); + ramDirectory1.close(); + hits=null; + + + + RAMDirectory ramDirectory2; + IndexSearcher indexSearcher2; + + ramDirectory1=new RAMDirectory(); + ramDirectory2=new RAMDirectory(); + + // Now put the documents in a different index + initIndex(ramDirectory1, nDocs, true, null); // documents with a single token "doc0", "doc1", etc... + initIndex(ramDirectory2, nDocs, true, "x"); // documents with two tokens "doc0" and "x", "doc1" and x, etc... + + indexSearcher1=new IndexSearcher(ramDirectory1); + indexSearcher2=new IndexSearcher(ramDirectory2); + + Searcher searcher=getMultiSearcherInstance(new Searcher[] { indexSearcher1, indexSearcher2 }); + + hits=searcher.search(query); + + assertEquals(message, 2, hits.length()); + + // The scores should be the same (within reason) + assertEquals(message, scores[0], hits.score(0), 1e-6); // This will a document from ramDirectory1 + assertEquals(message, scores[1], hits.score(1), 1e-6); // This will a document from ramDirectory2 + + + + // Adding a Sort.RELEVANCE object should not change anything + hits=searcher.search(query, Sort.RELEVANCE); + + assertEquals(message, 2, hits.length()); + + assertEquals(message, scores[0], hits.score(0), 1e-6); // This will a document from ramDirectory1 + assertEquals(message, scores[1], hits.score(1), 1e-6); // This will a document from ramDirectory2 + + searcher.close(); + + ramDirectory1.close(); + ramDirectory2.close(); + } }