MultiRetrieval implements Retrieval { public MultiRetrieval(ArrayList<Retrieval> indexes, Parameters p) throws Exception { this.retrievals = indexes; this.globalParameters = p; initRetrieval(); this.features = new FeatureFactory(this.globalParameters); defaultTraversals = features.getTraversals(this); } MultiRetrieval(ArrayList<Retrieval> indexes, Parameters p); @Override void close(); @Override IndexPartStatistics getIndexPartStatistics(String partName); @Override Parameters getAvailableParts(); @Override Parameters getGlobalParameters(); @Override Document getDocument(String identifier, DocumentComponents p); @Override Map<String, Document> getDocuments(List<String> identifiers, DocumentComponents p); @Override Results executeQuery(Node root); @Override Results executeQuery(Node queryTree, Parameters p); @Override Node transformQuery(Node root, Parameters qp); @Override FieldStatistics getCollectionStatistics(String nodeString); @Override FieldStatistics getCollectionStatistics(Node node); @Override NodeStatistics getNodeStatistics(String nodeString); @Override NodeStatistics getNodeStatistics(Node node); @Override NodeType getNodeType(Node node); String getPartName(Node node); @Override QueryType getQueryType(Node node); @Override Integer getDocumentLength(Long docid); @Override Integer getDocumentLength(String docname); @Override String getDocumentName(Long docid); @Override Long getDocumentId(String docname); @Override void addNodeToCache(Node node); @Override void addAllNodesToCache(Node node); @Override Tokenizer getTokenizer();  }
@Test public void testMultiRetrieval() throws Exception { File trecCorpusFile1 = null; File trecCorpusFile2 = null; File index1 = null; File index2 = null; try { String trecCorpus = AppTest.trecDocument("i1-55", "This is a sample document") + AppTest.trecDocument("i1-59", "sample document two"); trecCorpusFile1 = FileUtility.createTemporary(); StreamUtil.copyStringToFile(trecCorpus, trecCorpusFile1); index1 = FileUtility.createTemporaryDirectory(); App.main(new String[]{"build", "--indexPath=" + index1.getAbsolutePath(), "--inputPath=" + trecCorpusFile1.getAbsolutePath()}); trecCorpus = AppTest.trecDocument("i2-55", "This is a sample also a document") + AppTest.trecDocument("i2-59", "sample document four long"); trecCorpusFile2 = FileUtility.createTemporary(); StreamUtil.copyStringToFile(trecCorpus, trecCorpusFile2); index2 = FileUtility.createTemporaryDirectory(); App.main(new String[]{"build", "--indexPath=" + index2.getAbsolutePath(), "--inputPath=" + trecCorpusFile2.getAbsolutePath()}); Parameters params = Parameters.create(); String[] indexes = {index1.getAbsolutePath(), index2.getAbsolutePath()}; params.set("index", Arrays.asList(indexes)); MultiRetrieval mr = (MultiRetrieval) RetrievalFactory.create(params); String query = "#combine( sample document )"; Node parsedQuery = StructuredQuery.parse(query); Parameters qp = Parameters.create(); Node queryTree = mr.transformQuery(parsedQuery, qp); String expected = "#combine:w=1.0(" + " #dirichlet:" + "collectionLength=19:" + "maximumCount=1:" + "nodeFrequency=4:" + "w=0.5" + "( #lengths:document:part=lengths() #counts:sample:part=postings.krovetz() ) " + "#dirichlet:" + "collectionLength=19:" + "maximumCount=1:" + "nodeFrequency=4:" + "w=0.5" + "( #lengths:document:part=lengths() #counts:document:part=postings.krovetz() ) )"; assertEquals(queryTree.toString(), expected); List<ScoredDocument> results = mr.executeQuery(queryTree, qp).scoredDocuments; ScoredDocument[] expDocs = new ScoredDocument[4]; expDocs[0] = new ScoredDocument("i1-59", 1, -1.5569809573716442); expDocs[1] = new ScoredDocument("i2-59", 2, -1.5576460721284549); expDocs[2] = new ScoredDocument("i1-55", 3, -1.5583107448016458); expDocs[3] = new ScoredDocument("i2-55", 4, -1.5596387662451652); assertEquals(expDocs.length, results.size()); for (int i = 0; i < expDocs.length; i++) { assertEquals(expDocs[i].documentName, results.get(i).documentName); assertEquals(expDocs[i].rank, results.get(i).rank); assertEquals(expDocs[i].score, results.get(i).score, 0.000001); } } finally { if (trecCorpusFile1 != null) { trecCorpusFile1.delete(); } if (trecCorpusFile2 != null) { trecCorpusFile2.delete(); } if (index1 != null) { FSUtil.deleteDirectory(index1); } if (index2 != null) { FSUtil.deleteDirectory(index2); } } }