"MatchPhraseQuery always requires position information" sounds reasonable, but there is at least one case in which this can lead to confusing behavior.
Sometimes, the phrase you pass in analyzes to just a single term, and when that happens, logically the position information isn't needed, because any match of this term should count, there are no other terms which must exist relative to it. However, currently the implementation doesn't handle this, and the query fails.
For users this is confusing when the same document will satisfy the MatchQuery, but not a MatchPhraseQuery on the same term.
NOTE: this can indirectly occur in cases where a user has added double-quotes to a query string query. This technique can be used to force a text match, but in this case it also can break behavior when the position information has not been indexed.
Short-term workaround:
Be sure to use the SearchTermPositions() option on fields where you would like to use MatchPhraseQuery.
Possible improvements:
in the case where the resulting token stream is length 1, we could revert back to a traditional MatchQuery
alternatively, it could be possible to modify the match phrase logic to directly support correct behavior in the case where the location information is missing, but it isn't needed (single token)
"MatchPhraseQuery always requires position information" sounds reasonable, but there is at least one case in which this can lead to confusing behavior.
Sometimes, the phrase you pass in analyzes to just a single term, and when that happens, logically the position information isn't needed, because any match of this term should count, there are no other terms which must exist relative to it. However, currently the implementation doesn't handle this, and the query fails.
For users this is confusing when the same document will satisfy the MatchQuery, but not a MatchPhraseQuery on the same term.
NOTE: this can indirectly occur in cases where a user has added double-quotes to a query string query. This technique can be used to force a text match, but in this case it also can break behavior when the position information has not been indexed.
Short-term workaround:
Be sure to use the
SearchTermPositions()
option on fields where you would like to use MatchPhraseQuery.Possible improvements: