caio.co/de/cerberus

Search: Rewrite the query before using it

The lucene query derived from SearchQuery is used for count() and
search(); Both calls trigger a `IndexSearcher.rewrite(Query)` call, so
this patch reduces the duplicated work by rewriting it before usage.

Note that this does not mean `rewrite(Query)` won't be called again,
just that its subsequent calls will be cheaper.
Id
33d9afab7bb1ebb1732f225fe653570ff7b2aad3
Author
Caio
Commit time
2019-05-05T11:02:54+02:00

Modified src/main/java/co/caio/cerberus/search/SearcherImpl.java

@@ -97,7 +97,7
private SearchResult _search(SearchQuery query) throws IOException {
final int maxFacets = query.maxFacets();

- var luceneQuery = toLuceneQuery(query);
+ var luceneQuery = indexSearcher.rewrite(toLuceneQuery(query));

final int count = indexSearcher.count(luceneQuery);
final boolean computeFacets = maxFacets > 0 && canComputeFacets(count);