diff options
author | Arun Isaac | 2024-05-03 22:48:26 +0100 |
---|---|---|
committer | Arun Isaac | 2024-05-04 00:07:08 +0100 |
commit | ec7e7a9eabe210e1a75eeeb68f45dc1d6e5a7731 (patch) | |
tree | e27c3fdae9f82818c037b0e9f0079b3a55ceb85b | |
parent | 55f218b7f8db67fff559df94faaa55abb528939a (diff) | |
download | guile-xapian-ec7e7a9eabe210e1a75eeeb68f45dc1d6e5a7731.tar.gz guile-xapian-ec7e7a9eabe210e1a75eeeb68f45dc1d6e5a7731.tar.lz guile-xapian-ec7e7a9eabe210e1a75eeeb68f45dc1d6e5a7731.zip |
xapian: Wrap FieldProcessor.
* xapian.i.in (GuileXapianFieldProcessorWrapper): New class.
* xapian/xapian.scm (field-processor): New public function.
-rw-r--r-- | xapian.i.in | 33 | ||||
-rw-r--r-- | xapian/xapian.scm | 9 |
2 files changed, 40 insertions, 2 deletions
diff --git a/xapian.i.in b/xapian.i.in index ff4ce80..bc9991c 100644 --- a/xapian.i.in +++ b/xapian.i.in @@ -1,5 +1,5 @@ /* guile-xapian --- Guile bindings for Xapian - * Copyright © 2020, 2023 Arun Isaac <arunisaac@systemreboot.net> + * Copyright © 2020, 2023–2024 Arun Isaac <arunisaac@systemreboot.net> * Copyright © 2021, 2022 Bob131 <bob@bob131.so> * * This file is part of guile-xapian. @@ -141,3 +141,34 @@ return new Xapian::Query (op_, slot, range_lower, range_upper); } } + +// Child class of Xapian::FieldProcessor that calls back to a +// user-specified Scheme procedure to process fields. +%{ + class GuileXapianFieldProcessorWrapper + : public Xapian::FieldProcessor { + private: + SCM proc; + public: + GuileXapianFieldProcessorWrapper(SCM _proc) { + proc = _proc; + } + Xapian::Query operator()(const std::string &str) { + void *ptr; + int res = SWIG_ConvertPtr(scm_call_1(proc, scm_from_utf8_string(str.c_str())), + &ptr, + SWIGTYPE_p_Xapian__Query, + 0); + return *((Xapian::Query*)ptr); + } + }; +%} + +class GuileXapianFieldProcessorWrapper +: public Xapian::FieldProcessor +{ + public: + GuileXapianFieldProcessorWrapper(SCM); + ~GuileXapianFieldProcessorWrapper(); + Xapian::Query operator()(std::string const&); +}; diff --git a/xapian/xapian.scm b/xapian/xapian.scm index 80b4b9b..8b8b952 100644 --- a/xapian/xapian.scm +++ b/xapian/xapian.scm @@ -1,5 +1,5 @@ ;;; guile-xapian --- Guile bindings for Xapian -;;; Copyright © 2020, 2022 Arun Isaac <arunisaac@systemreboot.net> +;;; Copyright © 2020, 2022, 2024 Arun Isaac <arunisaac@systemreboot.net> ;;; Copyright © 2021 Bob131 <bob@bob131.so> ;;; ;;; This file is part of guile-xapian. @@ -53,6 +53,7 @@ query-and query-or query-filter + field-processor enquire enquire-mset mset-item-docid @@ -234,6 +235,12 @@ In a non-weighted context, @code{query-filter} and @code{query-and} are equivalent." (apply query-combine (Query-OP-FILTER) (Query-MatchAll) queries)) +(define (field-processor proc) + "Return a @code{FieldProcessor} object that calls +@var{proc} to process its field. @var{proc} is a procedure that, given +a string, must return a @code{Query} object." + (new-GuileXapianFieldProcessorWrapper proc)) + (define (get-flag flag-thunk value) (if value (flag-thunk) 0)) |