How does ReversedWildcardFilterFactory speed up wi

2019-07-21 21:22发布

问题:

The Solr docs say:

solr.ReversedWildcardFilterFactory

A filter that reverses tokens to provide faster leading wildcard and prefix queries. Add this filter to the index analyzer, but not the query analyzer. The standard Solr query parser will use this to reverse wildcard and prefix queries to improve performance...

How does it do that though?

Since all the tokens run through the ReversedWildcardFilterFactory, does it store all the tokens in reverse? (That seems silly to me)

Or, does it store all the tokens normally and the reversed tokens and then run through an index list roughly twice as long when querying? (Presumably that's still much faster than searching using a leading *)

Part of why I'm confused is that in the example schema.xml from Solr, they do the following:

<copyField source="*_en" dest="text_en_index"/>
<copyField source="*_en" dest="text_rev_index"/>

where text_rev_index uses a ReversedWildcardFilterFactory. If the ReversedWildcardFilterFactory stores both the forward and reversed tokens, I'm not sure why they would copy these fields to both the forward and reversed dest fields.

回答1:

From https://docs.lucidworks.com/display/lweug/Wildcard+Queries:

The Lucid query parser will detect when leading wildcards are used and invoke the reversal filter, if present in the index analyzer, to reverse the wildcard term so that it will generate the proper query term that will match the reversed terms that are stored in the index for this field.