Basic Search

Please see the below basic SOLR search examples for your reference:

Simple Search

Requested URL

http://localhost:8983/solr/films/select?q=day&row=20&wt=json&indent=true

Parameters Values Details
q day Text for searching
wt json Return results format, it can be json / xml / python / ruby / php / csv
row 20 Optional. By default = 10

Returning no of rows

 

Search with Specified Field

Requested URL

http://localhost:8983/solr/films/select?q=name:Harry&wt=json&indent=true

Parameters Values Details
q name:Harry Text for searching

 

Wildcard Search

Requested URL

http://localhost:8983/solr/films/select?q=name:ha*&wt=json&indent=true

http://localhost:8983/solr/films/select?q=name:*ha&wt=json&indent=true

http://localhost:8983/solr/films/select?q=name:ha*er&wt=json&indent=true

Parameters Values Details
q ha*

*ha

Ha*er

* is the wildcard character

 

You can place wildcard anywhere in the query string such as the above examples.

 

Order By

Requested URL

http://localhost:8983/solr/films/select?q=*:*&sort=initial_release_date+asc&wt=json&indent=true

http://localhost:8983/solr/films/select?q=*:*&sort=initial_release_date+asc,id+desc&wt=json&indent=true

Parameters Values Details
sort initial_release_date+asc

 

initial_release_date+asc,id+desc

Sorting by which field, you need to add:

asc – ascending

desc – descending

 

It can be sorted by multiple fields as well.

 

However, if the field is multiple values, it will not be supported for sorting.

 

Return Certain Field(s)

Requested URL

http://localhost:8983/solr/films/select?q=*:*&fl=name,directed_by&wt=json&indent=true

Parameters Values Details
fl name,directed_by You can specify which field(s) to be returned from the query

 

Search with AND Condition

Requested URL

http://localhost:8983/solr/films/select?q=name:boy+AND+name:girl&wt=json&indent=true

http://localhost:8983/solr/films/select?q=name:ring+AND+genre:Drama&wt=json&indent=true

http://localhost:8983/solr/films/select?q=name:ring&fq=genre:Drama&wt=json&indent=true

http://localhost:8983/solr/films/select?q=*:*&fq=genre:Drama&fq=name:ring&wt=json&indent=true

Parameters Values Details
q name:boy+AND+name:girl

name:ring+AND+genre:Drama

You can have more than one “AND” for your request
fq fq=genre:Drama

fq=genre:Drama&fq=name:ring

You can also :

1.       use q and fq to define “AND” condition

2.       or use 2 fq to define “AND” condition

 

Search with OR Condition

Requested URL

http://localhost:8983/solr/films/select?q=name:day+OR+name:ring&wt=json&indent=true

http://localhost:8983/solr/films/select?q=name:day+OR+genre:Drama&wt=json&indent=true

Parameters Values Details
q  

name:day+OR+name:ring

name:day+OR+genre:Drama

Return articles:

–          where name=“day” OR name=”ring”

–          where name=“day” OR genre=“Drama”

 

Search with NOT Condition

Requested URL

http://localhost:8983/solr/films/select?q=NOT(name:day)&wt=json&indent=true

http://localhost:8983/solr/films/select?q=NOT(genre:Drama)&wt=json&indent=true

Parameters Values Details
q  

NOT(name:day)

NOT(genre:Drama)

Return articles:

–          where name <> “day”

–          where genre <> “Drama”

 

Search with Integer Range

Requested URL

http://localhost:8983/solr/films/select?q=_version_:[0+TO+1600000000000000000]&wt=json&indent=true

Parameters Values Details
q _version_:[0+TO+1600000000000000000] Return articles where _version_ between 0 and 1600000000000000000

 

Search with Date Range

Requested URL

http://localhost:8983/solr/films/select?q=initial_release_date:[2001-01-01T16:00:00Z+TO+2002-01-02T16:00:00Z]&wt=json&indent=true

Parameters Values Details
q initial_release_date:[2001-01-01T16:00:00Z+TO+2002-01-02T16:00:00Z] Return articles where initial_release_date between 2001-01-01T16:00:00Z and 2002-01-02T16:00:00Z

 

Group By

Requested URL

http://localhost:8983/solr/films/select?q=*:*&group=true&group.field=initial_release_date&wt=json&indent=true

Parameters Values Details
group true Turn on grouping function
group.field initial_release_date Return number of article(s) group by initial_release_date

 

Please rate this