Divya-S1
New Creator

Search G2 Sorting

Hello Everyone,

Anyone please suggested the inputs for Search G2 string sorting. I have tried this but didn't helped us "sort=custom_s_heading(home,max)%20desc"

We have a requirement of sorting based on number of occurrence of string value in the search G2 result. 

Search: Plumbing – will try to find how many times plumbing is available in “custom_s_heading”  and sort it based on the number of occurrence. Then find the same in “content” and sort and display.

For example: below are some values of “custom_s_heading”,

Sentence 1: My name is plumbing

Sentence 2: Plumbing can be done with those who knows plumbing works. Plumbing is an easy job.

Sentence 3: My plumbing work is in progress. Plumbing is good.

Since the 2nd sentence is having plumbing 3 times, it will return as first item from the search G2 result followed by sentence 3(2 times word plumbing used) and sentence 1(only 1 time word plumbing used).

0 Kudos
1 Reply
EdwardChan
Crownpeak Employee

Perhaps you could try something like the following:

https://searchg2.crownpeak.net/<collection_name>/select/?q=a&fl=custom_t_heading,termfreq(custom_t_heading,a)&qf=custom_t_heading&defType=edismax&rows=320&sort=termfreq(custom_t_heading,a)%20desc
https://searchg2.crownpeak.net/<collection_name>/select/?q=the&fl=custom_t_heading,termfreq(custom_t...

Parameters Used:

qf = fields to query (eg. query fields applies to the q= parameter)

fl = field list to display

For the sort= querystring value we are using the termfreq() function. The first parameter of this function is the field to use and the second parameter is the term to count. 

In the examples above, we are searching for the word 'a' or 'the' within the custom_t_heading field and then sorting in ascending or descending order the number of times these words show up in the field. 

 

--


Edward Chan
Sr Product Consultant

## If I’ve helped, accept this response as a solution so that other’s can find is more quickly in the future.
## Have thoughts on Crownpeak products? We'd love to hear them. Speak with the Crownpeak Product Team..

0 Kudos