From 502566073c07eac6a91131847691cc0dbc093b18 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Wed, 23 Sep 2026 01:47:30 +0100 Subject: Replace query combinator with C++ query builder. We need composite queries to have more than two subqueries. The only way to do this is to provide Xapian::Query with an iterator. And to do this, we need to drop down to C++. --- xapian/xapian.scm | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) (limited to 'xapian') diff --git a/xapian/xapian.scm b/xapian/xapian.scm index d71bbe1..00a4896 100644 --- a/xapian/xapian.scm +++ b/xapian/xapian.scm @@ -299,17 +299,12 @@ on the database object." "Return a @code{Query} object for @var{term}." (new-Query term)) -(define (query-combine combine-operator default . queries) - (reduce-right (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)) + (guile-xapian-build-query (Query-OP-AND) queries)) (define (query-or . queries) "Return a query matching documents which at least one of @var{queries} @@ -317,7 +312,7 @@ 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)) + (guile-xapian-build-query (Query-OP-OR) queries)) (define (query-xor . queries) "Return a query matching documents which an odd number of @var{queries} @@ -325,7 +320,7 @@ match. In a weighted context, the weight is the sum of the weights for matching queries." - (apply query-combine (Query-OP-XOR) (Query-MatchNothing) queries)) + (guile-xapian-build-query (Query-OP-XOR) queries)) (define (query-filter . queries) "Return a query matching only documents matching all @var{queries}, @@ -333,19 +328,17 @@ 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)) + (guile-xapian-build-query (Query-OP-FILTER) queries)) -(define (query-phrase first-query . other-queries) - "Return a query matching only documents where @var{first-query} and all -of @var{other-queries} match near and in order. All queries must be -single-term queries (constructed using @code{query}) or single-term -queries composed with @code{query-or}. +(define (query-phrase . queries) + "Return a query matching only documents where all @var{queries} match +near and in order. All queries must be single-term +queries (constructed using @code{query}) or single-term queries +composed with @code{query-or}. In a weighted context, the weight is the sum of the weights for all queries." - (new-Query (Query-OP-PHRASE) - first-query - (apply query-or other-queries))) + (guile-xapian-build-query (Query-OP-PHRASE) queries)) (define* (prefixed-range-processor slot proc #:key (prefix "") repeated?) -- cgit 1.4.1