5

I just got started looking at using Solr as my search web service. I don't know whether Solr supports these query types:

  • Startswith
  • Exact Match
  • Contain
  • Doesn't Contain
  • In the range

Could anyone guide me how to implement those features in Solr?

Cheers, Samnang

Yuval F
  • 20,565
  • 5
  • 44
  • 69
Samnang
  • 5,536
  • 6
  • 35
  • 47

1 Answers1

8

Solr is capable of all those things but to adequately explain how to do each of time an answer would become a mini-manual for Solr.

I'd suggest you read the actual manual and tutorials linked from the Solr homepage.

In short though:

Startswith can be implemented using Lucene wildcards.

Exact matches will only be found if a field is not tokanized. I.e. the entire field is viewed as a single token.

Contain is the default search format. I.e. a search for "John" will find any document's whose search field contains the value "John". Prefixing with - (e.g. "-John" will only find documents that do not contain John).

Ranges (be they date or integer) are possible and quite powerful, example date:[* TO NOW] would find any document whose date is not in the future.

Kris
  • 14,426
  • 7
  • 55
  • 65
  • The "contain" solution described here only works for single words, not sub-phrases. E.g. "John" within "John Smith" will work, "John Smith" within "My name is John Smith" will not. – mils May 26 '16 at 08:02