On 29 Nov 2005, at 08:51, Stefan Gusenbauer wrote:
I've done this in the same way every document contains a field with
the corresponding index. I fear there is no other way to do this.
Fear not. There is a way. In fact, lucenebook.com uses this
capability to determine whether a search hit is from the book content
or from the blog content. Here's a snippet of its code:
MultiSearcher searcher = (MultiSearcher) context.getAttribute
("searcher");
IndexReader[] readers = (IndexReader[]) context.getAttribute
("readers");
Hits hits = searcher.search(query);
HttpServletRequest request = cycle.getRequestContext
().getRequest();
int currentPage = request.getParameter("page") == null ? 1 :
Integer.parseInt(request.getParameter("pa
ge"));
int numPages = (hits.length() / RESULTS_PER_PAGE) +
(hits.length() % RESULTS_PER_PAGE == 0 ? 0 : 1);
if (currentPage > numPages) currentPage = numPages;
int numPages = (hits.length() / RESULTS_PER_PAGE) +
(hits.length() % RESULTS_PER_PAGE == 0 ? 0 : 1);
if (currentPage > numPages) currentPage = numPages;
if (currentPage < 1) currentPage = 1;
setProperty("currentPage", new Integer(currentPage)); //
reset in case original value is out of bound
s
int startHit = (currentPage - 1) * RESULTS_PER_PAGE + 1;
int endHit = currentPage * RESULTS_PER_PAGE;
if (endHit > hits.length()) {
endHit = hits.length();
}
setProperty("startHit", new Integer(startHit));
setProperty("endHit", new Integer(endHit));
setProperty("numPages", new Integer(numPages));
setProperty("numHits", new Integer(hits.length()));
logger.info("Query: " + expression + " : #hits = " +
hits.length() + " : page=" + currentPage);
if (hits.length() == 0) return;
ArrayList results = new ArrayList();
for (int i = startHit; i <= endHit; i++) {
int position = i - 1;
Document doc = hits.doc(position);
int indexIndex = searcher.subSearcher(hits.id(position));
// ...
}
The trick is to use searcher.subSearcher with the document number
from hits.
Erik
-----Ursprüngliche Nachricht-----
Von: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Gesendet: Dienstag, 29. November 2005 14:48
An: java-user@lucene.apache.org
Betreff: Determine the index of a hit after using MultiSearcher
Hello,
I am searching over multiple indices using MultiSearcher. Thus I
get hits
from various indices. Is it possible to determine from which index
a hit
comes?
The solution I found is to store the index in a document's field,
but this
causes some overhead. I would like to find another solution.
Thank you for having read this!
Peter
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]