Document filter and boost using Solr query panel
This is a basic tutorial where I use the Solr document uploader to upload content to an index. Then, I use the query panel to check how document boost works. Note that in case of this tutorial, I'm picking up a random solr index to upload documents but you need to exercise caution with regard to the index where you upload content in Sitecore. Moreover, this blog article is mainly to demo the purpose of solr document uploader and its index query capability. This will be useful to formulate your search query with necessary filter and boost options before you implement in the actual application like Sitecore or others invoking Solr search.
To build the document, it is important to build some content. This is the process to build the document structure with different fields:
Once you have the needed fields, the document submit must be successful based on the response in the right side pane:
In order to boost the document, add the following query to the q field:
Although the concerned template topped the list, the other documents are missing from the result set. So, modify the query as follows:
Next add new document for en-AU and let's boost a particular keyword in the content even within en-AU:
Scenario: Filter documents with content having "test" but bring documents with template 3333-3333 on top of the results:
Final Test Data
Pre-requisites
1. Solr instance
2. Populated Solr index names
Context
If you need a solr instance with populated indexes, just install Sitecore and index names will be automatically populated in the corresponding solr console' left-side dropdown.
For the sake of this tutorial, I'm assuming that you already have Solr indexes setup in your solr instance. So, this is how my solr admin console with populated index names looks like:
If you need a solr instance with populated indexes, just install Sitecore and index names will be automatically populated in the corresponding solr console' left-side dropdown.
Menu options
To get to the query pane for the concerned index through UI:
https://localhost:8901/solr/#/sc102abc_core_index/query
1. Select the solr index from the dropdown
2. Click the auto-loaded Query menu option
At this point, when you press the Execute Query button, there are no results in the right pane since there are no documents uploaded as of now.
In order to upload some documents, click Documents in left menu and documents for the index can be uploaded here:
1. Select Document Builder option in Document type
2. Field gets auto-populated
To build the document, it is important to build some content. This is the process to build the document structure with different fields:
1. Select Field
2. Add field data
3. Add the field and field data to the data structure
Document is missing mandatory uniqueKey field: _uniqueid
Once you have the needed fields, the document submit must be successful based on the response in the right side pane:
Now, switch to the query pane and check if this document is present and retrieved from the corresponding solr index:
{
"_datasource": "d2",
"_uniqueid": "2",
"_content": "My test content for solr testing",
"_template": "2222-2222",
"_language": "en-US"
},
{
"_datasource": "d2",
"_uniqueid": "3",
"_content": " Unrelated content",
"_template": "2222-2222",
"_language": "en-AU"
},
{
"_datasource": "d2",
"_uniqueid": "4",
"_content": "My third test content for solr testing",
"_template": "3333-3333",
"_language": "en-AU"
}
Check if the documents are retrieved successfully through the query pane:
Query Boost in action
Now, with four documents setup and the results displaying all four, let's boost the document with template 3333-3333 and bring it on top of the search result:
_template:3333-3333
Although the concerned template topped the list, the other documents are missing from the result set. So, modify the query as follows:
_template:3333-3333 _content:*
Now, let's amp this up and upload another document with language en-GB as follows:
{
"_datasource":
"d2",
"_uniqueid":
"5",
"_content":
"My fourth test content for solr testing",
"_template":
"3333-3333",
"_language":
"en-GB"
For the same query, this is how the search results look after the upload:
_content:* _template:3333-3333 _language:en-GB
Next add new document for en-AU and let's boost a particular keyword in the content even within en-AU:
{
"_datasource": "d2",
"_uniqueid": "6",
"_content": " Latest data",
"_template": "3333-3333",
"_language": "en-AU"
}
Filter in action
Scenario: Filter documents with content having "test"
In this case, fq will hold filter query based on the search text - "test" and q will not be adjusted since no need for boosting.
Scenario: Filter documents with content having "test" but bring documents with template 3333-3333 on top of the results:
q
_template:3333-3333 _content:*
fq
_content:test
Filter with Boost
Scenario: Filter documents with content having "test" but bring documents with template 3333-3333 on top of the results, furthermore, boost en-GB over en-AU
q
_template:3333-3333 _content:* _language:en-GB
fq
_content:test
Scenario: For the same situation as previous, but boost one template (2222-2222) over another template (3333-3333)
q
_template:3333-3333 _template:2222-2222^2 _content:*
fq
_content:test
Result:
This way, the query panel is useful to test both query filtering as well as query boosting.
Comments
Post a Comment