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.i.in | 19 ++++++++++++++++++- xapian/xapian.scm | 27 ++++++++++----------------- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/xapian.i.in b/xapian.i.in index 84695e9..ba923d4 100644 --- a/xapian.i.in +++ b/xapian.i.in @@ -1,5 +1,5 @@ /* guile-xapian --- Guile bindings for Xapian - * Copyright © 2020, 2023–2024 Arun Isaac + * Copyright © 2020, 2023–2024, 2026 Arun Isaac * Copyright © 2021, 2022 Bob131 * * This file is part of guile-xapian. @@ -206,3 +206,20 @@ class GuileXapianFieldProcessorWrapper ~GuileXapianFieldProcessorWrapper(); Xapian::Query operator()(std::string const&); }; + +// Build query from subqueries. This needs to be in C++ because we +// need to provide Xapian::Query with an iterator. +%{ + Xapian::Query guile_xapian_build_query(Xapian::Query::op op, SCM subqueries) { + int length = scm_to_int(scm_length(subqueries)); + Xapian::Query **subqueries_arr = (Xapian::Query**) malloc(length * sizeof(Xapian::Query*)); + for (int i=0; i <>) - 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