about summary refs log tree commit diff
path: root/xapian.i.in
diff options
context:
space:
mode:
Diffstat (limited to 'xapian.i.in')
-rw-r--r--xapian.i.in84
1 files changed, 83 insertions, 1 deletions
diff --git a/xapian.i.in b/xapian.i.in
index ff4ce80..ba923d4 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, 2026 Arun Isaac <arunisaac@systemreboot.net>
  * Copyright © 2021, 2022 Bob131 <bob@bob131.so>
  *
  * This file is part of guile-xapian.
@@ -141,3 +141,85 @@
     return new Xapian::Query (op_, slot, range_lower, range_upper);
   }
 }
+
+// Child class of Xapian::RangeProcessor that calls back to a
+// user-specified Scheme procedure to process fields.
+%{
+  class GuileXapianRangeProcessorWrapper
+    : public Xapian::RangeProcessor {
+  private:
+    SCM proc;
+  public:
+    GuileXapianRangeProcessorWrapper(Xapian::valueno slot, const std::string &str, unsigned flags, SCM _proc)
+      : Xapian::RangeProcessor(slot, str, flags) {
+      proc = _proc;
+    }
+    Xapian::Query operator()(const std::string &begin, const std::string &end) {
+      void *ptr;
+      int res = SWIG_ConvertPtr(scm_call_2(proc,
+                                           begin.empty() ? SCM_BOOL_F : scm_from_utf8_string(begin.c_str()),
+                                           end.empty() ? SCM_BOOL_F : scm_from_utf8_string(end.c_str())),
+                                &ptr,
+                                SWIGTYPE_p_Xapian__Query,
+                                0);
+      return *((Xapian::Query*)ptr);
+    }
+  };
+%}
+
+class GuileXapianRangeProcessorWrapper
+: public Xapian::RangeProcessor
+{
+ public:
+  GuileXapianRangeProcessorWrapper(Xapian::valueno, std::string const&, unsigned, SCM);
+  ~GuileXapianRangeProcessorWrapper();
+  Xapian::Query operator()(std::string const&, std::string const&);
+};
+
+// 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&);
+};
+
+// 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<length; i++)
+      SWIG_ConvertPtr(scm_list_ref(subqueries, scm_from_int(i)),
+                      (void**)&subqueries_arr[i],
+                      SWIGTYPE_p_Xapian__Query,
+                      0);
+    return Xapian::Query(op, subqueries_arr, subqueries_arr + length);
+  }
+%}
+
+Xapian::Query guile_xapian_build_query(Xapian::Query::op, SCM);