question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is custom sorting on search not supported?

See original GitHub issue

The Custom sort seems to only sort the results.

I have 10,000 documents indexed and I search with a limit of 10 and those 10 are now sorted according to popularity. I’m doing:

const indexResults = this.index.search({
  query: q,
  field: "title",
  limit: 10,
  sort: (a, b) => b.popularity - a.popularity,
  suggest: true
});

But it still seems to sort on “matchness” (or “relevance”) and NOT on my popularity.

What I want, when I type wa that the document that contains a wa anywhere and has the highest popularity should appear first. If there are, 10,000 documents and 1,000 that technically match wa I want those 1,000 to be sorted by popularity.

(PS. I tried using sort: "popularity" but that sorted the results the wrong direction and doing sort: "-popularity" didn’t work)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
peterbecommented, Nov 14, 2019

Actually. I tried that. It works really well! Here’s what I did:

-    Object.entries(titles).forEach(([uri, title]) => {
-      this.index.add(uri, title);
-    });
+    Object.entries(titles)
+      .sort((a, b) => b[1].popularity - a[1].popularity)
+      .forEach(([uri, info]) => {
+        this.index.add(uri, info.title);
+      });

Doing a couple of searches this way seems to produce pretty good results. At least good enough that I’m no longer blocked and can continue to use FlexSearch.

0reactions
ts-thomascommented, Nov 14, 2019

Yeah nice idea. It works when the results have the same relevance. If not the relevance gets prioritize over the sort. But you can control relevance. Relevance isn’t a float value, it is an integer. You can control the “resolution” of how many different relevance values exist (“slots”). This way you can force to sort by an external value regardless of the relevance:

new FlexSearch({
    threshold: 0,
    resolution: 1
});

This will categorize each text to the same relevance “slot”.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom Sort not Working - Microsoft Community Hub
In the sample file the custom sort works according to the settings. The data for year 2006 is sorted in ascending order and...
Read more >
Activity Custom Lookups do not support Sort options, but they ...
When Activity Custom Lookups are turned on and add a lookup to a custom object, the resulting related list has the option to...
Read more >
Sorting and filtering is not working in google custom search ...
Q) if I use sort by attribute date-sdate and pages which doesn't have this attribute should not appear in search results right because...
Read more >
Custom Sorting option not working in Magetno 2.4 search
When i select the Newest filter it shows the message No Result Found. Any one tell me what is the issue or any...
Read more >
Log sorting - Custom sorting is not working - Stack Overflow
It's not a sorted array, so that you can just go from one element to the one with the lesser priority.The Iterator provided...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found