Solr Query with LIKE Clause

Mark Meisel picture Mark Meisel · Jan 17, 2012 · Viewed 29.2k times · Source

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. In SQL, this would be written like Name LIKE 'New York%'.

My question - how do you write a LIKE query in Solr?

I'm using the SolrNet library, if that makes a difference.

Answer

Mauricio Scheffer picture Mauricio Scheffer · Jan 17, 2012

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.