Bug 23875 - Elasticsearch - ES - When sorting by score we should provide a tiebreaker
Summary: Elasticsearch - ES - When sorting by score we should provide a tiebreaker
Status: Signed Off
Alias: None
Product: Koha
Classification: Unclassified
Component: Searching - Elasticsearch (show other bugs)
Version: master
Hardware: All All
: P5 - low normal (vote)
Assignee: Nick Clemens
QA Contact:
URL:
Keywords:
Depends on: 23089
Blocks:
  Show dependency treegraph
 
Reported: 2019-10-22 14:39 UTC by Nick Clemens
Modified: 2020-03-11 14:10 UTC (History)
7 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Trivial patch
Who signed the patch off:
Text to go in the release notes:
Version(s) released in:


Attachments
Bug 23875: Explicitly srt searches by score and provide local-number as tie breaker (3.04 KB, patch)
2019-10-22 14:43 UTC, Nick Clemens
Details | Diff | Splinter Review
Bug 23875: Explicitly srt searches by score and provide local-number as tie breaker (3.08 KB, patch)
2019-10-25 06:35 UTC, Ere Maijala (away 16Mar-10May)
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Nick Clemens 2019-10-22 14:39:21 UTC
In ES if we sort by 'relevance' we actually don't pass anything to ES and results are ordered by score.

When doing a search limiting only by collection or type, the scores are all the same. This is fine, except that editing any record will then cause a reordering of the results, even though it won't affect the score.

We should provide a tie-breaker in the case of equal sort scores
Comment 1 Nick Clemens 2019-10-22 14:43:08 UTC
Created attachment 94579 [details] [review]
Bug 23875: Explicitly srt searches by score and provide local-number as tie breaker

To test:
 1 - Set search engine to ES
 2 - Search the catalog for "*"
 3 - Note results
 4 - Edit first result
 5 - Repeat search, results are reordered
 6 - Apply patch
 7 - Search for "*"
 8 - Highest biblionumbers are returned first
 9 - Edit first result, repeat search
