Return-Path: Delivered-To: apmail-incubator-lucene-net-user-archive@locus.apache.org Received: (qmail 60466 invoked from network); 11 Feb 2008 16:15:18 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 11 Feb 2008 16:15:18 -0000 Received: (qmail 94853 invoked by uid 500); 11 Feb 2008 16:15:11 -0000 Delivered-To: apmail-incubator-lucene-net-user-archive@incubator.apache.org Received: (qmail 94639 invoked by uid 500); 11 Feb 2008 16:15:11 -0000 Mailing-List: contact lucene-net-user-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: lucene-net-user@incubator.apache.org Delivered-To: mailing list lucene-net-user@incubator.apache.org Received: (qmail 94630 invoked by uid 99); 11 Feb 2008 16:15:11 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 11 Feb 2008 08:15:11 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of mffmartin@gmail.com designates 64.233.170.189 as permitted sender) Received: from [64.233.170.189] (HELO rn-out-0910.google.com) (64.233.170.189) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 11 Feb 2008 16:14:40 +0000 Received: by rn-out-0910.google.com with SMTP id e24so1962463rng.6 for ; Mon, 11 Feb 2008 08:14:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=6gsfAm2my7A3vmvBkiCTQphPg8/RidE25ZqGgonSMT4=; b=LuIdaAJAh/Nu2gaufkXxfTI63jx/5BLaqcRY4XFUFRwvLJzkDtsZvvcGBJ9lQcXkapI0YHa4wmezmqUAKk4oZugARQzQlk8a/ktyZFryz3Uv3+jJIjvMRgelnpg+dySmClwevettkWbovr7VRp2pYu7+pp7acnjgEJR8+pVgvwg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=PSsiJ5xK/CwF+eU80dRWyf2lE/pzhJxrW/WUS0TQ2zsEwrAgR8XGjjP2QSmfKMn/jG8YFGpY0rdn32xkicUrgk14bCH3QYHNYLdLcdHg0FkW1kbwBKGhFd9B8KzZrOmboTlN1saGknTFTDkglE+fs41F3VMUk2w1/F5wH/ydgFE= Received: by 10.142.245.10 with SMTP id s10mr109969wfh.186.1202746484559; Mon, 11 Feb 2008 08:14:44 -0800 (PST) Received: by 10.142.223.2 with HTTP; Mon, 11 Feb 2008 08:14:44 -0800 (PST) Message-ID: Date: Mon, 11 Feb 2008 17:14:44 +0100 From: "Martin Nilsson" To: lucene-net-user@incubator.apache.org Subject: Re: QueryParser vs own QueryBuilder In-Reply-To: <80CF7FF9C81BC64FB8453D113F49D22C0EA3D4F4E3@USWAL-MXVS1.amer.thermo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <80CF7FF9C81BC64FB8453D113F49D22C0EA3D4F4E3@USWAL-MXVS1.amer.thermo.com> X-Virus-Checked: Checked by ClamAV on apache.org Neal, Thanks for your answer! I have also looked at the underlying types and they look the same for both (QueryParser and QueryBuilder) queries. But I only looked at the type of query and the term of the query. Is there anything else I should look at? The internalSearcher is the same, I'm sure. "I have looked at the types of the underlying query and they are also the same. BooleanQuery with 6 clauses where 5 are term queries and one, title, is a phrase query. Looks the same both for my query and the one that QueryParser.Parse creates." My own Query Builder: query.GetType().Name "BooleanQuery" ((BooleanQuery) query).GetClauses()[0].GetQuery() {category:general} [Lucene.Net.Search.TermQuery]: {category:general} ((BooleanQuery) query).GetClauses()[1].GetQuery() {product_type:1763} [Lucene.Net.Search.TermQuery]: {product_type:1763} ((BooleanQuery) query).GetClauses()[2].GetQuery() {title:"shirt brewality"} [Lucene.Net.Search.PhraseQuery]: {title:"shirt brewality"} ((BooleanQuery) query).GetClauses()[3].GetQuery() {country:2} [Lucene.Net.Search.TermQuery]: {country:2} ((BooleanQuery) query).GetClauses()[4].GetQuery() {whitelabel:5} [Lucene.Net.Search.TermQuery]: {whitelabel:5} ((BooleanQuery) query).GetClauses()[5].GetQuery() {price_type:1} [Lucene.Net.Search.TermQuery]: {price_type:1} QueryParser: query.GetType().Name "BooleanQuery" ((BooleanQuery) query).GetClauses()[0].GetQuery() {category:general} [Lucene.Net.Search.TermQuery]: {category:general} ((BooleanQuery) query).GetClauses()[1].GetQuery() {product_type:1763} [Lucene.Net.Search.TermQuery]: {product_type:1763} ((BooleanQuery) query).GetClauses()[2].GetQuery() {title:"shirt brewality"} [Lucene.Net.Search.PhraseQuery]: {title:"shirt brewality"} ((BooleanQuery) query).GetClauses()[3].GetQuery() {country:2} [Lucene.Net.Search.TermQuery]: {country:2} ((BooleanQuery) query).GetClauses()[4].GetQuery() {whitelabel:5} [Lucene.Net.Search.TermQuery]: {whitelabel:5} ((BooleanQuery) query).GetClauses()[5].GetQuery() {price_type:1} [Lucene.Net.Search.TermQuery]: {price_type:1} On Feb 11, 2008 3:54 PM, Granroth, Neal V. wrote: > Martin, > > It is important to remember that Search(...) does not work from the text representation of the Query object that you see when you use the ToString() method. Instead it works from the type of objects of which the Query object is composed and the clauses that join them together. > > It is entirely possible that there is a bug or operational quirk in ToString(), which makes your two Query objects look identical even when they are not. (For example, maybe your QueryBuilder is inserting a null Term that causes the search to fail, but that ToString() does not list since it is null, meaningless, term.) > > Another possibility to look at is your "internalSearcher" object. Are you absolutely sure that it is being constructed in exactly the same way for both searches? > > -- Neal > > > > > -----Original Message----- > From: Martin Nilsson [mailto:mffmartin@gmail.com] > Sent: Sunday, February 10, 2008 12:42 PM > To: lucene-net-user@incubator.apache.org > Subject: QueryParser vs own QueryBuilder > > Hi, > > I'm struggling with a problem I can't solve. I create my Query object from > my own implemented query builder. However, I don't get any results back but > if I do a query.ToString and send it to the QueryParser I get result. Let me > show you some code. > > //this doesn't return any results > //query.ToString() = "+category:general +product_type:1763 +title:\"shirt > brewality\" +country:2 +whitelabel:5 +price_type:1" > ISearchResult searchResult2 = searcher.Search(query); > > //this returns 4 results > //query.Clone().ToString() = "+category:general +product_type:1763 > +title:\"shirt brewality\" +country:2 +whitelabel:5 +price_type:1" > ISearchResult searchResult = searcher.Search(query.Clone > ().ToString()); > > //this is called from query.Clone().ToString() above > public ISearchResult Search(string searchTerms) > { > if (string.IsNullOrEmpty(searchTerms)) throw new > ArgumentNullException("searchTerms"); > > QueryParser parser = new QueryParser(defaultField, analyzer); > parser.SetFuzzyMinSim(fuzzyMinSimilarity); > Query query = parser.Parse(searchTerms); > //the one that doesn't return any results calls below (Search(Query)) > directly. > //So the only, what I can see, difference is the code above in this > function > return Search(query); > } > > //and both are calling this > public ISearchResult Search(Query query) > { > //query.ToString() returns below result for BOTH, the one that returns 0 > and the one that returns 4 result, queries > //"+category:general +product_type:1763 +title:\"shirt brewality\" > +country:2 +whitelabel:5 +price_type:1" > Hits hits = internalSearcher.Search(query); > //code to create result > ... > } > > I have looked at the types of the underlying query and they are also the > same. BooleanQuery with 6 clauses where 5 are term queries and one, title, > is a phrase query. Looks the same both for my query and the one that > QueryParser.Parse creates. > > I'm sooo confused! Please help! > > Br, > Martin >