Querying the Solr API: Search Parameters Explained

Solr API

Every Opensolr Index answers searches at its own /select URL. The hosted search page, the chat bot and the Drupal and WordPress plugins use it, and your own code can use it too. This page covers the request and its search parameters; the pages linked at the end cover each feature: hybrid search, highlighting, faceting, pagination, sorting and spellcheck.

01 · The request

Send a GET or a POST to the /select URL of your index. YOUR_INDEX_HOST is the host shown in the Control Panel of the index. Every request carries the username and password of the index (HTTP Basic Authentication).

curl -u "opensolr:YOUR_API_KEY" "https://YOUR_INDEX_HOST/solr/YOUR_INDEX/select" \
  --data-urlencode "q=solar panels" \
  --data-urlencode "fl=id,uri,title,description,score" \
  --data-urlencode "rows=10" \
  --data-urlencode "wt=json"
Keep the API key and the password of the index on your server. A web page shows its JavaScript to every visitor, and the password of a new index is your API key: the username and password of your index.

02 · Copy the request of your search page

The hosted search page of your index, https://search.opensolr.com/YOUR_INDEX, shows the exact request it sent for every search:

01

Run a search on the page.

02

Click { } Debug in the bottom left corner. The Query Inspector opens with every parameter and its value.

03

Click Copy Params to copy them all.

Start from these: they already carry the Search Tuning of your index (field weights, minimum match, search mode).

03 · The parameters that matter

ParameterWhat it doesExample
qWhat to search for. With the hybrid parser it holds the hybrid query.q=solar panels
fqA filter: keeps only the documents that match, does not change the ranking, and is cached by Solr. Several fq must all match.fq=content_type:text*
flThe fields to send back. Ask only for what you show.fl=id,uri,title,score
rows, startHow many results, and from which position.rows=10&start=20
sortAn order other than relevance.sort=creation_date desc
wtThe format of the answer.wt=json

04 · Filters you will use

fq=content_type:text*                    web pages only (the Web tab of the hosted page)
fq=-content_type:text*                   documents only: PDF, Word, Excel... (the Documents tab)
fq={!term f=meta_detected_language}en    one language
fq={!term f=meta_domain}example.com      one site, when the index holds several
fq=creation_date:[NOW-7DAYS TO *]        published in the last 7 days
fq=-uri_s:*/tag/*                        leave out every address containing /tag/

The {!term} form takes the value exactly as written, so a value your page received from a facet can go straight into the filter.

05 · Filters on every search

To leave pages out of every search without changing your code, add the filter to search.xml in the Configuration tab of your index, in the appends list of the /select handler. Saving the file reloads the index, and the filter applies to every search from then on, the hosted search page included.

<lst name="appends">
    <str name="fq">-uri_s:*/tag/*</str>
    <str name="fq">-uri_s:*/cart*</str>
</lst>

To keep a page out of the index itself, use the rules of the crawl instead: rules per site.

06 · Next

Hybrid search parameters

The {!hybrid} parser: words and meaning in one request.

Highlighting

Snippets with the searched words marked.

The JSON response

What each part of the answer holds.

Facets

Counts per value and filters.

Pagination

rows, start and cursorMark.

Sorting

By date, price or any field.

Fresh results

Lift newer documents.

Autocomplete

Suggestions while typing.

Did you mean

Spelling corrections.

Code examples

PHP, Node.js, Python and curl.

No Solr request to build at all: search from your own code with one API call that embeds and searches.