* [bug#73220] [PATCH] ui: Add more nuance to relevance scoring. @ 2024-09-13 7:02 aurtzy 2024-09-13 14:12 ` Simon Tournier 2024-09-13 14:24 ` [bug#73220] [PATCH v2] ui: Add partial match " Simon Tournier 0 siblings, 2 replies; 4+ messages in thread From: aurtzy @ 2024-09-13 7:02 UTC (permalink / raw) To: 73220 Cc: aurtzy, Christopher Baines, Josselin Poiret, Ludovic Courtès, Mathieu Othacehe, Simon Tournier, Tobias Geerinckx-Rice Fixes <https://issues.guix.gnu.org/70689>. * guix/ui.scm (char-set:word-border): New variable. (relevance): Update docstring. [whole-word-score, exact-match-score]: New variables. [score]: Score whole words such that matching a whole word will always put an object higher than another if the other does not match any whole words. Exact matches are given similar treatment. Score matches slightly higher than the baseline if they have one word boundary, with the assumption that they are more likely to be part of compound words rather than simply substrings. Only count a maximum of one scored match per field to limit putting too much weight on terms that happen to be very common. [score][string-ref-border?]: New procedure. Change-Id: I8e3d7a20bf296485355d1c191fe3fee5ef6490c8 --- Hello! This is an attempt to improve guix's search functionality for cases like the linked issue. Elaborating on some parts of my implementation: I opted to switch to counting a maximum of one match per field, which helps with cases where a common subword matches /many/ times in packages with longer descriptions, pushing more relevant packages down. In multi-term searches, the unique terms - which are naturally rarer - also contribute to a larger percentage of the score as a result of these changes. Having matches with only one word boundary be scored as 2 instead of 1 was done with the reasoning that a term is more likely to be part of a compound word name (and thus more relevant) if it is a prefix or suffix; for example, "gl" in OpenGL, "borg" in borgmatic, and "tor" in torbrowser. In an effort to minimize regressions in scoring, I've compiled a set of test cases and their expected results, which - if useful - might also be usable in future work: | Keyword(s) with poor | Expectations | | results before | | |-----------------------+-----------------------------------------------| | dig | ~bind~ near top. | | rsh | ~inetutils~ near top. | | c | C language related. | | c compiler | Compiler-related C stuff. | | r | R language related. | | tor | Tor related; ~torbrowser~ somewhere near top. | | gcc | ~gcc-toolchain~ near top. | |-----------------------+-----------------------------------------------| | Keyword(s) with mixed | | | results before | | |-----------------------+-----------------------------------------------| | gl | GL related. | | sh | Shell-related. | |-----------------------+-----------------------------------------------| | Keywords(s) with good | | | results before | | |-----------------------+-----------------------------------------------| | gcc toolchain | ~gcc-toolchain~ near top. | | python | ~python~ at top. | | python language | ~python~ at top. | | python minimal | ~python{,2}-minimal~ and friends near top. | | sync files | File synchronization related. | | sdl2 | ~sdl2~ at top. | However, some of these cases might be a bit too abstract, so I'm not sure how sufficient this testing is. Note that I only did minimal testing with =guix system search= and =guix home search= which - while seemingly fine - could be more rigorous (am I forgetting any other commands?). Going over the results of these changes on the test cases: There were notable improvements searching: - =rsh=: ~inetutils~ now shows up at the top when searching =rsh=, with another relevant (but previously buried) ~emacs-tramp~ at second place. - =c=: Searches for =c= return results related to the language now, whereas before it was a lot of unrelated packages that simply had the most =c= characters. - =dig=: While not the first result, ~bind~ is now displayed as tied for 3rd in relevance score, showing up within 10 packages. - =r=: Previously in a similar situation as C. Now ~r~ shows up at the top, with other R-related packages under it. - =gl=: The =gl= test case's results are slightly improved. Before, there were some non-relevant packages with the =gl= substring near the top, which is no longer the case. - =sh=: As a common subword, searching =sh= led to a mix of relevant and less relevant results at the top. A good majority are now shell-related. - =tor=: ~tor~ shows up on the top in both cases, but before with lots of non-relevant packages under it; the previously buried ~torbrowser~ now accompanies other more relevant results near the top. - =gcc=: ~gcc-toolchain~ is now a top result, compared to ~gccgo~ at the top before (and even ~gdc-toolchain~ also being higher; upstream name being "gcc" seems to have caused that). There are slight regressions with searching: - =sync files=: The new algorithm has a few less relevant results at the top compared to before, but otherwise seems like a shuffling of the old results. - =sdl2=: ~sdl2~'s top rank is overtaken by two libraries. If I didn't mention a test case from the table, it's probably because results were at least consistent or better (and I think I've written too much to read already). Closing this message on an unrelated note for future work: I stumbled on an interesting idea while looking for test cases which suggested reducing the score of a programming library when its language is not included in search terms. It's out of scope for the current issue, but I thought I'd mention it anyways for potential further improvements. Cheers, aurtzy guix/ui.scm | 54 ++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/guix/ui.scm b/guix/ui.scm index 966f0611f6..420f1f7501 100644 --- a/guix/ui.scm +++ b/guix/ui.scm @@ -19,6 +19,7 @@ ;;; Copyright © 2018 Steve Sprang <scs@stevesprang.com> ;;; Copyright © 2022 Taiju HIGASHI <higashi@taiju.info> ;;; Copyright © 2022 Liliana Marie Prikler <liliana.prikler@gmail.com> +;;; Copyright © 2024 aurtzy <aurtzy@gmail.com> ;;; ;;; This file is part of GNU Guix. ;;; @@ -1678,22 +1679,57 @@ (define* (package->recutils p port #:optional (width (terminal-columns)) ;;; Searching. ;;; +(define char-set:word-border (char-set-union char-set:digit + char-set:punctuation + char-set:symbol + char-set:whitespace)) + (define (relevance obj regexps metrics) - "Compute a \"relevance score\" for OBJ as a function of its number of -matches of REGEXPS and accordingly to METRICS. METRICS is list of -field/weight pairs, where FIELD is a procedure that returns a string or list -of strings describing OBJ, and WEIGHT is a positive integer denoting the -weight of this field in the final score. + "Compute a \"relevance score\" for OBJ as a function of its matches of REGEXPS and +accordingly to METRICS. METRICS is list of field/weight pairs, where FIELD is a +procedure that returns a string or list of strings describing OBJ, and WEIGHT is a +positive integer denoting the weight of this field in the final score. A score of zero means that OBJ does not match any of REGEXPS. The higher the score, the more relevant OBJ is to REGEXPS." + ;; Ensure that objects with whole word matches always score greater than (or equal + ;; to) objects that only match substrings. + (define whole-word-score (apply + (map (match-lambda + ((_ . weight) weight)) + metrics))) + (define exact-match-score (* whole-word-score 2)) + (define (score regexp str) + (define (string-ref-border? k) + (if (<= 0 k (1- (string-length str))) + (char-set-contains? char-set:word-border (string-ref str k)) + #t)) + (fold-matches regexp str 0 (lambda (m score) - (+ score - (if (string=? (match:substring m) str) - 5 ;exact match - 1))))) + (cond + ((string=? (match:substring m) str) + exact-match-score) + ((>= score whole-word-score) + ;; No need to compute further if score is already max + ;; possible score + score) + (else + (let ((start-border? + (string-ref-border? (1- (match:start m)))) + (end-border? + (string-ref-border? (match:end m)))) + (max score + (cond + ((and start-border? end-border?) + whole-word-score) + ((or start-border? end-border?) + ;; If the match only has one border, it could still be + ;; part of a compound word, and thus be more likely to + ;; be relevant than if it was just a substring. + 2) + (else + 1))))))))) (define (regexp->score regexp) (let ((score-regexp (lambda (str) (score regexp str)))) base-commit: b6d5a7f5836739dab884b49a64ca354794dd845f -- 2.45.2 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [bug#73220] [PATCH] ui: Add more nuance to relevance scoring. 2024-09-13 7:02 [bug#73220] [PATCH] ui: Add more nuance to relevance scoring aurtzy @ 2024-09-13 14:12 ` Simon Tournier 2024-09-14 0:17 ` aurtzy 2024-09-13 14:24 ` [bug#73220] [PATCH v2] ui: Add partial match " Simon Tournier 1 sibling, 1 reply; 4+ messages in thread From: Simon Tournier @ 2024-09-13 14:12 UTC (permalink / raw) To: aurtzy, 73220 Cc: Josselin Poiret, aurtzy, Mathieu Othacehe, Ludovic Courtès, Tobias Geerinckx-Rice, Christopher Baines Hi, On Fri, 13 Sep 2024 at 03:02, aurtzy <aurtzy@gmail.com> wrote: > Fixes <https://issues.guix.gnu.org/70689>. Thanks! > | Keyword(s) with poor | Expectations | > | results before | | > |-----------------------+-----------------------------------------------| > | dig | ~bind~ near top. | Hum, indeed and I do not know if we can improve here. Well, it’s hard to improve for short terms, BTW. --8<---------------cut here---------------start------------->8--- $ ./pre-inst-env guix search dig | recsel -p name,relevance | head -8 name: go-go-uber-org-dig relevance: 104 name: rust-num-bigint-dig relevance: 78 name: rust-num-bigint-dig relevance: 78 --8<---------------cut here---------------end--------------->8--- Compared to current: --8<---------------cut here---------------start------------->8--- $ guix search dig | recsel -p name,relevance | head -8 name: sysdig relevance: 24 name: texlive-pedigree-perl relevance: 13 name: ruby-net-http-digest-auth relevance: 13 --8<---------------cut here---------------end--------------->8--- Indeed, 17th position is better than 609th. But if you add a term as ’dns’, bang! :-) Well, BTW the description of ’bind’ could be a bit improved because the word network does not appear. Anyway. :-) Hum, why this: guix search ' dig$' dig | recsel -p name,relevance | head -8 does not return the package ’bind’? > | rsh | ~inetutils~ near top. | --8<---------------cut here---------------start------------->8--- $ ./pre-inst-env guix search rsh | recsel -p name,relevance | head -8 name: inetutils relevance: 26 name: emacs-tramp relevance: 26 name: rust-borsh-schema-derive-internal relevance: 22 --8<---------------cut here---------------end--------------->8--- Compared to current: --8<---------------cut here---------------start------------->8--- $ guix search rsh | recsel -p name,relevance | head -8 name: go-sigs-k8s-io-yaml relevance: 14 name: python-pymarshal relevance: 13 name: emacs-powershell relevance: 13 --8<---------------cut here---------------end--------------->8--- > | c | C language related. | > | c compiler | Compiler-related C stuff. | This cannot be improved. > | r | R language related. | Usually, I add the prefix ^r\- and I do not have issue with search for r packages. For instance, search ^r\- keyword and it works well. $ guix search ^r\- cyto | recsel -CP name | cut -f1 -d'-' | uniq -c 29 r Somehow, I do not think we can improve here. I mean, the improvement is to document the usage of prefixes. Similarly for ghc (haskell), ocaml, python, etc. > | tor | Tor related; ~torbrowser~ somewhere near top. | --8<---------------cut here---------------start------------->8--- $ ./pre-inst-env guix search tor | recsel -p name,relevance | head -8 name: tor relevance: 208 name: tor-client relevance: 169 name: torsocks relevance: 103 --8<---------------cut here---------------end--------------->8--- Compared to current: --8<---------------cut here---------------start------------->8--- $ guix search tor | recsel -p name,relevance | head -8 name: tor relevance: 47 name: ghc-storablevector relevance: 29 name: tor-client relevance: 28 --8<---------------cut here---------------end--------------->8--- However, the position move from 225th to 19th. $ guix search tor | recsel -P name | grep -n torbrowser 225:torbrowser $ ./pre-inst-env guix search tor | recsel -P name | grep -n torbrowser 19:torbrowser Similarly as ’dig’, the description of ’torbrowser’ package could be improvement. Because ’guix search tor browser’ returns nothing. > | gcc | ~gcc-toolchain~ near top. | Indeed, something is unexpected. Well, first: $ guix search gcc | recsel -CP name | uniq | head -8 gccgo gfortran-toolchain gdc-toolchain gcc-toolchain gcc-cross-x86_64-w64-mingw32-toolchain gcc-cross-or1k-elf-toolchain gcc-cross-i686-w64-mingw32-toolchain gcc-cross-avr-toolchain $ guix search gcc | recsel -CP name | uniq -c | sort -rn | head -8 18 llvm 12 gcc-toolchain 6 libgccjit 6 gccgo 3 isl 2 libstdc++-doc 2 java-commons-cli 2 gdc-toolchain Other said, the packages with multi-versions decrease the experience. Well, that had already by “improved” [1] with some SEO. ;-) Indeed, maybe the relevance should be improved. Second, gccgo has a relevance score of 22 with the only term ’gcc’, compared to gcc-toolchain scoring at 15. gccgo gcc-toolchain 4 * 1 * 1 4 * 1 * 1 + 2 * 5 * 1 + 2 * 1 * 1 + 1 * 0 + 1 * 0 + 3 * 1 * 1 + 3 * 1 * 1 + 2 * 0 + 2 * 1 * 3 + 1 * 5 * 1 + 1 * 0 = 22 = 15 This is unexpected. And, IMHO that’s bug! In the description of gcc-toolchain, the term ’gcc’ appears 3 times but it only score with ’1’ instead of ’5’. As the patch try to address, the main issue is: (define (score regexp str) (fold-matches regexp str 0 (lambda (m score) (+ score (if (string=? (match:substring m) str) 5 ;exact match 1))))) Here the exact match does not consider a substring exact match. For instance, one would consider that the term ’gcc’ exactly matches in “some GCC thing”. Considering the current implementation, that’s not the case. For instance, a snippet as the procedure ’scoring’: --8<---------------cut here---------------start------------->8--- scheme@(guix-user)> ,use(ice-9 regex) scheme@(guix-user)> (define regexp (make-regexp "gcc" regexp/icase)) scheme@(guix-user)> (define str "some GCC thing") scheme@(guix-user)> (fold-matches regexp str 0 (lambda (m res) (+ res (if (string=? (match:substring m) str) 5 1)))) $2 = 1 --8<---------------cut here---------------end--------------->8--- See v2 for my proposal fixing this. Please note that this v2 gives the same ranking for torbrowser. And also improve the situation with gcc-toolchain. --8<---------------cut here---------------start------------->8--- $ ./pre-inst-env guix search gcc | recsel -CP name | grep -n gcc-toolchain 1:gcc-toolchain 2:gcc-toolchain 3:gcc-toolchain 4:gcc-toolchain 5:gcc-toolchain 6:gcc-toolchain 7:gcc-toolchain 8:gcc-toolchain 9:gcc-toolchain 10:gcc-toolchain 11:gcc-toolchain 12:gcc-toolchain $ ./pre-inst-env guix search tor | recsel -CP name | grep -n torbrowser 7:torbrowser $ ./pre-inst-env guix search dig | recsel -CP name | grep -n bind 44:bind --8<---------------cut here---------------end--------------->8--- However, inetutils is still at 44th with the only one term ’rsh’. I would suggest to do some tweak with the description. Bah maybe it is then a bit slower on cold caches? Hum?! Well, I have not investigated, neither with your patch. :-) Well, that something that could be investigated; especially the performance of ’char-set’ operations. 1: https://issues.guix.gnu.org/43342 > I opted to switch to counting a maximum of one match per field, which helps > with cases where a common subword matches /many/ times in packages with longer > descriptions, pushing more relevant packages down. In multi-term searches, > the unique terms - which are naturally rarer - also contribute to a larger > percentage of the score as a result of these changes. > Having matches with only one word boundary be scored as 2 instead of 1 was > done with the reasoning that a term is more likely to be part of a compound > word name (and thus more relevant) if it is a prefix or suffix; for example, > "gl" in OpenGL, "borg" in borgmatic, and "tor" in torbrowser. [...] > Closing this message on an unrelated note for future work: I stumbled on an > interesting idea while looking for test cases which suggested reducing the > score of a programming library when its language is not included in search > terms. It's out of scope for the current issue, but I thought I'd mention it > anyways for potential further improvements. Well, years ago I thought about implementing TF-IDF [2,3]. Other ideas [4] are floating around. Then, we spent some time for making “guix search” faster [5] and today my TODO is about having an extension relying on Guile-Xapian. Therefore, I would prefer keep the ’relevance’ more or less predictable by only counting the number of occurrences and apply some weights. Else, for what my opinion is worth, the direction would not be to re-invent an algorithm but maybe implement some already well-known ones. TF-IDF [3] is one or Okapi-BM25 is another one, etc. In all in all, that what Xapian provides. ;-) And it does it very well! That’s why I would be tempted to have a Guix extension relying on Guile-Xapin for indexing and searching (fast!). Cheers, simon 2: Re: Organizing packages zimoun <zimon.toutoune@gmail.com> Tue, 16 Jul 2019 19:04:26 +0200 id:CAJ3okZ0LaJzWDBA7bjqZew_jAmtt1rj9PJhevwrtBiA_COXENg@mail.gmail.com https://lists.gnu.org/archive/html/guix-devel/2019-07 https://yhetil.org/guix/CAJ3okZ0LaJzWDBA7bjqZew_jAmtt1rj9PJhevwrtBiA_COXENg@mail.gmail.com 3: https://en.wikipedia.org/wiki/Tf%E2%80%93idf 4: Inverted index to accelerate guix package search Arun Isaac <arunisaac@systemreboot.net> Sun, 12 Jan 2020 20:33:51 +0530 id:cu7h810emy0.fsf@systemreboot.net https://lists.gnu.org/archive/html/guix-devel/2020-01 https://yhetil.org/guix/cu7h810emy0.fsf@systemreboot.net 5: [bug#39258] Faster guix search using an sqlite cache Arun Isaac <arunisaac@systemreboot.net> Fri, 24 Jan 2020 01:21:57 +0530 id:cu7pnfaar36.fsf@systemreboot.net https://issues.guix.gnu.org/39258 https://issues.guix.gnu.org/msgid/cu7pnfaar36.fsf@systemreboot.net https://yhetil.org/guix/cu7pnfaar36.fsf@systemreboot.net 6: https://en.wikipedia.org/wiki/Okapi_BM25 ^ permalink raw reply [flat|nested] 4+ messages in thread
* [bug#73220] [PATCH] ui: Add more nuance to relevance scoring. 2024-09-13 14:12 ` Simon Tournier @ 2024-09-14 0:17 ` aurtzy 0 siblings, 0 replies; 4+ messages in thread From: aurtzy @ 2024-09-14 0:17 UTC (permalink / raw) To: 73220; +Cc: aurtzy, Simon Tournier [-- Attachment #1: Type: text/plain, Size: 11633 bytes --] Hi Simon, On 9/13/24 10:12, Simon Tournier wrote: >> | tor | Tor related; ~torbrowser~ somewhere near top. | > --8<---------------cut here---------------start------------->8--- > $ ./pre-inst-env guix search tor | recsel -p name,relevance | head -8 > name: tor > relevance: 208 > > name: tor-client > relevance: 169 > > name: torsocks > relevance: 103 > --8<---------------cut here---------------end--------------->8--- > > Compared to current: > > --8<---------------cut here---------------start------------->8--- > $ guix search tor | recsel -p name,relevance | head -8 > name: tor > relevance: 47 > > name: ghc-storablevector > relevance: 29 > > name: tor-client > relevance: 28 > --8<---------------cut here---------------end--------------->8--- > > However, the position move from 225th to 19th. > > $ guix search tor | recsel -P name | grep -n torbrowser > 225:torbrowser > > $ ./pre-inst-env guix search tor | recsel -P name | grep -n torbrowser > 19:torbrowser > > Similarly as ’dig’, the description of ’torbrowser’ package could be > improvement. Because ’guix search tor browser’ returns nothing. Does ~torbrowser~ not appear as the third result in all three cases for you when running =guix search tor browser=? Otherwise, if you meant =guix search tor= to find ~torbrowser~: perhaps it should be higher ranked, but it could be argued that patch v1's behavior is still more optimal in this aspect considering all results above ~torbrowser~ it are indeed related to Tor. >> | Keyword(s) with poor | Expectations | >> | results before | | >> |-----------------------+-----------------------------------------------| >> | dig | ~bind~ near top. | > Hum, indeed and I do not know if we can improve here. Well, it’s hard > to improve for short terms, BTW. > > --8<---------------cut here---------------start------------->8--- > $ ./pre-inst-env guix search dig | recsel -p name,relevance | head -8 > name: go-go-uber-org-dig > relevance: 104 > > name: rust-num-bigint-dig > relevance: 78 > > name: rust-num-bigint-dig > relevance: 78 > --8<---------------cut here---------------end--------------->8--- > > Compared to current: > > --8<---------------cut here---------------start------------->8--- > $ guix search dig | recsel -p name,relevance | head -8 > name: sysdig > relevance: 24 > > name: texlive-pedigree-perl > relevance: 13 > > name: ruby-net-http-digest-auth > relevance: 13 > --8<---------------cut here---------------end--------------->8--- > > Indeed, 17th position is better than 609th. But if you add a term as > ’dns’, bang! :-) Well, BTW the description of ’bind’ could be a bit > improved because the word network does not appear. Anyway. :-) [...] >> | rsh | ~inetutils~ near top. | > --8<---------------cut here---------------start------------->8--- > $ ./pre-inst-env guix search rsh | recsel -p name,relevance | head -8 > name: inetutils > relevance: 26 > > name: emacs-tramp > relevance: 26 > > name: rust-borsh-schema-derive-internal > relevance: 22 > --8<---------------cut here---------------end--------------->8--- > > Compared to current: > > --8<---------------cut here---------------start------------->8--- > $ guix search rsh | recsel -p name,relevance | head -8 > name: go-sigs-k8s-io-yaml > relevance: 14 > > name: python-pymarshal > relevance: 13 > > name: emacs-powershell > relevance: 13 > --8<---------------cut here---------------end--------------->8--- [...] >> | gcc | ~gcc-toolchain~ near top. | > Indeed, something is unexpected. Well, first: > > $ guix search gcc | recsel -CP name | uniq | head -8 > gccgo > gfortran-toolchain > gdc-toolchain > gcc-toolchain > gcc-cross-x86_64-w64-mingw32-toolchain > gcc-cross-or1k-elf-toolchain > gcc-cross-i686-w64-mingw32-toolchain > gcc-cross-avr-toolchain > > $ guix search gcc | recsel -CP name | uniq -c | sort -rn | head -8 > 18 llvm > 12 gcc-toolchain > 6 libgccjit > 6 gccgo > 3 isl > 2 libstdc++-doc > 2 java-commons-cli > 2 gdc-toolchain > > Other said, the packages with multi-versions decrease the experience. > Well, that had already by “improved” [1] with some SEO. ;-) Indeed, > maybe the relevance should be improved. > > Second, gccgo has a relevance score of 22 with the only term ’gcc’, > compared to gcc-toolchain scoring at 15. > > gccgo gcc-toolchain > 4 * 1 * 1 4 * 1 * 1 > + 2 * 5 * 1 + 2 * 1 * 1 > + 1 * 0 + 1 * 0 > + 3 * 1 * 1 + 3 * 1 * 1 > + 2 * 0 + 2 * 1 * 3 > + 1 * 5 * 1 + 1 * 0 > = 22 = 15 > > This is unexpected. And, IMHO that’s bug! In the description of > gcc-toolchain, the term ’gcc’ appears 3 times but it only score with ’1’ > instead of ’5’. > > As the patch try to address, the main issue is: > > (define (score regexp str) > (fold-matches regexp str 0 > (lambda (m score) > (+ score > (if (string=? (match:substring m) str) > 5 ;exact match > 1))))) > > Here the exact match does not consider a substring exact match. For > instance, one would consider that the term ’gcc’ exactly matches in > “some GCC thing”. Considering the current implementation, that’s not > the case. For instance, a snippet as the procedure ’scoring’: > > --8<---------------cut here---------------start------------->8--- > scheme@(guix-user)> ,use(ice-9 regex) > scheme@(guix-user)> (define regexp (make-regexp "gcc" regexp/icase)) > scheme@(guix-user)> (define str "some GCC thing") > scheme@(guix-user)> (fold-matches regexp str 0 > (lambda (m res) > (+ res > (if (string=? (match:substring m) str) > 5 1)))) > $2 = 1 > --8<---------------cut here---------------end--------------->8--- > > > See v2 for my proposal fixing this. > > Please note that this v2 gives the same ranking for torbrowser. And > also improve the situation with gcc-toolchain. > > --8<---------------cut here---------------start------------->8--- > $ ./pre-inst-env guix search gcc | recsel -CP name | grep -n gcc-toolchain > 1:gcc-toolchain > 2:gcc-toolchain > 3:gcc-toolchain > 4:gcc-toolchain > 5:gcc-toolchain > 6:gcc-toolchain > 7:gcc-toolchain > 8:gcc-toolchain > 9:gcc-toolchain > 10:gcc-toolchain > 11:gcc-toolchain > 12:gcc-toolchain > > $ ./pre-inst-env guix search tor | recsel -CP name | grep -n torbrowser > 7:torbrowser > > $ ./pre-inst-env guix search dig | recsel -CP name | grep -n bind > 44:bind > --8<---------------cut here---------------end--------------->8--- > > However, inetutils is still at 44th with the only one term ’rsh’. I > would suggest to do some tweak with the description. And including a relevant part of your message from #70689: > Again, considering the case at hand: If instead of 3 randomly picked in > v2 of #73220, we would pick 7, then inetutils is ranked first. > > Yeah, maybe 3 isn’t enough… And maybe 7 is a good choice. What do you think about setting the value to the sum of all weights in ~metrics~ as I did in patch v1? My logic is that an object is almost always going to be relevant if it contains a whole word match compared to "maybe relevant" if it only matches substrings, so it would be reasonable to thus show most of the objects with whole word matches first. This improves or maintains consistency of relevant results in the test cases with shorter terms, and also reduces the need for guesswork with choosing arbitrary numbers that may or may not work. Note that I also gave the same treatment to exact match scores, although not as extremely weighed (only double the whole word score in v1). In the case of ~inetutils~, for example, this formula guarantees that if I were to search =rsh= - which is a common subword, but itself has a very unique meaning - ~inetutils~ /always/ shows up at or near the top along with other rsh-related packages, assuming no exact matches. In other words, the intention would be to have the calculations set up such that they implicitly "categorize" object rankings into a (rough) hierarchy of the following: |--------------------------------------------| | Objects with at least one exact match | |--------------------------------------------| | Objects with at least one whole word match | |--------------------------------------------| | Objects with only substring matches | |--------------------------------------------| >> I opted to switch to counting a maximum of one match per field, which helps >> with cases where a common subword matches /many/ times in packages with longer >> descriptions, pushing more relevant packages down. In multi-term searches, >> the unique terms - which are naturally rarer - also contribute to a larger >> percentage of the score as a result of these changes. >> Having matches with only one word boundary be scored as 2 instead of 1 was >> done with the reasoning that a term is more likely to be part of a compound >> word name (and thus more relevant) if it is a prefix or suffix; for example, >> "gl" in OpenGL, "borg" in borgmatic, and "tor" in torbrowser. > [...] > >> Closing this message on an unrelated note for future work: I stumbled on an >> interesting idea while looking for test cases which suggested reducing the >> score of a programming library when its language is not included in search >> terms. It's out of scope for the current issue, but I thought I'd mention it >> anyways for potential further improvements. > Well, years ago I thought about implementing TF-IDF [2,3]. Other ideas > [4] are floating around. Then, we spent some time for making “guix > search” faster [5] and today my TODO is about having an extension > relying on Guile-Xapian. > > Therefore, I would prefer keep the ’relevance’ more or less predictable > by only counting the number of occurrences and apply some weights. > Else, for what my opinion is worth, the direction would not be to > re-invent an algorithm but maybe implement some already well-known ones. > TF-IDF [3] is one or Okapi-BM25 is another one, etc. In all in all, > that what Xapian provides. ;-) And it does it very well! That’s why I > would be tempted to have a Guix extension relying on Guile-Xapin for > indexing and searching (fast!). Yes, I had thought about trying something like TF-IDF while looking into the issue, but it seemed much less trivial than changes to a scoring function. The count-once-per-field change was supposed to at least tangentially mimic this behavior and reduce bias towards objects that happen to have very long descriptions but aren't very relevant. It's also needed for my "categorization" math to hold. > Hum, why this: > > guix search ' dig$' dig | recsel -p name,relevance | head -8 > > does not return the package ’bind’? It appears the ~regexp/newline~ flag needs to be set for ~make-regexp~. A quick test adding it here [1] seemed to work. My main concern with v2 is that I don't think whole words are weighed heavily enough, but it provides a simpler solution that still offers improvement, so I'm happy either way. Thanks for the feedback! [1] https://git.savannah.gnu.org/cgit/guix.git/tree/guix/scripts/package.scm#n897 Cheers, aurtzy [-- Attachment #2: Type: text/html, Size: 13856 bytes --] ^ permalink raw reply [flat|nested] 4+ messages in thread
* [bug#73220] [PATCH v2] ui: Add partial match relevance scoring. 2024-09-13 7:02 [bug#73220] [PATCH] ui: Add more nuance to relevance scoring aurtzy 2024-09-13 14:12 ` Simon Tournier @ 2024-09-13 14:24 ` Simon Tournier 1 sibling, 0 replies; 4+ messages in thread From: Simon Tournier @ 2024-09-13 14:24 UTC (permalink / raw) To: 73220 Cc: aurtzy, Simon Tournier, Christopher Baines, Josselin Poiret, Ludovic Courtès, Mathieu Othacehe, Simon Tournier, Tobias Geerinckx-Rice * guix/ui.scm (char-set:delimiters): New variable. (revelance)[string-match-term?]: New procedure. [score]: Use it. Change-Id: If2edc0e08b338a0064f73425db60d688c0535fb0 --- guix/ui.scm | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/guix/ui.scm b/guix/ui.scm index 966f0611f6..a8d1d120a4 100644 --- a/guix/ui.scm +++ b/guix/ui.scm @@ -1678,6 +1678,14 @@ (define* (package->recutils p port #:optional (width (terminal-columns)) ;;; Searching. ;;; +(define char-set:delimiters (char-set-xor + (char-set #\-) ;remove from punctuation + (char-set-union (char-set #\nul) + (char-set #\newline) + char-set:punctuation + char-set:symbol + char-set:whitespace))) + (define (relevance obj regexps metrics) "Compute a \"relevance score\" for OBJ as a function of its number of matches of REGEXPS and accordingly to METRICS. METRICS is list of @@ -1687,13 +1695,28 @@ (define (relevance obj regexps metrics) A score of zero means that OBJ does not match any of REGEXPS. The higher the score, the more relevant OBJ is to REGEXPS." + (define (string-match-term? regex-match str) + (let* ((start (match:start regex-match)) + (char:start (if (= 0 start) + #\nul + (string-ref str (1- start)))) + (end (match:end regex-match)) + (char:end (if (= end (string-length str)) + #\nul + (string-ref str end)))) + (and (char-set-contains? char-set:delimiters char:start) + (char-set-contains? char-set:delimiters char:end)))) + (define (score regexp str) (fold-matches regexp str 0 (lambda (m score) (+ score - (if (string=? (match:substring m) str) - 5 ;exact match - 1))))) + (cond + ((string=? (match:substring m) str) + 5) ;exact match + ((string-match-term? m str) + 3) ;XXX + (else 1)))))) (define (regexp->score regexp) (let ((score-regexp (lambda (str) (score regexp str)))) base-commit: 98bc13b9ea5f22a60de6c289d59072638001e08e prerequisite-patch-id: 912de410e3d8a0796e83bfa50047debb0030b624 prerequisite-patch-id: 9c72d45734a13bd80021b14b562ed1b6238aa7ca prerequisite-patch-id: 952cbe8dad322348d00f15125b512d34aaad8009 prerequisite-patch-id: fa6543fd5e6ec54a5036335aa5fa2b3a52675610 prerequisite-patch-id: cd68729ed441ec8235fde738e1f19669b570b099 prerequisite-patch-id: 53c5439602662bd61a3729aedf9327dfee5e9956 prerequisite-patch-id: a7edcd751c7a127f76b9c8e33ee425b6e800cfd7 prerequisite-patch-id: 29c1b2b9fcc017cff904ff3c1a32f65a6d54bad8 prerequisite-patch-id: 71757f95077bb7812f9d5a4e942c15b152ec7ac9 -- 2.45.2 ^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-09-14 0:20 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-09-13 7:02 [bug#73220] [PATCH] ui: Add more nuance to relevance scoring aurtzy 2024-09-13 14:12 ` Simon Tournier 2024-09-14 0:17 ` aurtzy 2024-09-13 14:24 ` [bug#73220] [PATCH v2] ui: Add partial match " Simon Tournier
Code repositories for project(s) associated with this external index https://git.savannah.gnu.org/cgit/guix.git This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.