lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erik Hatcher <e...@ehatchersolutions.com>
Subject Re: AW: AW: Determine the index of a hit after using MultiSearcher
Date Tue, 29 Nov 2005 17:53:28 GMT

On 29 Nov 2005, at 10:05, Stefan Gusenbauer wrote:
> This is an other good reason for buying the book ultimately!

Well, unfortunately, this particular trivia isn't covered in the  
book, but rather behind the scenes of the website about the book.  I  
will mark this as something to add to the 2nd edition though.

	Erik


> -----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


---------------------------------------------------------------------
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