Function Queries

DSE Version: 6.0

Video

Transcript: 

Hi, I'm Joe Chu and welcome to function queries.

In this video we will be talking about some different parsers that allows a user to manipulate document scores using prebuilt functions. They can be used in conjunction with the major query parsers, such as the standard parser, dismax, and edismax parsers and can be added to the q, fq, and sort parameters in a search query. While the functions can be used to replace the score of a document, please be aware that it is not possible to return the result of a function directly.

There are two function parsers that we will be describing in this video. The function query parser and the function range query parser.

The function query parser works by specifying the func parser and providing a function query, in lieu of a search query. The function query will then run on all of the documents in the search index, with the result of the function query acting as a score for the document.

The function range query parser uses a set of bounds for the output of a function query, in addition to the relevancy score, to determine documents that are included in the search results.

Here we have an example of using the function query parser. Instead of a search query, we are using a function query that divides the value of the sum_ratings column by the num_ratings column, which essentially is generating an average rating for each document. The output of the function is the score for the document, and will determine what documents are included in the results, with the highest scores at the front.

The second example here is a JSON search query that uses the same function query, but also includes a filter query that contains a search expression. Therefore this JSON search query will only return the documents that have a num_ratings of 100, sorted by the function query. Only returning documents that have exactly a value of 100 sounds limited, which is why our next couple of examples will show how this can be done better.

In our first function range query example, the same function query is used as our previous examples, except that its uses the frange parser to determine the bounds for the function query output, which needs to be between greater than or equal to 7 and less than 9.

The second example uses the the function range query parser as a filter query to include only the documents that have a num_ratings of 20 or more.

It is also possible to use functions directly in the search query sort parameter, and gives control to determine the order direction. In the examples here, you can see our function query added to return results in either ascending or descending order.

Here are some of the common mathematical and relevancy score-related functions that are available to use with function queries. Aside from these, there are much more that can be used, which I invite you to check out. A complete list can be found in the Solr Reference Guide.

No write up.
No Exercises.
No FAQs.
No resources.
Comments are closed.