Return-Path: X-Original-To: apmail-lucene-java-user-archive@www.apache.org Delivered-To: apmail-lucene-java-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C328D7014 for ; Tue, 20 Sep 2011 17:32:53 +0000 (UTC) Received: (qmail 76966 invoked by uid 500); 20 Sep 2011 17:32:51 -0000 Delivered-To: apmail-lucene-java-user-archive@lucene.apache.org Received: (qmail 76907 invoked by uid 500); 20 Sep 2011 17:32:51 -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 76899 invoked by uid 99); 20 Sep 2011 17:32:51 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 20 Sep 2011 17:32:51 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of uwe@thetaphi.de designates 188.138.97.18 as permitted sender) Received: from [188.138.97.18] (HELO mail.sd-datasolutions.de) (188.138.97.18) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 20 Sep 2011 17:32:43 +0000 Received: from VEGA (port-92-196-115-146.dynamic.qsc.de [92.196.115.146]) by mail.sd-datasolutions.de (Postfix) with ESMTPSA id 94B8614AA0DF; Tue, 20 Sep 2011 17:32:22 +0000 (UTC) From: "Uwe Schindler" To: , References: <1316538543.28138.YahooMailNeo@web160705.mail.bf1.yahoo.com> In-Reply-To: <1316538543.28138.YahooMailNeo@web160705.mail.bf1.yahoo.com> Subject: RE: QueryWrapperFilter and DocIdSetIterator Date: Tue, 20 Sep 2011 19:32:43 +0200 Message-ID: <01ab01cc77bb$4e44e770$eaceb650$@thetaphi.de> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQORosgo+MAD8UlU7ycIbYHo2w06wZHML2fQ Content-Language: de X-Virus-Checked: Checked by ClamAV on apache.org Hi, I don't see a problem in your code: If you look at the source code of QueryWrapperFilter, it will never = return NULL, so it returns always a DocIdSet theat itself returns the Scorer of = the query as Iterator. @Override public DocIdSet getDocIdSet(final IndexReader reader) throws = IOException { final Weight weight =3D new IndexSearcher(reader).createNormalizedWeight(query); return new DocIdSet() { @Override public DocIdSetIterator iterator() throws IOException { return weight.scorer(reader, true, false); } @Override public boolean isCacheable() { return false; } }; } The only reason the DISI returned by iterator() is null is the case, = when the underlying query returns a null scorer (which can happen if no = documents match the query). One thing is different in your type of execution: Since Lucene 2.9, IndexSearcher executes the query per-segment, but you are executing the filter on the top-level IndexReader (not separately for each segment). = This should not be an issue in Lucene 3.x, but with Lucene trunk this will = throw UnsupportedOperationException. I think, your query seems to really return no documents, I have no idea, why. Uwe ----- Uwe Schindler H.-H.-Meier-Allee 63, D-28213 Bremen http://www.thetaphi.de eMail: uwe@thetaphi.de > -----Original Message----- > From: aberdeen61@yahoo.com [mailto:aberdeen61@yahoo.com] > Sent: Tuesday, September 20, 2011 7:09 PM > To: java-user@lucene.apache.org > Subject: QueryWrapperFilter and DocIdSetIterator >=20 > I've been trying to use the QueryWrapperFilter as part of composing a = set of > filters. Are there limitations on the types of queries it can wrap? = =A0When I try to > get the DocSetIdIterator for the filter it comes up null. This happens even when > the query is a simple TermQuery. >=20 > The following code shows that the iterator for a QueryWrapperFilter returns > null rather than an iterator with the same document as a search using = the > query. > This was run using lucene-core-3.4.0.jar on java 1.6.0_27 > Am I using this incorrectly? Are there constraints or additional information on > how a reader is supposed to be passed to the method to get a DocIdSet? >=20 > On a related note,=A0I examined the TestQueryWrapperFilter source code = in > lucene 3.4.0 which indicates that the=A0QueryWrapperFilter can be used = with > primitive, complex primitive and=A0non primitive Queries. I did note = that the test > for=A0complex primitive query generates a BooleanQuery, but doesn't = use it in > the test. However, even when I corrected that it passed the test, so = I'm unclear > on the difference in the usage in the published test case and my = example > below. >=20 > Thanks, > Dan >=20 > = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D > import java.io.IOException;import > org.apache.lucene.analysis.WhitespaceAnalyzer;import > org.apache.lucene.document.Document; > import org.apache.lucene.document.Field; > import org.apache.lucene.document.Field.Index; > import org.apache.lucene.document.Field.Store; > import org.apache.lucene.index.IndexReader; > import org.apache.lucene.index.IndexWriter; > import org.apache.lucene.index.IndexWriterConfig; > import org.apache.lucene.index.Term; > import org.apache.lucene.store.RAMDirectory; > import org.apache.lucene.util.Version; > import org.apache.lucene.search.DocIdSet; > import org.apache.lucene.search.DocIdSetIterator; > import org.apache.lucene.search.Filter; > import org.apache.lucene.search.IndexSearcher; > import org.apache.lucene.search.QueryWrapperFilter; > import org.apache.lucene.search.TermQuery; > import org.apache.lucene.search.TopDocs; >=20 > public class TestQueryWrapperFilterIterator { > public static void main(String[] args) { > try { > IndexWriterConfig iwconfig =3D new = IndexWriterConfig(Version.LUCENE_34, new > WhitespaceAnalyzer(Version.LUCENE_34)); > iwconfig.setOpenMode(IndexWriterConfig.OpenMode.CREATE); > RAMDirectory dir =3D new RAMDirectory(); > IndexWriter writer =3D new IndexWriter(dir, iwconfig); > Document d =3D new Document(); > d.add(new Field("id", "1001", Store.YES, Index.NOT_ANALYZED)); > d.add(new Field("text", "headline one group one", Store.YES, Index.ANALYZED)); > d.add(new Field("group", "grp1", Store.YES, Index.NOT_ANALYZED)); > writer.addDocument(d); > writer.commit(); > writer.close(); > IndexReader rdr =3D IndexReader.open(dir); > IndexSearcher searcher =3D new IndexSearcher(rdr); > TermQuery tq =3D new TermQuery(new Term("text", "headline")); > TopDocs results =3D searcher.search(tq, 5); > System.out.println("Number of search results: " + results.totalHits); > Filter f =3D new QueryWrapperFilter(tq);DocIdSet dis =3D > f.getDocIdSet(rdr);DocIdSetIterator it =3D dis.iterator(); > if (it !=3D null) { > int docId =3D it.nextDoc(); > while (docId !=3D DocIdSetIterator.NO_MORE_DOCS) { > Document doc =3D rdr.document(docId); > System.out.println("Iterator doc: " + doc.get("id")); > docId =3D it.nextDoc(); > } > } else { > System.out.println("Iterator was null: "); > } > searcher.close(); > rdr.close(); > } catch (IOException ioe) { > ioe.printStackTrace(); > } >=20 > } > } >=20 >=20 > --------------------------------------------------------------------- > 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