aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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))