Solr is able to achieve fast search responses because, instead of searching the text directly, it searches an index instead.
You can make search request on Solr in following ways:
Search Request Query example:
Suppose, we need to get result of all books with title ‘Java’.
Then we would need to write query as shown below:
http://localhost:8983/solr/demo/query?
q=title_t:java
fl=author_s,title_t
Here, in above example ‘fl’ is used specify which fields should be returned from documents matching the query.
We should see a result like the following:
{“response”:{“numFound”:2,”start”:0,”docs”:[
{
"title_t":"The Java Book",
"author_s":"Abc"},
{
"title_t":"Java Black Ook",
"author_s":"Def"}]
}}
Solr Search Request in JSON:
If you prefer using JSON to search the index, you can use the JSON Request API:
$ curl http:
//localhost:8983/solr/demo/query -d '
{
"query"
:
"title_t:java"
,
"fields"
: [
"title_t"
,
"author_s"
]
}'
q=*:*&
fq=publisher_s:Abc& // filter query based on publisher
rows=3&
sort=pubyear_i desc& //sorts the “pubyear_i” field in descending
fl=title_t,pubyear_i’
{
“pubyear_i”:1999,
“title_t”:["Abc"]},
{
“pubyear_i”:1996,
“title_t”:["Def"]},
{
“pubyear_i”:1992,
“title_t”:["Fgh"]}]
}