Querying the Solr API: Search Parameters Explained
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"
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:
Run a search on the page.
Click { } Debug in the bottom left corner. The Query Inspector opens with every parameter and its value.
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
| Parameter | What it does | Example |
|---|---|---|
q | What to search for. With the hybrid parser it holds the hybrid query. | q=solar panels |
fq | A 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* |
fl | The fields to send back. Ask only for what you show. | fl=id,uri,title,score |
rows, start | How many results, and from which position. | rows=10&start=20 |
sort | An order other than relevance. | sort=creation_date desc |
wt | The 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
The {!hybrid} parser: words and meaning in one request.
Snippets with the searched words marked.
What each part of the answer holds.
Counts per value and filters.
rows, start and cursorMark.
By date, price or any field.
Lift newer documents.
Suggestions while typing.
Spelling corrections.
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.