Customizing the order of search results

Aug 02, 2013


Suppose you have a group of nodes/pages on your site for e.g. FAQs, Case Studies and you want to provide a feature so that visitors can search for that content.  You also want to give higher weightage to some properties/field values of the node/page.  For e.g. if the search term occurs in the title then show that result first.

The following are the configuration steps to achieve this.

1. Update \crx-quickstart\repository\workspaces\crx.default\workspace.xml and add the line below (bolded)

Code:

<SearchIndex class="com.day.crx.query.lucene.LuceneHandler"> <param name="path" value="${wsp.home}/index"/> <param name="resultFetchSize" value="50"/> <param name="indexingConfiguration" value="${wsp.home}/indexing_config.xml"/> </SearchIndex>

2. Create the file /crx-quickstart/repository/workspaces/crx.default/indexing_config.xml and copy the content from this link http://helpx.adobe.com/experience-manager/kb/SearchIndexingConfig.html

3. Include the following lines in the above the file. Change the condition and properties as per your need.

<index-rule nodeType="nt:unstructured" condition="@sling:resourceType = 'app1/components/faq'"> <property boost="3.0">question</property> <property >answer</property> <property >sling:resourceType</property> </index-rule>

4. Re-index the repository.

Delete the following in the directory /crx-quickstart/repository/workspaces/crx.default/

/index/

/index_xxx.tar

5. Now write your query and use fulltext search on the relevant properties that you are searching.

Sample Query:

path=/content/xxx/FAQs/jcr:content/ type=nt:unstructured 1_property=sling:resourceType 1_property.value=app1/components/faq group.p.or=true group.1_fulltext=My_Search_String group.1_fulltext.relPath=@question group.2_fulltext= My_Search_String group.2_fulltext.relPath=@answer

References:

How to debug JCR Queries

How to use ‘Boosts’ at Indexing Time and at Query Runtime

Indexing Configuration

If you would like more help optimizing or managing your AEM Contact Us Today.

ABOUT TECHASPECT

TechAspect is an innovative digital transformation agency, specializing in delivering the digital experience, commerce, and marketing solutions. For nearly two decades, we have been helping traditional businesses transform and create dynamic digital cultures through disruptive strategies and agile deployment of innovative solutions.