Keith
Keith

Reputation: 21244

Lucene: TermQuery vs. SpanTermQuery

There doesn't seem to be any functional difference between TermQuery and SpanTermQuery. Is there any other difference such as in search performance? I'd like to know even if the difference is minuscule.

I'm using Lucene.Net 2.9.4g if that makes a difference.

Upvotes: 1

Views: 1618

Answers (3)

Keith
Keith

Reputation: 21244

I discovered there is a noticeable performance difference between the 2 query types when the search server is under load. TermQuery is faster.

I got the following average search times with a load test using 50 concurrent users against a database with several million documents.

  • With SpanTermQuery: 5 seconds
  • With TermQuery: 3 seconds

(There are other factors that make my averages higher than normal such as large documents, complex queries, and a less-than-ideal server. However the impact of using TermQuery vs. SpanTermQuery is clear.)

Upvotes: 3

Duke
Duke

Reputation: 1

SpanTermQuery need additional IO even if does not need position information. So if TermQuery can work, do not user SpanTermQuery.

Upvotes: 0

Jf Beaulac
Jf Beaulac

Reputation: 5246

If you dont need the features from the Spans search API, there is no functional differences. For example, you would need to use a SpanTermQuery for clauses if you want to use the SpanNearQuery/ SpanOrQuery/SpanNotQuery etc., but if you dont uses the Spans API you dont need it.

Spans are also very handy when you work with Payloads.

The performance should be the same on both classes.

Upvotes: 0

Related Questions