aboutsummaryrefslogtreecommitdiff
path: root/xapian
diff options
context:
space:
mode:
authorArun Isaac2022-10-16 00:55:22 +0530
committerArun Isaac2022-10-17 01:45:33 +0530
commit410e78b472b5195f799a75507e5e3c4ec7e03650 (patch)
treeb57d20f0b3783229db8b34465abafe9ab41be36f /xapian
parented02fb855726c8f19c856212ff8e13aa11a9db51 (diff)
downloadguile-xapian-410e78b472b5195f799a75507e5e3c4ec7e03650.tar.gz
guile-xapian-410e78b472b5195f799a75507e5e3c4ec7e03650.tar.lz
guile-xapian-410e78b472b5195f799a75507e5e3c4ec7e03650.zip
xapian: Support combining queries with OR, AND and FILTER operators.
* xapian/xapian.scm: Import (srfi srfi-1). (query-combine): New function. (query-and, query-or, query-filter): New public functions.
Diffstat (limited to 'xapian')
-rw-r--r--xapian/xapian.scm32
1 files changed, 32 insertions, 0 deletions
diff --git a/xapian/xapian.scm b/xapian/xapian.scm
index 650c401..f22cfee 100644
--- a/xapian/xapian.scm
+++ b/xapian/xapian.scm
@@ -22,6 +22,7 @@
#:use-module (rnrs arithmetic bitwise)
#:use-module (rnrs bytevectors)
#:use-module (ice-9 match)
+ #:use-module (srfi srfi-1)
#:use-module (srfi srfi-26)
#:use-module (htmlprag)
#:use-module (xapian wrap)
@@ -49,6 +50,9 @@
index-text!
increase-termpos!
parse-query
+ query-and
+ query-or
+ query-filter
enquire
enquire-mset
mset-item-docid
@@ -196,6 +200,34 @@ on the database object."
(MSetIterator-next head)
(loop head result))))))
+(define (query-combine combine-operator default . queries)
+ (reduce (cut new-Query combine-operator <> <>)
+ default
+ queries))
+
+(define (query-and . queries)
+ "Return a query matching only documents matching all @var{queries}.
+
+In a weighted context, the weight is the sum of the weights for all
+queries."
+ (apply query-combine (Query-OP-AND) (Query-MatchAll) queries))
+
+(define (query-or . queries)
+ "Return a query matching documents which at least one of @var{queries}
+match.
+
+In a weighted context, the weight is the sum of the weights for
+matching queries."
+ (apply query-combine (Query-OP-OR) (Query-MatchNothing) queries))
+
+(define (query-filter . queries)
+ "Return a query matching only documents matching all @var{queries},
+but only take weight from the first of @var{queries}.
+
+In a non-weighted context, @code{query-filter} and @code{query-and}
+are equivalent."
+ (apply query-combine (Query-OP-FILTER) (Query-MatchAll) queries))
+
(define (get-flag flag-thunk value)
(if value (flag-thunk) 0))