10 - Order does not change
11 - Confirm sorting by author, title, etc passes the same trials
Comment 2 Ere Maijala (away 16Mar-10May) 2019-10-23 14:08:43 UTC
Should we care that the sorting by local-number.raw isn't numeric?
Comment 3 Nick Clemens 2019-10-24 10:23:09 UTC
(In reply to Ere Maijala from comment #2)
> Should we care that the sorting by local-number.raw isn't numeric?

In the mappings local-number is set as a string by default - should we change it to a number? I think in practice it will be a number, however, under ES at least I don't see why someone couldn't map local-number to 001 and manage their own control numbers with letters, so maybe string is okay as long as your numbers are built consistently?
Comment 4 Ere Maijala (away 16Mar-10May) 2019-10-25 06:35:15 UTC
Created attachment 94712 [details] [review]
Bug 23875: Explicitly srt searches by score and provide local-number as tie breaker

To test:
 1 - Set search engine to ES
 2 - Search the catalog for "*"
 3 - Note results
 4 - Edit first result
 5 - Repeat search, results are reordered
 6 - Apply patch
 7 - Search for "*"
 8 - Highest biblionumbers are returned first
 9 - Edit first result, repeat search
10 - Order does not change
11 - Confirm sorting by author, title, etc passes the same trials

Signed-off-by: Ere Maijala <ere.maijala@helsinki.fi>
Comment 5 Ere Maijala (away 16Mar-10May) 2019-10-25 06:41:14 UTC
(In reply to Nick Clemens from comment #3)
> In the mappings local-number is set as a string by default - should we
> change it to a number? I think in practice it will be a number, however,
> under ES at least I don't see why someone couldn't map local-number to 001
> and manage their own control numbers with letters, so maybe string is okay
> as long as your numbers are built consistently?

Changing it to number would be scary, and I don't think this is really an issue. If we want to make sorting consistent, we could always left-pad the biblionumber with zeros, but I don't really like it since it wouldn't match the biblionumber field in MARC exactly. Alternatively we could have a hardcoded mapping to a numeric biblionumber field. Or make the tie-breaker sort field configurable. But since local-number gives us consistent results, I believe this is good enough for all practical purposes.
Comment 6 Katrin Fischer 2019-10-27 14:19:10 UTC
(In reply to Ere Maijala from comment #5)
> (In reply to Nick Clemens from comment #3)
> > In the mappings local-number is set as a string by default - should we
> > change it to a number? I think in practice it will be a number, however,
> > under ES at least I don't see why someone couldn't map local-number to 001
> > and manage their own control numbers with letters, so maybe string is okay
> > as long as your numbers are built consistently?
> 
> Changing it to number would be scary, and I don't think this is really an
> issue. If we want to make sorting consistent, we could always left-pad the
> biblionumber with zeros, but I don't really like it since it wouldn't match
> the biblionumber field in MARC exactly. Alternatively we could have a
> hardcoded mapping to a numeric biblionumber field. Or make the tie-breaker
> sort field configurable. But since local-number gives us consistent results,
> I believe this is good enough for all practical purposes.

I am not sure if I understand the issue compeletely, but why would local-number be scary as a number? local-number is usually the biblionumber, right? And if it is, I am in doubt about what Nick says that you could just remap it to 001 - at least I would expect issues with that.

I think being able to sort numerical on biblionumber is important so you can use it as a tie breaker as mentioned before, when all other criteria are the some. You you can sort from newer to older.

If we don't sort numerical... that meanst 9 999 2 22 1 11 ... something like that?
Comment 7 Ere Maijala (away 16Mar-10May) 2019-10-28 07:12:58 UTC
(In reply to Katrin Fischer from comment #6)
> I am not sure if I understand the issue compeletely, but why would
> local-number be scary as a number? local-number is usually the biblionumber,
> right? And if it is, I am in doubt about what Nick says that you could just
> remap it to 001 - at least I would expect issues with that.

Yes, it's usually biblionumber, but there's nothing preventing one from e.g. adding other fields in it too. Unless we hard-code a field for biblionumber, we can't positively say it's always a number.

> If we don't sort numerical... that meanst 9 999 2 22 1 11 ... something like
> that?

Yes.
Comment 8 Katrin Fischer 2019-10-28 07:15:03 UTC
(In reply to Ere Maijala from comment #7)
> (In reply to Katrin Fischer from comment #6)
> > I am not sure if I understand the issue compeletely, but why would
> > local-number be scary as a number? local-number is usually the biblionumber,
> > right? And if it is, I am in doubt about what Nick says that you could just
> > remap it to 001 - at least I would expect issues with that.
> 
> Yes, it's usually biblionumber, but there's nothing preventing one from e.g.
> adding other fields in it too. Unless we hard-code a field for biblionumber,
> we can't positively say it's always a number.
> 
> > If we don't sort numerical... that meanst 9 999 2 22 1 11 ... something like
> > that?
> 
> Yes.

Maybe we should have an unchangeable index for biblionumber then? The sorting could quickly become an issue. People tend to search very 'broadly' and then the tie breaker would come in quickly. At least that's what we see with Zebra quite often with searches for single words and similar.
Comment 9 Ere Maijala (away 16Mar-10May) 2019-10-28 07:19:03 UTC
(In reply to Katrin Fischer from comment #8)
> Maybe we should have an unchangeable index for biblionumber then? The
> sorting could quickly become an issue. People tend to search very 'broadly'
> and then the tie breaker would come in quickly. At least that's what we see
> with Zebra quite often with searches for single words and similar.

Using non-numeric sort doesn't really matter for tie-breaker unless you care for the order. I'd actually like us to have a hard-coded biblionumber index field. One could also argue that biblionumber should only be the last resort, and publication date should be the primary. We'll probably end up making it configurable. ;)
Comment 10 Katrin Fischer 2019-10-28 07:25:16 UTC
And by the reasoning that we can't prevent other fields being added... doesn't that apply to all other indexes as well? Would Elastic give you an error when searching on a string in a numerical index or just not sort them 'right'?(In reply to Ere Maijala from comment #9)
> (In reply to Katrin Fischer from comment #8)
> > Maybe we should have an unchangeable index for biblionumber then? The
> > sorting could quickly become an issue. People tend to search very 'broadly'
> > and then the tie breaker would come in quickly. At least that's what we see
> > with Zebra quite often with searches for single words and similar.
> 
> Using non-numeric sort doesn't really matter for tie-breaker unless you care
> for the order. I'd actually like us to have a hard-coded biblionumber index
> field. One could also argue that biblionumber should only be the last
> resort, and publication date should be the primary. We'll probably end up
> making it configurable. ;)

publication date can get quickly problematic for serials... the first date in 008 is usually quite old. Every approach has its own problems ;)

Maybe we can move the discussion of adding a hardcoded biblionumber index into another bug, but it really bugs me that the sorting of a clearly numerical value would be alphabetic... it just seems very wrong. I've ended up explaining the 'last resort' ordering a lot of times to libraries.
Comment 11 Ere Maijala (away 16Mar-10May) 2019-10-28 08:02:19 UTC
(In reply to Katrin Fischer from comment #10)
> publication date can get quickly problematic for serials... the first date
> in 008 is usually quite old. Every approach has its own problems ;)

True, and I didn't mean to imply that should be a default. :)

> Maybe we can move the discussion of adding a hardcoded biblionumber index
> into another bug, but it really bugs me that the sorting of a clearly
> numerical value would be alphabetic... it just seems very wrong. I've ended
> up explaining the 'last resort' ordering a lot of times to libraries.

I'm fine either way. But clearly at least a follow-up to this bug is needed.
Comment 12 Martin Renvoize 2020-03-11 14:10:48 UTC
Are you intending on continuing here with the requested followup Nick?

I think the suggestion was to have a fixed biblionumber index which is numeric and use that for the tie-breaker by default.. as aposed to using the existing 'local-number' index which can be re-mapped?