0
0

optimization when boolean query has should constituents only

A common search case is when a user performs a query-string query,
such as for "the lazy dog".  That would be parsed into a boolean query
with a nil Must child, a nil MustNot child, and a non-nil Should child
(a disjunction query for "the", "lazy", "dog").

The optimization in this case is to return just the Should child
directly, skipping any additional Must and MustNot overhead.

On a dev box bleve-query benchmark on a wiki index with a query string
of "text:afternoon text:coffee", the throughput was previously 873qps
and with this change hits 940qps.
This commit is contained in:
Steve Yen 2016-09-20 18:17:54 -07:00
parent 46a46357a7
commit 16dac98f71

View File

@ -123,6 +123,11 @@ func (q *booleanQuery) Searcher(i index.IndexReader, m *IndexMapping, explain bo
return nil, err return nil, err
} }
} }
if mustSearcher == nil && shouldSearcher != nil && mustNotSearcher == nil {
return shouldSearcher, nil
}
return searchers.NewBooleanSearcher(i, mustSearcher, shouldSearcher, mustNotSearcher, explain) return searchers.NewBooleanSearcher(i, mustSearcher, shouldSearcher, mustNotSearcher, explain)
} }