lucenenet-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Granroth, Neal V." <>
Subject RE: QueryParser vs own QueryBuilder
Date Mon, 11 Feb 2008 14:54:33 GMT

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 []
Sent: Sunday, February 10, 2008 12:42 PM
Subject: QueryParser vs own QueryBuilder


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<ITinyItem> 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<ITinyItem> searchResult = searcher.Search(query.Clone

//this is called from query.Clone().ToString() above
public ISearchResult<T> Search(string searchTerms)
  if (string.IsNullOrEmpty(searchTerms)) throw new

  QueryParser parser = new QueryParser(defaultField, analyzer);
  Query query = parser.Parse(searchTerms);
  //the one that doesn't return any results calls below (Search(Query))
  //So the only, what I can see, difference is the code above in this
  return Search(query);

//and both are calling this
public ISearchResult<T> 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!


View raw message