lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Uwe Schindler" <>
Subject RE: Lucene parsing overhead VS directly creating queries?
Date Fri, 14 Oct 2016 14:52:16 GMT

The overhead is neglectible in most cases. The real reason why you want to create queries
on your own is that you have all control:

- if you have (unanalyzed) StringField and want to query them, it is better to build queries
by hand. This is mostly the case for special data types or facet filters applied
- if you want to use queries not supported by query parser
- if you already complex construct queries via code, then *always* do it by code. Only parts
that were entered by users and should be parsed/analyzed should be processed by a query parser.
The final query (e.g user input, filters for facets, data range,...) should be constructed
in API. If you don't do this you will end up in query escaping hell...!!!

If you just want to convert a string to a query including text analysis, but no query syntax
(similar to Elasticsearch's match query), use Lucene's QueryBuilder class.


Uwe Schindler
H.-H.-Meier-Allee 63, D-28213 Bremen

> -----Original Message-----
> From: Rajnish Kamboj []
> Sent: Friday, October 14, 2016 4:36 PM
> To:
> Subject: Lucene parsing overhead VS directly creating queries?
> Hi
> Is there any performance gain of writing Lucene queries (query objects)
> rather than parsing Lucene query strings using QueryParser. I believe
> parser has its own overhead.
> Example:
> Term lTerm1 = new Term("rs", "9971000001");
> Term uTerm1 = new Term("rs", "9971000004");
> TermRangeQuery trQuery1 = new TermRangeQuery("rs", lTerm1.bytes(),
> uTerm1.bytes(), true, true);
> VS
> Parsing the below string using QueryParser and then perform search.
> Query q = new QueryParser("def", analyzer).parse("rs:[9971000001 TO
> 9971000004]");
> --
> Rajnish

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message