Return-Path: Delivered-To: apmail-lucene-java-user-archive@www.apache.org Received: (qmail 95311 invoked from network); 29 Nov 2005 15:06:11 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 29 Nov 2005 15:06:11 -0000 Received: (qmail 31851 invoked by uid 500); 29 Nov 2005 15:06:04 -0000 Delivered-To: apmail-lucene-java-user-archive@lucene.apache.org Received: (qmail 31824 invoked by uid 500); 29 Nov 2005 15:06:03 -0000 Mailing-List: contact java-user-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: java-user@lucene.apache.org Delivered-To: mailing list java-user@lucene.apache.org Received: (qmail 31807 invoked by uid 99); 29 Nov 2005 15:06:03 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 29 Nov 2005 07:06:03 -0800 X-ASF-Spam-Status: No, hits=0.8 required=10.0 tests=INFO_TLD X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [194.96.178.21] (HELO ad1.ad.kbse.net) (194.96.178.21) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 29 Nov 2005 07:07:33 -0800 X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message Subject: AW: AW: Determine the index of a hit after using MultiSearcher MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Date: Tue, 29 Nov 2005 16:05:42 +0100 Message-ID: <28CC4850CA7A704FB1980317A99FA036749A@ad1.ad.kbse.net> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: AW: Determine the index of a hit after using MultiSearcher Thread-Index: AcX09QEDFFJejvIZS/C4kz0G53ZrbgAARYGQ From: "Stefan Gusenbauer" To: X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N This is an other good reason for buying the book ultimately!=20 Thx stefan -----Urspr=FCngliche Nachricht----- Von: Erik Hatcher [mailto:erik@ehatchersolutions.com]=20 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 =20 > 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 =20 capability to determine whether a search hit is from the book content =20 or from the blog content. Here's a snippet of its code: MultiSearcher searcher =3D (MultiSearcher) context.getAttribute=20 ("searcher"); IndexReader[] readers =3D (IndexReader[]) context.getAttribute=20 ("readers"); Hits hits =3D searcher.search(query); HttpServletRequest request =3D cycle.getRequestContext=20 ().getRequest(); int currentPage =3D request.getParameter("page") =3D=3D null ? 1 = : =20 Integer.parseInt(request.getParameter("pa ge")); int numPages =3D (hits.length() / RESULTS_PER_PAGE) + =20 (hits.length() % RESULTS_PER_PAGE =3D=3D 0 ? 0 : 1); if (currentPage > numPages) currentPage =3D numPages; int numPages =3D (hits.length() / RESULTS_PER_PAGE) + =20 (hits.length() % RESULTS_PER_PAGE =3D=3D 0 ? 0 : 1); if (currentPage > numPages) currentPage =3D numPages; if (currentPage < 1) currentPage =3D 1; setProperty("currentPage", new Integer(currentPage)); // =20 reset in case original value is out of bound s int startHit =3D (currentPage - 1) * RESULTS_PER_PAGE + 1; int endHit =3D currentPage * RESULTS_PER_PAGE; if (endHit > hits.length()) { endHit =3D 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 =3D " + =20 hits.length() + " : page=3D" + currentPage); if (hits.length() =3D=3D 0) return; ArrayList results =3D new ArrayList(); for (int i =3D startHit; i <=3D endHit; i++) { int position =3D i - 1; Document doc =3D hits.doc(position); int indexIndex =3D searcher.subSearcher(hits.id(position)); // ... } The trick is to use searcher.subSearcher with the document number =20 from hits. Erik > > > -----Urspr=FCngliche 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 =20 > get hits > from various indices. Is it possible to determine from which index =20 > a hit > comes? > > The solution I found is to store the index in a document's field, =20 > 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