Here is a hint:
package org.apache.lucene.search;
import java.io.IOException;
/**
* Implements search over a set of <code>Searchables</code> using
multiple filters.
*/
public class MultiFilterMultiSearcher extends MultiSearcher {
public MultiFilterMultiSearcher(Searchable[] searchables)
throws IOException {
super(searchables);
}
/**
* Pass filter for Searchable[i] as filter[i].
*/
public TopDocs search(Weight weight, Filter[] filters, int nDocs)
throws IOException {
HitQueue hq = new HitQueue(nDocs);
int totalHits = 0;
int[] starts = getStarts();
Searchable[] searchables = getSearchables();
for (int i = 0; i < searchables.length; i++) { // search each
searcher
TopDocs docs = searchables[i].search(weight, filters[i], nDocs);
totalHits += docs.totalHits; // update totalHits
ScoreDoc[] scoreDocs = docs.scoreDocs;
for (int j = 0; j < scoreDocs.length; j++) { // merge
scoreDocs into hq
ScoreDoc scoreDoc = scoreDocs[j];
scoreDoc.doc += starts[i]; // convert doc
if (!hq.insert(scoreDoc)) {
break; // no more scores > minScore
}
}
}
ScoreDoc[] scoreDocs = new ScoreDoc[hq.size()];
for (int i = hq.size() - 1; i >= 0; i--) // put docs in array
scoreDocs[i] = (ScoreDoc) hq.pop();
float maxScore = (totalHits == 0) ? Float.NEGATIVE_INFINITY
: scoreDocs[0].score;
return new TopDocs(totalHits, scoreDocs, maxScore);
}
public TopFieldDocs search(Weight weight , Filter[] filters, int n,
Sort sort)
throws IOException {
FieldDocSortedHitQueue hq = null;
int totalHits = 0;
float maxScore = Float.NEGATIVE_INFINITY;
int[] starts = getStarts();
Searchable[] searchables = getSearchables();
for (int i = 0; i < searchables.length; i++) { // search each
searcher
TopFieldDocs docs = searchables[i].search(weight,
filters[i], n, sort);
if (hq == null) {
hq = new FieldDocSortedHitQueue(docs.fields, n);
}
totalHits += docs.totalHits; // update totalHits
maxScore = Math.max(maxScore, docs.getMaxScore());
ScoreDoc[] scoreDocs = docs.scoreDocs;
for (int j = 0; j < scoreDocs.length; j++) { // merge
scoreDocs into hq
ScoreDoc scoreDoc = scoreDocs[j];
scoreDoc.doc += starts[i]; // convert doc
if (!hq.insert(scoreDoc)) {
break; // no more scores > minScore
}
}
}
ScoreDoc[] scoreDocs = new ScoreDoc[hq.size()];
for (int i = hq.size() - 1; i >= 0; i--) // put docs in array
scoreDocs[i] = (ScoreDoc) hq.pop();
return new TopFieldDocs(totalHits, scoreDocs, hq.getFields(),
maxScore);
}
}
- Mark
Spencer Tickner wrote:
Hi List,
Thanks in advance for the help. I can't wrap my head around the
MultiSearcher. I need to search across multiple indexes, but also need to
filter documents from users based on Access. The problem seems to be that
MultiSearcher takes in 1 filter, however my filter varies from one index to
another. Any advice on implementing this would be a huge help.
Thanks,
Spencer
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]