From: Arun Isaac <arunisaac@systemreboot.net>
To: Pierre Neidhardt <mail@ambrevar.xyz>, zimoun <zimon.toutoune@gmail.com>
Cc: Guix Devel <guix-devel@gnu.org>
Subject: Re: Inverted index to accelerate guix package search
Date: Fri, 17 Jan 2020 00:36:37 +0530 [thread overview]
Message-ID: <cu7tv4vcjb6.fsf@systemreboot.net> (raw)
In-Reply-To: <87muaqnmod.fsf@ambrevar.xyz>
[-- Attachment #1.1: Type: text/plain, Size: 1749 bytes --]
Pierre Neidhardt <mail@ambrevar.xyz> writes:
> By the way, what about using Xapian in Guix?
I looked up xapian's features at https://xapian.org/features and it is
quite impressive. I was introduced to xapian through notmuch. notmuch
does not utilize xapian to the fullest and I therefore ended up
underestimating its value. Of particular importance might be the
following.
- Relevance feedback - given one or more documents, Xapian can suggest
the most relevant index terms to expand a query, suggest related
documents, categorise documents, etc.
- Phrase and proximity searching - users can search for words occurring
in an exact phrase or within a specified number of words, either in a
specified order, or in any order.
- Supports stemming of search terms (e.g. a search for "football" would
match documents which mention "footballs" or "footballer")
I think these features would really help in Pierre's work trying to
improve search and discoverability on Guix. If we are planning to have a
"Software Center" like interface at some point in the future, xapian's
search could come in handy.
Not directly related to Guix, but I also wonder if info manuals would be
a lot more useful if they had good full text search using xapian.
For the time being, since we don't have xapian bindings, I think we
should settle for sqlite's full text search capabilities.
https://www.sqlite.org/fts5.html
I have attached a short proof of concept script for an sqlite based
search. Speedup is around 200x, and populating the database only takes
around 2.5 seconds. Here is a sample run.
Sqlite database populated in 2.5516340732574463 seconds
Brute force search took 0.11850595474243164 seconds
Sqlite search took 5.459785461425781e-4 seconds
[-- Attachment #1.2: sqlite-search.scm --]
[-- Type: text/plain, Size: 2145 bytes --]
(use-modules (gnu packages)
(guix packages)
(ice-9 match)
(sqlite3)
(srfi srfi-26))
(define db (sqlite-open "/tmp/index.sqlite"))
(define schema
"CREATE VIRTUAL TABLE packages USING fts5(name, description)")
(define (build-sqlite-database)
(sqlite-exec db schema)
(sqlite-exec db "BEGIN")
(fold-packages
(lambda (package _)
(let ((statement (sqlite-prepare db "INSERT INTO packages(name, description) VALUES(:name, :description)")))
(sqlite-bind-arguments statement
#:name (package-name package)
#:description (package-description package))
(sqlite-fold cons '() statement)
(sqlite-finalize statement)))
#f)
(sqlite-exec db "COMMIT;"))
(define (sqlite-retrieve query)
(let ((statement (sqlite-prepare db "SELECT name FROM packages WHERE description MATCH :query")))
(sqlite-bind-arguments statement #:query query)
(let ((result (sqlite-fold (lambda (v result)
(match v
(#(name) (cons name result))))
'() statement)))
(sqlite-finalize statement)
result)))
(define (brute-force-retrieve query)
"Return names of all packages whose descriptions contain the string QUERY.
Search brute force by folding over all packages."
(fold-packages (lambda (package result)
(if (string-contains (package-description package) query)
(cons package result)
result))
'()))
(define (time-us thunk)
(define pair->sec
(match-lambda
((sec . usec)
(+ sec (/ usec 1e6)))))
(let ((start (gettimeofday)))
(thunk)
(let ((stop (gettimeofday)))
(- (pair->sec stop) (pair->sec start)))))
(format #t "Sqlite database populated in ~a seconds
Brute force search took ~a seconds
Sqlite search took ~a seconds
"
(time-us build-sqlite-database)
(time-us (cut brute-force-retrieve "strategy"))
(time-us (cut sqlite-retrieve "strategy")))
(sqlite-close db)
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]
next prev parent reply other threads:[~2020-01-16 19:07 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-12 15:03 Inverted index to accelerate guix package search Arun Isaac
2020-01-13 8:48 ` Pierre Neidhardt
2020-01-13 15:08 ` Arun Isaac
2020-01-13 17:54 ` zimoun
2020-01-14 3:53 ` Bengt Richter
2020-01-14 14:21 ` Pierre Neidhardt
2020-01-14 15:27 ` Giovanni Biscuolo
2020-01-14 20:55 ` zimoun
2020-01-14 21:41 ` Pierre Neidhardt
2020-01-14 21:59 ` zimoun
2020-01-15 9:12 ` Pierre Neidhardt
2020-01-15 14:25 ` zimoun
2020-01-15 11:53 ` Giovanni Biscuolo
2020-01-15 14:49 ` zimoun
2020-01-16 19:06 ` Arun Isaac [this message]
2020-01-16 20:08 ` zimoun
2020-01-17 17:13 ` Pierre Neidhardt
2020-01-17 19:11 ` Pierre Neidhardt
2020-01-18 20:31 ` Arun Isaac
2020-01-15 5:44 ` Arun Isaac
2020-01-15 9:06 ` Pierre Neidhardt
2020-01-15 12:00 ` zimoun
2020-01-15 13:41 ` Pierre Neidhardt
2020-01-15 11:54 ` zimoun
2020-01-15 21:03 ` Ricardo Wurmus
2020-01-15 21:19 ` zimoun
2020-01-16 14:44 ` Ludovic Courtès
2020-01-16 15:04 ` zimoun
2020-01-16 19:11 ` Arun Isaac
2020-01-16 19:53 ` zimoun
2020-01-17 19:29 ` Arun Isaac
2020-01-20 19:14 ` zimoun
2020-01-20 20:42 ` Arun Isaac
2020-01-21 10:46 ` Ludovic Courtès
2020-01-23 20:49 ` Arun Isaac
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cu7tv4vcjb6.fsf@systemreboot.net \
--to=arunisaac@systemreboot.net \
--cc=guix-devel@gnu.org \
--cc=mail@ambrevar.xyz \
--cc=zimon.toutoune@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.