You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When doing a search throughout the documentation, the result are not ordered by relevance which makes search less efficient than it could be.
Steps to reproduce
I can't provide a demo.
I can detail my example and propose the fix that I have done on my side.
We have around 200 pages of documentation (and growing ),
I type a word, for example, "Performance",
The pages that are provided are relevant but it feels that they are not properly ordered. In the example case, I have at least two pages provided, entitled "Performance" and "Configuration".
Expected result
Both pages indeed contain the word "performance" but the dedicated page should be proposed first.
Actual result
The page titled "Configuration" is proposed before the page entitled "Performance".
From my understanding, Flexsearch is providing result in relevance order, however the flexsearch.js wrapper in @hyas/assets/js/flexSearch.js is implicitly reordering the result due to the way data are aggregating before display. The function do search is aggegrating result by there index in a map:
The issue is that when you do Object.keys on result, the order is not relevance given by Flexsearch anymore but the id number.
If you want to aggregate on id you also need to keep the order of the document provided by Flexsearch as follow (it's a tiny bit dirty):
functionshowResults(items,order){consttemplate=document.querySelector('template').content;constfragment=document.createDocumentFragment();constresults=document.querySelector('.search-results');results.textContent='';constitemsLength=Object.keys(items).length;// Show/hide "No recent searches" and "No search results" messagesif((itemsLength===0)&&(query.value==='')){// Hide "No search results" messagedocument.querySelector('.search-no-results').classList.add('d-none');// Show "No recent searches" messagedocument.querySelector('.search-no-recent').classList.remove('d-none');}elseif((itemsLength===0)&&(query.value!=='')){// Hide "No recent searches" messagedocument.querySelector('.search-no-recent').classList.add('d-none');// Show "No search results" messageconstqueryNoResults=document.querySelector('.query-no-results');queryNoResults.innerText=query.value;document.querySelector('.search-no-results').classList.remove('d-none');}else{// Hide both "No recent searches" and "No search results" messagesdocument.querySelector('.search-no-recent').classList.add('d-none');document.querySelector('.search-no-results').classList.add('d-none');}order.forEach((id)=>{constitem=items[id];constresult=template.cloneNode(true);consta=result.querySelector('a');consttime=result.querySelector('time');constcontent=result.querySelector('.content');a.innerHTML=item.title;a.href=item.permalink;time.innerText="";content.innerHTML=item.summary;fragment.appendChild(result);});results.appendChild(fragment);}functiondoSearch(){constquery=document.querySelector('.search-text').value.trim();constlimit={{.searchLimit }};constresults=index.search({query: query,enrich: true,limit: limit,});constitems={};constorder=[];results.forEach(function(result){result.result.forEach(function(r){if(!order.includes(r.id)){order.push(r.id);}items[r.id]=r.doc;});});showResults(items,order);}
The result, feels more relevant that way, on our case. "Performance" page was proposed first other felt much more relevant.
Don't hesitate to tell me, if I miss something or got something wrong.
The text was updated successfully, but these errors were encountered:
Description
When doing a search throughout the documentation, the result are not ordered by relevance which makes search less efficient than it could be.
Steps to reproduce
I can't provide a demo.
I can detail my example and propose the fix that I have done on my side.
Expected result
Both pages indeed contain the word "performance" but the dedicated page should be proposed first.
Actual result
The page titled "Configuration" is proposed before the page entitled "Performance".
Environment
Proposed fix:
From my understanding, Flexsearch is providing result in relevance order, however the
flexsearch.js
wrapper in@hyas/assets/js/flexSearch.js
is implicitly reordering the result due to the way data are aggregating before display. The function do search is aggegrating result by there index in a map:The issue is that when you do Object.keys on result, the order is not relevance given by Flexsearch anymore but the id number.
If you want to aggregate on id you also need to keep the order of the document provided by Flexsearch as follow (it's a tiny bit dirty):
The result, feels more relevant that way, on our case. "Performance" page was proposed first other felt much more relevant.
Don't hesitate to tell me, if I miss something or got something wrong.
The text was updated successfully, but these errors were encountered: