Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Solr query starts with

Tags:

solr

How I write a query in Solr that performs "start with" function? For example, if I have 3 documents with the following title fields:

  1. "Star Wars Episode I"
  2. "Star Wars Episode II"
  3. "Star Trek"
  4. "My Star Wars movie"

I want the query to return first 2 documents, whose title starts with "Star Wars"

Edit: For the record, this is what I end up using:

fq=(name:"/Apple Ipad.*/")&wt=xml
like image 830
sean717 Avatar asked Dec 04 '22 01:12

sean717


1 Answers

Define '^' as the first character of a search phrase meaning "Starts With".

Define '$' as the last character of a search phrase meaning "Ends With".

Pre-parse your search phrase, substituting '^' and '$' appropriately.

You can use regular expressions

https://web.archive.org/web/20161030170947/http://www.openjems.com/solr-regex-tutorial/

like image 90
Oyeme Avatar answered Feb 09 '23 01:02

Oyeme