Search code examples
searchsolrsunspot

sunspot solr attribute substring/wildcard searches


Is it possible to search solr attribute fields (non solr.TextField types) using a substring/wildcard/partial string match?

For instance if I have a solr.StrField field and documents that contain the string "1234567890" I want to be able to search on "456" and have that document returned.

From what I can see only textfields can be searched in this method using things like EdgeNGram and the like, but not attribute fields??


Solution

  • You can have the partial matches working for String as well Text fields for wildcards.

    If the query parsers you are using, supports leading wildcard queries, you can easily search for *456*, and this should match 1234567890.

    However, EdgeNGram would only work for solr.TextField, as solr.strField do not allow analysers to be added to it.
    So you can only define fields with class as solr.TextField and have the EdgeNGram in the analysis chain, which would break down the indexed terms into shingles for partial matching.