Another very common case is when we have to sort the results. This is very simple to obtain using a specific sort parameter. For example, to obtain the results ordered by artist
in a descending order (so that we have the last ordered artist in the first position), and in particular to produce a document result list containing only the fields uri
and sameAs
(that represents the uri pointing to the same resource on another repository).
>> curl -X GET 'http://localhost:8983/solr/paintings/select?q=*:*&start=0&rows=200&sort=artist desc&fl=sameAs,uri&wt=json&indent=true'
The sort
parameter needs a very simple syntax, as you have seen in the previous example. It needs the name of the field on which we want to sort, and the type of sorting. Here, asc
is used for ascending order and desc
for descending order. It is important to remember that we can append a new sort definition for every field on which we want to sort (we could combine them as we need). Moreover sorting makes sense only on single valued field, not on multivalued ones.
Sorting should be used only when strictly necessary. Please be aware of the impact of sorting operations in terms of memory consumptions, refreshing of cache, and garbage collector invocations.
One of the typical usage for function query (for more information in function query visit http://wiki.apache.org/solr/FunctionQuery) is sorting. We could sort a collection over a value calculated by a specific function query (similar to using pseudo-fields).
A RequestHandler
is a component used to expose a new service. It is designed to receive a specific type of query. This way, it's also possible to define two different services with the same component, changing only the parameters values or the list of parameters they are designed to parse. The list of the possible handlers is on the wiki at http://wiki.apache.org/solr/SolrRequestHandler. The update components are already enabled by default. So, we can post the data to be indexed using CSV, json, or XML, as we have already seen. Other components are designed to be used for advanced query capabilities that we will see in the Looking at different search parsers – Lucene, Dismax and Edismax and Introducing the spellcheck components section of Chapter 5, Extending Search, and in Chapter 6, Using Faceted Search – from Searching to Finding. The DataImportHandler
will be used in Chapter 8, Indexing External Data Sources, for acquiring external data.
Remember that we can switch among different handlers using the qt
parameter, and when we have not defined any handler's name, we are actually using the default one (/select/
on StandardRequestHandler
). In the next example, we will create a new endpoint using some specific configuration on StandardRequesHandler
.
3.144.19.243