Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Solr Query Syntax

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

like image 721
Samnang Avatar asked Jun 09 '09 06:06

Samnang


People also ask

How do I query in Solr collection?

You can search for "solr" by loading the Admin UI Query tab, enter "solr" in the q param (replacing *:* , which matches all documents), and "Execute Query". See the Searching section below for more information. To index your own data, re-run the directory indexing command pointed to your own directory of documents.

How does Solr query work?

Solr works by gathering, storing and indexing documents from different sources and making them searchable in near real-time. It follows a 3-step process that involves indexing, querying, and finally, ranking the results – all in near real-time, even though it can work with huge volumes of data.

How query all fields in Solr?

The correct way is the copyField you have and declaring the field all as the default search field. That's how the examples that ship with Solr out of the box do it. Excellent, adding <str name="df">all</str> to defaults in solrconfig. xml indeed solved this.


1 Answers

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.

like image 144
Kris Avatar answered Sep 22 '22 19:09

Kris