lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stefan Gusenbauer" <stefan.gusenba...@kbse.net>
Subject AW: AW: Determine the index of a hit after using MultiSearcher
Date Tue, 29 Nov 2005 15:05:42 GMT
This is an other good reason for buying the book ultimately! 
Thx
stefan

-----Urspr√ľngliche Nachricht-----
Von: Erik Hatcher [mailto:erik@ehatchersolutions.com] 
Gesendet: Dienstag, 29. November 2005 15:57
An: java-user@lucene.apache.org
Betreff: Re: AW: Determine the index of a hit after using MultiSearcher


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: pbatcoi@gmx.net [mailto:pbatcoi@gmx.net]
> 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: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message