Solr Query with LIKE Clause

后端 未结 2 1660
旧时难觅i
旧时难觅i 2021-02-15 01:44

I\'m working with Solr and I\'d like to know if it is possible to have a LIKE clause in the query. For example, I want to know all organizations with \"New York\" in the title.

相关标签:
2条回答
  • 2021-02-15 02:12

    If you're using solr 3.1 or newer, have a look at the Extended DisMax Query Parser, which supports wildcard queries. You can enable it using <str name="defType">edismax</str> in the request handler configuration.

    Then you can use a query like title:New York* with the same behaviour as a query with like clause. The main difference between my answer and the accepted one is that you can even search for fragment of words using wildcards. For example New Yorkers would match in this case. Unfortunately you could have problems with case-sensitive queries even if you're using a LowerCaseFilterFactory. Have a look here to know more. Most of those problems will be fixed with the solr 3.6 release since the SOLR-2438 issue has been solved.

    0 讨论(0)
  • 2021-02-15 02:27

    You just search for "New York", but first you need to properly configure your field's analyzer. For example you might want to start with a field type like text_general as defined in the default Solr schema. This field type will tokenize on whitespace and other common word separators, then apply a filter of stopwords, then lowercase the terms in order to make searches case-insensitive.

    More information about analyzers in the Solr wiki.

    0 讨论(0)
提交回复
热议问题