diff options
32 files changed, 1653 insertions, 318 deletions
diff --git a/.dir-locals.el b/.dir-locals.el index e609fc4..8050241 100644 --- a/.dir-locals.el +++ b/.dir-locals.el @@ -3,8 +3,11 @@ ((nil (indent-tabs-mode)) + (makefile-mode + (indent-tabs-mode t)) (scheme-mode (eval put 'call-with-database 'scheme-indent-function 1) - (eval put 'call-with-writable-database 'scheme-indent-function 1))) + (eval put 'call-with-writable-database 'scheme-indent-function 1) + (eval put 'call-with-temporary-writable-database 'scheme-indent-function 1))) diff --git a/.guix-authorizations b/.guix-authorizations new file mode 100644 index 0000000..a8ef8be --- /dev/null +++ b/.guix-authorizations @@ -0,0 +1,4 @@ +(authorizations + (version 0) + (("7F73 0343 F2F0 9F3C 77BF 79D3 2E25 EE8B 6180 2BB3" + (name "arunisaac")))) diff --git a/.guix-channel b/.guix-channel new file mode 100644 index 0000000..35e181f --- /dev/null +++ b/.guix-channel @@ -0,0 +1,3 @@ +(channel + (version 0) + (directory ".guix")) diff --git a/.guix/guile-xapian-distribution.scm b/.guix/guile-xapian-distribution.scm new file mode 100644 index 0000000..a28b888 --- /dev/null +++ b/.guix/guile-xapian-distribution.scm @@ -0,0 +1,85 @@ +;;; guile-xapian --- Guile bindings for Xapian +;;; Copyright © 2026 Arun Isaac <arunisaac@systemreboot.net> +;;; +;;; This file is part of guile-xapian. +;;; +;;; guile-xapian is free software: you can redistribute it and/or +;;; modify it under the terms of the GNU General Public License as +;;; published by the Free Software Foundation, either version 2 of the +;;; License, or (at your option) any later version. +;;; +;;; guile-xapian is distributed in the hope that it will be useful, +;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;;; General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with guile-xapian. If not, see +;;; <https://www.gnu.org/licenses/>. + +(define-module (guile-xapian-distribution) + #:use-module ((gnu packages version-control) #:select (git-minimal)) + #:use-module ((guix build-system guile) #:select (%guile-build-system-modules)) + #:use-module (guix gexp) + #:use-module (guix profiles) + #:use-module ((guile-xapian-package) #:select (guile-xapian))) + +(define guile-xapian-git-repo + (local-file "../.git" + "guile-xapian-git-repo" + #:recursive? #t)) + +;; guile-xapian-git-repo cannot find the git repo when built from a +;; Guix channel. So, guile-xapian-distribution cannot be built from a +;; Guix channel. +(define-public guile-xapian-distribution-gexp + (let ((development-profile + (profile + (content (package->development-manifest guile-xapian)) + (allow-collisions? #t)))) + (with-imported-modules %guile-build-system-modules + #~(begin + (use-modules (guix build guile-build-system) + (guix build utils) + (ice-9 ftw) + (ice-9 match) + (srfi srfi-26)) + + (set-path-environment-variable + "PATH" (list "/bin") (list #$development-profile #$git-minimal)) + (set-path-environment-variable + "C_INCLUDE_PATH" (list "/include") (list #$development-profile)) + (set-path-environment-variable + "CPLUS_INCLUDE_PATH" (list "/include") (list #$development-profile)) + (set-path-environment-variable + "LIBRARY_PATH" (list "/lib") (list #$development-profile)) + (set-path-environment-variable + "ACLOCAL_PATH" (list "/share/aclocal") (list #$development-profile)) + (set-path-environment-variable + "PKG_CONFIG_PATH" (list "/lib/pkgconfig") (list #$development-profile)) + (set-path-environment-variable + "GUILE_LOAD_PATH" + (list (string-append "/share/guile/site/" + (target-guile-effective-version))) + (list #$development-profile)) + (set-path-environment-variable + "GUILE_LOAD_COMPILED_PATH" + (list (string-append "/lib/guile/" (target-guile-effective-version) "/site-ccache")) + (list #$development-profile)) + (invoke "git" "clone" + (string-append "file://" #$guile-xapian-git-repo) + (getcwd)) + (patch-shebang "bootstrap.sh") + (invoke "./bootstrap.sh") + (patch-shebang "configure") + (invoke "./configure" "CONFIG_SHELL=sh" "SHELL=sh") + (invoke "make" "dist") + (match (scandir (getcwd) (cut string-suffix? ".tar.lz" <>)) + ((tarball) + (copy-file tarball #$output))))))) + +(define-public guile-xapian-distribution + (computed-file "guile-xapian.tar.lz" guile-xapian-distribution-gexp)) + +guile-xapian-distribution + diff --git a/.guix/guile-xapian-package.scm b/.guix/guile-xapian-package.scm new file mode 100644 index 0000000..ecf8ca5 --- /dev/null +++ b/.guix/guile-xapian-package.scm @@ -0,0 +1,63 @@ +;;; guile-xapian --- Guile bindings for Xapian +;;; Copyright © 2021–2024, 2026 Arun Isaac <arunisaac@systemreboot.net> +;;; +;;; This file is part of guile-xapian. +;;; +;;; guile-xapian is free software: you can redistribute it and/or +;;; modify it under the terms of the GNU General Public License as +;;; published by the Free Software Foundation, either version 2 of the +;;; License, or (at your option) any later version. +;;; +;;; guile-xapian is distributed in the hope that it will be useful, +;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;;; General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with guile-xapian. If not, see +;;; <https://www.gnu.org/licenses/>. + +(define-module (guile-xapian-package) + #:use-module ((gnu packages autotools) #:select (autoconf autoconf-archive automake libtool)) + #:use-module ((gnu packages guile) #:select (guile-2.2)) + #:use-module ((gnu packages guile-xyz) #:prefix guix:) + #:use-module ((gnu packages search) #:select (xapian)) + #:use-module ((gnu packages swig) #:select (swig)) + #:use-module (guix gexp) + #:use-module (guix git-download) + #:use-module (guix packages) + #:use-module (guix utils)) + +(define-public guile-xapian + (package + (inherit guix:guile-xapian) + (source (local-file ".." + "guile-xapian-checkout" + #:recursive? #t + #:select? (or (git-predicate (dirname (current-source-directory))) + (const #t)))) + (inputs + (modify-inputs (package-inputs guix:guile-xapian) + (replace "xapian" xapian))) + (native-inputs + (modify-inputs (package-native-inputs guix:guile-xapian) + (prepend autoconf autoconf-archive automake libtool) + (replace "swig" swig))))) + +(define-public guile2.2-xapian + (package + (inherit guix:guile2.2-xapian) + (source (local-file ".." + "guile-xapian-checkout" + #:recursive? #t + #:select? (or (git-predicate (dirname (current-source-directory))) + (const #t)))) + (inputs + (modify-inputs (package-inputs guix:guile2.2-xapian) + (replace "xapian" xapian))) + (native-inputs + (modify-inputs (package-native-inputs guix:guile2.2-xapian) + (prepend autoconf autoconf-archive automake libtool) + (replace "swig" swig))))) + +guile-xapian diff --git a/.guix/guile-xapian-website.scm b/.guix/guile-xapian-website.scm new file mode 100644 index 0000000..9944157 --- /dev/null +++ b/.guix/guile-xapian-website.scm @@ -0,0 +1,42 @@ +;;; guile-xapian --- Guile bindings for Xapian +;;; Copyright © 2026 Arun Isaac <arunisaac@systemreboot.net> +;;; +;;; This file is part of guile-xapian. +;;; +;;; guile-xapian is free software: you can redistribute it and/or +;;; modify it under the terms of the GNU General Public License as +;;; published by the Free Software Foundation, either version 2 of the +;;; License, or (at your option) any later version. +;;; +;;; guile-xapian is distributed in the hope that it will be useful, +;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;;; General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with guile-xapian. If not, see +;;; <https://www.gnu.org/licenses/>. + +(define-module (guile-xapian-website) + #:use-module ((gnu packages emacs) #:select (emacs-minimal)) + #:use-module (guix gexp) + #:use-module (guix packages) + #:use-module ((guile-xapian-package) #:select (guile-xapian))) + +(define guile-xapian-website-gexp + (with-imported-modules '((guix build utils)) + #~(begin + (use-modules (guix build utils)) + + (copy-recursively #$(package-source guile-xapian) + (getcwd)) + (invoke #$(file-append emacs-minimal "/bin/emacs") + "--quick" "--batch" + "--load" "build-aux/build-home-page.el" + "--funcall" "build-website") + (copy-recursively "website" #$output)))) + +(define-public guile-xapian-website + (computed-file "guile-xapian-website" guile-xapian-website-gexp)) + +guile-xapian-website diff --git a/HACKING.md b/HACKING.md new file mode 100644 index 0000000..b2a56ef --- /dev/null +++ b/HACKING.md @@ -0,0 +1,35 @@ +# Set up development environment + +Drop into a development environment using `guix shell`. +``` +guix shell -Df guix.scm +``` + +# Build the website + +``` +guix build -L .guix -f guile-xapian-website.scm +``` + +# Make a release +## Bump version +Bump version in `configure.ac`. +## Tag a release +Tag (annotated and signed; use the -ase flags to `git tag`) a release `vx.x.x` putting news into the tag message. +## Create a release tarball, test it, and sign it +``` +cp $(guix build -L .guix -f .guix/guile-xapian-distribution.scm) guile-xapian-x.x.x.tar.lz +guix build -L .guix --with-source=guile-xapian=guile-xapian-x.x.x.tar.lz -e '(@@ (guile-xapian-package) guile-xapian)' +guix build -L .guix --with-source=guile2.2-xapian=guile-xapian-x.x.x.tar.lz -e '(@@ (guile-xapian-package) guile2.2-xapian)' +gpg --detach-sign --armor guile-xapian-x.x.x.tar.lz +``` +## Publish release tarball +Add release tarball and signature to website. +## Update Guix package +## Publicize +Publicize on +- [guile-xapian public inbox](mailto:guile-xapian@systemreboot.net) +- [guile-user mailing list](mailto:guile-user@gnu.org) +- the fediverse + +A mail template is available in `release-email.scm`. If you have your default mail client configured correctly, you can simply run `./release-email.scm` to open your mail client with the announcement e-mail filled in. diff --git a/Makefile.am b/Makefile.am index e88d63b..9ba38b7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,5 +1,5 @@ # guile-xapian --- Guile bindings for Xapian -# Copyright © 2020, 2021, 2022 Arun Isaac <arunisaac@systemreboot.net> +# Copyright © 2020–2024, 2026 Arun Isaac <arunisaac@systemreboot.net> # Copyright © 2022 Bob131 <bob@bob131.so> # # This file is part of guile-xapian. @@ -18,14 +18,11 @@ # along with guile-xapian. If not, see # <https://www.gnu.org/licenses/>. +GPG = gpg + # Prefix variables for silencing various commands. See "(automake) # Automake Silent Rules" for details. -EMACS_GEN = $(EMACS_GEN_$(V)) -EMACS_GEN_ = $(EMACS_GEN_$(AM_DEFAULT_VERBOSITY)) -EMACS_GEN_0 = @echo " EMACS" $@; -EMACS_GEN_1 = - GUILD_GEN = $(GUILD_GEN_$(V)) GUILD_GEN_ = $(GUILD_GEN_$(AM_DEFAULT_VERBOSITY)) GUILD_GEN_0 = @echo " GUILD " $@; @@ -50,7 +47,7 @@ CLEANFILES = xapian.i xapian_wrap.cc xapian/wrap.scm xapian.i: xapian.i.in Makefile sed -e 's|@libdir[@]|$(libdir)|g' -e 's|@GUILE_EFFECTIVE_VERSION[@]|$(GUILE_EFFECTIVE_VERSION)|g' $< > $@ -xapian_wrap.cc xapian/wrap.scm &: xapian.i xapian-head.i xapian-headers.i +xapian_wrap.cc xapian/wrap.scm &: xapian.i xapian-head.i xapian-headers.i except.i std_string_view.i $(MKDIR_P) xapian $(SWIG_GEN)$(SWIG) $(SWIG_FLAGS) -I$(srcdir) -scmstub -o xapian_wrap.cc -guile -package xapian -c++ $< @@ -59,7 +56,7 @@ xapian_wrap.cc xapian/wrap.scm &: xapian.i xapian-head.i xapian-headers.i moddir = $(prefix)/share/guile/site/$(GUILE_EFFECTIVE_VERSION) godir = $(libdir)/guile/$(GUILE_EFFECTIVE_VERSION)/site-ccache -SOURCES = xapian/wrap.scm xapian/xapian.scm +SOURCES = xapian/error.scm xapian/wrap.scm xapian/xapian.scm GOBJECTS = $(SOURCES:%.scm=%.go) nobase_mod_DATA = $(SOURCES) @@ -77,23 +74,13 @@ xapian/xapian.go: xapian/xapian.scm libguilexapian-@GUILE_EFFECTIVE_VERSION@.la # Tests -TEST_EXTENSIONS = .scm -SCM_TESTS = tests/xapian.scm -TESTS = $(SCM_TESTS) +test_files = tests/examples.scm tests/smoketest.scm tests/xapian.scm -SCM_LOG_DRIVER = \ - $(builddir)/pre-inst-env \ - $(GUILE) --no-auto-compile -s \ - $(builddir)/build-aux/test-driver.scm +check-local: + $(builddir)/pre-inst-env $(GUILE_RUN64) $(test_files) # Distribution -EXTRA_DIST = $(TESTS) $(SOURCES) xapian.i.in xapian-head.i xapian-headers.i - -# Build website - -website: website/index.html - -CLEANFILES += website/index.html -website/index.html: README.org - $(EMACS_GEN)$(EMACS) -Q --batch --load build-aux/build-home-page.el --funcall build-website +EXTRA_DIST = $(test_files) $(SOURCES) \ + examples/100-objects.sexp examples/index.scm examples/search.scm \ + except.i std_string_view.i xapian.i.in xapian-head.i xapian-headers.i diff --git a/NEWS b/NEWS index 702e262..9111785 100644 --- a/NEWS +++ b/NEWS @@ -1,10 +1,50 @@ -*- org -*- #+TITLE: guile-xapian NEWS – History of user-visible changes -Copyright © 2022 Arun Isaac <arunisaac@systemreboot.net> +Copyright © 2022–2024, 2026 Arun Isaac <arunisaac@systemreboot.net> Please send guile-xapian bug reports to arunisaac@systemreboot.net +Changes in 0.5.0 and later are in the git tag messages. + +* Changes in 0.4.0 (since 0.3.1) +** Features +*** New higher level field processors +New higher level field processors that wrap FieldProcessor, +RangeProcessor and DateRangeProcessor are now available. You can now +write these field processors conveniently in Scheme. +*** parse-query accepts boolean prefixes, range processors and a few common query parser flags +*** New query function +new-Query is now exposed as the more Scheme-like query function. +** Noteworthy bug fixes +*** mset-snippet and mset-sxml-snippet now actually work + +* Changes in 0.3.1 (since 0.3.0) +** Noteworthy bug fixes +*** Catch C++ xapian exceptions and raise them as scheme exceptions + +* Changes in 0.3.0 (since 0.2.1) +** New dependencies +guile-xapian now depends on guile-lib for (htmlprag) used in the new +mset-sxml-snippet function. +** Features +*** Allow indexing text without position information +The index-text! function now optionally allows indexing text without +position information using a new #:positions? keyword argument. +*** Support combining queries with OR, AND and FILTER operators +We introduce new query-and, query-or and query-filter functions that +combine queries using the OR, AND and FILTER operators. +*** Support generation of SXML snippets +We introduce mset-sxml-snippet, a function that can generate snippets +in SXML form. + +* Changes in 0.2.1 (since 0.2.0) +** Noteworthy bug fixes +*** Distinguish libguilexapian based on Guile effective version +We suffix libguilexapian with the Guile effective version in order to +support simultaneous installation of guile-xapian for Guile 3.0 and +guile-xapian for Guile 2.2. + * Changes in 0.2.0 (since 0.1.0) ** Noteworthy bug fixes *** Look for libguilexapian.so under .libs diff --git a/README.org b/README.org index bf0aa25..1e7883f 100644 --- a/README.org +++ b/README.org @@ -2,16 +2,17 @@ #+OPTIONS: *:nil #+MACRO: ci-badge [[https://ci.systemreboot.net/jobs/$1][https://ci.systemreboot.net/badge/$1.svg]] -{{{ci-badge(guile-xapian-with-guile-2.2)}}} {{{ci-badge(guile-xapian-with-guile-3.0)}}} {{{ci-badge(guile-xapian-with-guile-3.0-latest)}}} {{{ci-badge(guile-xapian-website)}}} +{{{ci-badge(guile-xapian)}}} {{{ci-badge(guile-xapian-website)}}} guile-xapian provides Guile bindings for [[https://xapian.org][Xapian]], a search engine -library. Xapian is a highly adaptable toolkit which allows developers +library used in popular applications such as the [[https://notmuchmail.org/][notmuch]] email +system. Xapian is a highly adaptable toolkit which allows developers to easily add advanced indexing and search facilities to their own applications. It has built-in support for several families of weighting models and also supports a rich set of boolean query operators. -Once these bindings are sufficiently mature, they will be merged with +Once these bindings are sufficiently mature, they may be merged with [[https://github.com/xapian/xapian/tree/master/xapian-bindings][xapian-bindings]]. This will involve creating more complete Scheme-friendly wrapping of the Xapian library, writing test cases and documentation. When we are done, the user should not ever have to call @@ -23,9 +24,9 @@ There is no proper documentation yet. See the examples in the source tree. Also see [[https://getting-started-with-xapian.readthedocs.io/en/latest/index.html][Getting Started with Xapian]] which describes the Python bindings. -*Warning:* guile-xapian is in a very early stage of development and -the high level API in (xapian xapian) is not stable. It may change at -any time. +*Warning:* The high level API in (xapian xapian) has been relatively +stable for a while. However, it may still change. Keep an eye out on +the release notes. * Usage @@ -59,13 +60,29 @@ example searches. ./pre-inst-env guile examples/search.scm /tmp/db watch ./pre-inst-env guile examples/search.scm /tmp/db Dent watch ./pre-inst-env guile examples/search.scm /tmp/db title:sunwatch -./pre-inst-env guile examples/search.scm /tmp/db description:\"leather case\" AND title:sundial +./pre-inst-env guile examples/search.scm /tmp/db description:"leather case" AND title:sundial #+END_SRC +* Download + +[[https://repology.org/project/guile-xapian/versions][https://repology.org/badge/vertical-allrepos/guile-xapian.svg]] + +Download release tarballs. + +- 2026-10-08 [[./releases/guile-xapian-0.6.0.tar.lz][guile-xapian-0.6.0.tar.lz]] [[./releases/guile-xapian-0.6.0.tar.lz.asc][GPG Signature]] +- 2026-09-24 [[./releases/guile-xapian-0.5.0.tar.lz][guile-xapian-0.5.0.tar.lz]] [[./releases/guile-xapian-0.5.0.tar.lz.asc][GPG Signature]] +- 2024-05-10 [[./releases/guile-xapian-0.4.0.tar.lz][guile-xapian-0.4.0.tar.lz]] [[./releases/guile-xapian-0.4.0.tar.lz.asc][GPG Signature]] + +Download [[https://systemreboot.net/about/arunisaac.pub][public signing key]]. + +Browse the [[https://git.systemreboot.net/guile-xapian][development version]] of guile-xapian hosted in a git +repository. + * Contributing -Feedback, suggestions, feature requests and bug reports are all -welcome. Please write to me at [[mailto:arunisaac@systemreboot.net][arunisaac@systemreboot.net]]. +Feedback, feature requests, bug reports and patches are all welcome. +Please write to the public inbox at [[mailto:guile-xapian@systemreboot.net][guile-xapian@systemreboot.net]]. You +may also browse the [[https://lists.systemreboot.net/guile-xapian][archives]] of previous conversations. * Contributors Thanks to these wonderful people! :-) diff --git a/build-aux/test-driver.scm.in b/build-aux/test-driver.scm.in deleted file mode 100644 index 262d3a8..0000000 --- a/build-aux/test-driver.scm.in +++ /dev/null @@ -1,100 +0,0 @@ -;;; guile-xapian --- Guile bindings for Xapian -;;; Copyright © 2021 Arun Isaac <arunisaac@systemreboot.net> -;;; -;;; This file is part of guile-xapian. -;;; -;;; guile-xapian is free software: you can redistribute it and/or -;;; modify it under the terms of the GNU General Public License as -;;; published by the Free Software Foundation, either version 2 of the -;;; License, or (at your option) any later version. -;;; -;;; guile-xapian is distributed in the hope that it will be useful, -;;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -;;; General Public License for more details. -;;; -;;; You should have received a copy of the GNU General Public License -;;; along with guile-xapian. If not, see -;;; <https://www.gnu.org/licenses/>. - -;;; Commentary: - -;; This is a better test driver for Guile's (srfi srfi-64). -;; -;; TODO: Improve Guile's test driver so this module won't be -;; necessary. - -;;; Code: - -(use-modules (ice-9 format) - (ice-9 getopt-long) - (ice-9 match) - (srfi srfi-26) - (srfi srfi-64)) - -;; Currently, only log-file and trs-file are understood. Everything -;; else is ignored. -(define %options - '((test-name (value #t)) - (log-file (value #t)) - (trs-file (value #t)) - (color-tests (value #t)) - (expect-failure (value #t)) - (enable-hard-errors (value #t)))) - -(define (color code str color?) - (if color? - (format #f "~a[~am~a~a[0m" #\esc code str #\esc) - str)) - -(define red (cut color 31 <> <>)) -(define green (cut color 32 <> <>)) -(define magenta (cut color 35 <> <>)) - -(define (my-gnu-runner log-port trs-port color?) - (let ((runner (test-runner-null))) - (test-runner-on-group-begin! runner - (lambda (runner suite-name count) - (format #t (magenta "%%%% ~a~%" color?) suite-name))) - (test-runner-on-group-end! runner - (lambda _ - (newline))) - (test-runner-on-test-end! runner - (lambda (runner) - (let ((name (test-runner-test-name runner)) - (result (string-upcase - (symbol->string (test-result-kind runner)))) - (result-alist (test-result-alist runner))) - (format trs-port ":test-result: ~a ~a~%" result name) - (format #t "~a ~a~%" - (case (test-result-kind runner) - ((pass) (green result color?)) - (else (red result color?))) - name) - (format log-port "~a ~a~%" result name) - ;; If test did not pass, print details. - (unless (eq? (test-result-kind runner) 'pass) - (let* ((expected-value (match (assq-ref result-alist 'source-form) - (('test-assert _ ...) #t) - (_ (assq-ref result-alist 'expected-value)))) - (log-output - (format #f "~a:~a~%expected: ~s~%actual: ~s~%" - (assq-ref result-alist 'source-file) - (assq-ref result-alist 'source-line) - expected-value - (assq-ref result-alist 'actual-value)))) - (display log-output log-port) - (display log-output (current-error-port))))))) - runner)) - -(let ((opts (getopt-long (command-line) %options))) - (call-with-output-file (string-append "@abs_top_builddir@/" - (option-ref opts 'log-file #f)) - (lambda (log-port) - (call-with-output-file (option-ref opts 'trs-file #f) - (lambda (trs-port) - (chdir "@abs_top_srcdir@") - (test-with-runner (my-gnu-runner log-port trs-port - (string=? (option-ref opts 'color-tests "yes") - "yes")) - (load-from-path (option-ref opts 'test-name #f)))))))) diff --git a/configure.ac b/configure.ac index f0388c8..54a8e51 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ dnl guile-xapian --- Guile bindings for Xapian -dnl Copyright © 2020, 2021, 2022 Arun Isaac <arunisaac@systemreboot.net> +dnl Copyright © 2020–2024, 2026 Arun Isaac <arunisaac@systemreboot.net> dnl dnl This file is part of guile-xapian. dnl @@ -17,23 +17,25 @@ dnl You should have received a copy of the GNU General Public License dnl along with guile-xapian. If not, see dnl <https://www.gnu.org/licenses/>. -AC_INIT([guile-xapian], [0.2.0]) -AM_INIT_AUTOMAKE([color-tests -Wall -Wno-portability foreign check-news no-dist-gzip dist-lzip]) +AC_INIT([guile-xapian], [0.6.0]) +AM_INIT_AUTOMAKE([-Wall -Wno-portability foreign no-dist-gzip dist-lzip]) AM_SILENT_RULES([yes]) LT_INIT AC_PROG_CXX -AX_PKG_SWIG +AX_CXX_COMPILE_STDCXX(17) +AX_PKG_SWIG([4.2], [], [ AC_MSG_ERROR([swig >= 4.2 is required]) ]) GUILE_PKG([3.0 2.2]) PKG_CHECK_MODULES([GUILE], [guile-3.0],,[ PKG_CHECK_MODULES([GUILE], [guile-2.2]) ]) GUILE_PROGS -PKG_CHECK_MODULES([XAPIAN], [xapian-core]) +GUILE_MODULE_REQUIRED([htmlprag]) +PKG_CHECK_MODULES([XAPIAN], [xapian-core >= 2]) PKG_CHECK_MODULES([ZLIB], [zlib]) -# To build the website -AC_PATH_PROG([EMACS], [emacs]) +# For tests +AC_PATH_PROG([GUILE_RUN64], [guile-run64]) dnl pkg-config does not output xapian include flags when the include dnl path is already in CPATH. See @@ -44,5 +46,4 @@ AC_SUBST([SWIG_FLAGS], [$(PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 pkg-config --cflags x AC_CONFIG_FILES([Makefile]) AC_CONFIG_FILES([pre-inst-env], [chmod +x pre-inst-env]) -AC_CONFIG_FILES([build-aux/test-driver.scm]) AC_OUTPUT diff --git a/examples/100-objects-v1.csv b/examples/100-objects-v1.csv new file mode 100644 index 0000000..b8f8f77 --- /dev/null +++ b/examples/100-objects-v1.csv @@ -0,0 +1,101 @@ +id_NUMBER,ITEM_NAME,TITLE,MAKER,DATE_MADE,PLACE_MADE,MATERIALS,MEASUREMENTS,DESCRIPTION,WHOLE_PART,COLLECTION +1974-100,Pocket horizontal sundial,Ansonia Sunwatch (pocket compas dial),Ansonia Clock Co.,1922-1939,"New York county, New York state, United States",,,Ansonia Sunwatch (pocket compass dial),WHOLE,SCM - Time Measurement +1883-74,spring-driven clock mechanism; fusee; model,Model of train of wheels used in a clock (full size) with pa,,,,,,Model of train of wheels used in a clock (full size) with pair of vanes and base,WHOLE,SCM - Time Measurement +1953-404,log (nautical instrument); sandglass,Ship's log-glass in wooden mount. 14 secs. Abbot Horne No.22,,,,glass; sand; mounted; wood; timer,,Ship's log-glass in wooden mount. 14 secs. Abbot Horne No.22. Type B,WHOLE,SCM - Time Measurement +1970-377,pocket watch; duplex watch,Watch with Chinese duplex escapement,,,,,,Watch with Chinese duplex escapement,WHOLE,SCM - Time Measurement +1979-5,,"""Ever Ready"" ceiling clock",Ever Ready Co. (maker),,,,"overall: 140 mm x 124 mm x 152 mm,","""Ever Ready"" ceiling clock",WHOLE,SCM - Time Measurement +1938-371,diptych sundial,Ivory diptych dial by Jasper Milner,"Milner, Jasper",1501-1600,,dial: ivory,,Ivory diptych dial by Jasper Milner,WHOLE,SCM - Time Measurement +1883-64,deadbeat escapement; clock mechanism; model,Dead-beat escapement model (full size) with wooden stand.,,,,stand: wood,,Dead-beat escapement model (full size) with wooden stand.,WHOLE,SCM - Time Measurement +1953-448,sand glass,"Large single sand-glass in wooden mount, 21 1/2"" long x 11""",,,,overall: glass; mount: wood,overall: 555 mm x 275 mm,"Large single sand-glass in wooden mount, 21 1/2"" long x 11"" diameter. Abbot Horne No.111. Type A",WHOLE,SCM - Time Measurement +1985-438,Spring driven pendulum clock,Copy of a Dwerrihouse skeleton clock with coup-perdu escape,Thwaites and Reed Ltd. (maker),1973,"London, England, United Kingdom","brass (copper, zinc alloy); steel (metal); wood (unidentified)","overall: 380 mm x 300 mm x 192 mm, weight: 6.45kg","Copy of a Dwerrihouse skeleton clock with coup-perdu escapement. Made by Thwaites and Reed, London, England, 1973. No. 88 of a limited edition of 100.",WHOLE,SCM - Time Measurement +1985-475,Electrically driven pendulum clock,"Synchronome free pendulum clock, patented by F. Hope-Jones i",Synchronome Co. Ltd. (maker),,"London, Greater London, England, United Kingdom",,"overall: 1350 mm x 364 mm x 200 mm,","Synchronome free pendulum clock, patented by F. Hope-Jones in 1935, in oak case, lacks both pendulums, with weight (probably not original)",WHOLE,SCM - Time Measurement +1985-770,sand glass,"""Timetrunk"" by Hines and Co., Glasgow (a sandglass for timin",Hines and Co. (maker),,"Glasgow, Scotland, United Kingdom",,"overall: 182 mm x 40 mm x 40 mm,","""Timetrunk"" by Hines and Co., Glasgow (a sandglass for timing telephone calls)",WHOLE,SCM - Time Measurement +1985-1202,clock,Assembled and unassembled EXA electric clock kit,EXA,1931-1939,Belgium,"brass (copper, zinc alloy); steel (metal); cardboard; wood (unidentified)",overall: 170 mm x 132 mm x 154 mm,"Electric clock kit in original box and a similar clock which has been assembled, by EXA, Belgium, 1931-1939. Support stand broken on finished dock. Lid of box containing finished clock missing.",TOP,SCM - Time Measurement +1985-1538,,Watch timer by P,P.L. Instruments Ltd. (maker),,,,,"Watch timer by P.L. Instruments Ltd., Welwyn Garden City; with tuning fork standard and spark printer",WHOLE,SCM - Time Measurement +1985-1389,Plate horizontal sundial,"Horizontal sundial in bronze dated, 1551 with initials W.B.","Gemini, Thomas",1551,,,,"Horizontal sundial in bronze dated, 1551 with initials W.B. (? William Buckley). Possibly by Thomas Gemini",WHOLE,SCM - Time Measurement +1985-1914,pocket watch,"Ingersoll ""Dan Dare"" automaton pocket watch with pin-pallet",Ingersoll (maker),1953,,,overall: 65 x 12 x 52 mm,"Ingersoll ""Dan Dare"" automaton pocket watch with pin-pallet lever escapement. The dial shows a helmeted Dan Dare holding a ray gun, with a monster approaching. The emblem of the "" Eagle"" children's comic is impressed in the back of case.",WHOLE,SCM - Time Measurement +1985-172,Sundial model,Copy of the gearing of the Byzantine sundial-calendar (1983-,,,,,,"Copy of the gearing of the Byzantine sundial-calendar (1983-1393) three times true size, conjecturally completed, in perspex and brass",WHOLE,SCM - Time Measurement +1955-303,Cylinder sundial,"Column dial by Henry Robert, Horloger, au Palais Royal, pape","Robert, Henry (maker)",1831-1870,"Paris, Ville de Paris, Île-de-France, France",,,"Column dial by Henry Robert, Horloger, au Palais Royal, paper on wood, early 19th century",WHOLE,SCM - Time Measurement +1987-1145,pocket watch,Solar/Sidereal verge watch with epicyclic maintaining power,"Green, James (maker)",,"London, Greater London, England, United Kingdom",,,"Solar/Sidereal verge watch with epicyclic maintaining power by James Green, London, no. 5969, in silver pair case hallmarked 1776, believed to be the earliest English watch to indicate solar and sidereal time with seconds.",WHOLE,SCM - Time Measurement +1876-19,photograph,Photograph of Dent's chronometer with glass balance spring,School of Military Engineering,1870-1876,"Chatham, Medway, England, United Kingdom",,photograph (excluding mount): 285 x 230 mm,"Photograph (portrait) of Dent's chronometer with glass balance spring, taken by the School of Military Engineering, Chatham, Kent, England, 1870-1876",WHOLE,SCM - Time Measurement +1876-70,drawing,"Drawing Representing Galileo's Proposal for the Application of the Pendulum to the Clock, 1659, copy","Viviani, Vincenzo",1659,Italy,paper (fibre product),overall: 500 mm x 420 mm,"Copy of the drawing representing Galileo's idea of the application of the pendulum to the clock, 1659.",WHOLE,SCM - Time Measurement +1876-322,polyhedral sundial; reproduction,Ancient stone sundial - plaster cast,,,,casting plaster; polyhedral; chronological; replication,overall: 320 mm high,Ancient stone sundial - plaster cast,WHOLE,SCM - Time Measurement +1876-377,chronograph - timer,"Bashforth's Chronograph with screens, frame and weights, inv","Bashforth, Rev. Francis",1865-1875,"Horncastle, Lincolnshire, England, United Kingdom",paper (fiber product); cord (fiber product); cotton fibre; thread; brass (alloy); copper; wood; rotating; vertical; cylindrical; electrical properties; electromagnetic; timer; regulated,,"Bashforth's Chronograph with screens, frame and weights, invented c. 1865.",WHOLE,SCM - Time Measurement +1876-950,,"Description of the Chronograph, given by Mr",,,,,,"Description of the Chronograph, given by Mr. Bashforth (Note:- may be accepted as presented with the chronograph)",WHOLE,SCM - Time Measurement +1879-32,regulator clock; gravity escapement,Regulator Clock with Gravity Escapement,"Bloxam, J. M.",1845-1855,,"steel (metal); cast iron; mercury; wood (unidentified); brass (copper, zinc alloy); glass",overall: 1850 mm x 350 mm x 250 mm,"Clock with gravity escapement constructed by Mr. J. M. Bloxam, 1845-1855.",WHOLE,SCM - Time Measurement +1880-29,universal ring sundial,"Universal ringdial brass (part silvered), diameter 8 1/2"", b",,1701-1800,France,brass (alloy); silvered; adjustable; chronological,brassplate: 86 mm square; ringdial diameter: 216 mm,"Universal ringdial brass (part silvered), diameter 8 1/2"", brassplate 3 3/8 In. square, French, 18th century",WHOLE,SCM - Time Measurement +1880-30,equinoctial sundial,Sundial and compass with perpetual calendar and lunar circles,"Köhler, Christopher",1677,"Dresden, Germany","brass (copper, zinc alloy); silvered; glass","overall: 180 mm x 136 mm x 175 mm, weight: 0.93kg","Sundial and compass with perpetual calendar and lunar circles. Brass, part silvered, 6 1/8 x 5 3/8-inches. By Christopher Kohler, Dresden, Germany, 1677. Glass of compass box cracked, compass needle missing.",WHOLE,SCM - Time Measurement +1880-31,sundial,Sundial,"Langlois, Claude",1730-1751,France,,overall: 203 mm x 175 mm,"Sundial, Brass, gromon and heads of levelling screws gilt. Plate 8 in. by 6 7/8 in. Invented by Julien le Roy. Made by Langlois, French. 1730-1751",WHOLE,SCM - Time Measurement +1880-34,Horizontal sundial,"Sundial with separate compass. Brass gilt 8 5/8"" by 7 1/2"".","Weiss, Godfried (maker)",1671-1730,Germany,,,"Sundial with separate compass. Brass gilt 8 5/8"" by 7 1/2"". Compass plate 3in. square. By Godfried Weiss, German, late 17th or early 18th century",WHOLE,SCM - Time Measurement +1880-35,string style horizontal sundial,"Sundial and compass, brass gilt, dial plate 10 3/4in. by 8 3","Knitl, Franz Antoni",1671-1730,"Linz, Oberösterreich, Austria",brass; gilding; horizontal; chronological; rotating; magnetic; inscription; engraved,dial plate: 273 x 223 mm,"Sundial and compass, brass gilt, dial plate 10 3/4in. by 8 3/4in. Engraved ""Franz Antoni Knitl Linz, fecit"". Austrian, late 17th or early 18th century",WHOLE,SCM - Time Measurement +1985-2001,Universal equinoctial sundial,"A universal equinoctial sundial signed ""Carl Von Mandern fec","Mandern, Carl Von (maker)",1701-1800,"Copenhagen, Denmark",,overall: 210 mm x 205 mm,"A universal equinoctial sundial signed ""Carl Von Mandern fecit Hafnia"" (Copenhagen), 18th century",WHOLE,SCM - Time Measurement +1985-2021,Folding equinoctial compass sundial,"Portable universal equinoctial sundial, in brass, signed ""A","Ryther, A. (maker)",1588,"London, Greater London, England, United Kingdom",gilded brass; silvered; mica,overall diameter: 50 mm,"Portable universal equinoctial sundial, in brass, signed ""A Ryther * Fecit * 1588"" with inscription ""WILLIAM PAWLEY OWETH THIS SAME IN ANNO DOMINI 1588"". Diameter 50mm. With compass needle (not original).",WHOLE,SCM - Time Measurement +1969-479,water clock,"Glass Bowl Replicating an Egyptian Water Clock, 1940-1965",Whitefriars Glass Ltd. (maker),1940-1965,"Wealdstone, Harrow, Greater London, England, United Kingdom",,,"Glass bowl in the shape of an ancient Egyptian water-clock, 1940-1965",WHOLE,SCM - Time Measurement +1986-516,,A device by Favag of Neuchatel which enables a stop watch to,Favag (maker),1961,"Neuchâtel, Neuchâtel, Switzerland",,"overall: 112 mm x 108 mm x 118 mm,","A device by Favag of Neuchatel which enables a stop watch to be operated by an electric signal, 1961",WHOLE,SCM - Time Measurement +1986-279,,"""Ticket"" clock by Ever-Ready in mahogany case with reeded br",Ever Ready Co. (maker),1915,,,"overall: 162 mm x 166 mm x 120 mm,","""Ticket"" clock by Ever-Ready in mahogany case with reeded brass pillars, c.1915",WHOLE,SCM - Time Measurement +1986-1153,,Synchronome master clock (No,Synchronome Co. Ltd. (maker),,"London, Greater London, England, United Kingdom",,"overall: 1260 mm x 270 mm x 148 mm,","Synchronome master clock (No.6133), fitted with a seconds switch and a centre seconds slave dial. With a battery charger",WHOLE,SCM - Time Measurement +1986-91,wrist-watch; calendar watch,Universal 'Tri-Compax' chronographic wrist watch,Universal (maker),1960-1986,"Geneva, Switzerland","leather; gold (metal); glass; brass (copper, zinc alloy); metal (unknown)","overall: 12 mm x 226 mm x 37 mm, weight: 0.05kg","'Tri-Compax' calendar chronograph wristwatch in gold case, by Universal, Geneva, Switzerland, 1960-1986.",WHOLE,SCM - Time Measurement +1986-1553,,"""Silent Triangle"" 1/2 minute impulse dial movement by Gents",Gent and Co. Ltd. (maker),,"Leicester, England, United Kingdom","brass (copper, zinc alloy); copper (alloy); steel (metal); plastic (unidentified); cotton (fibre)","overall: 51 mm x 95 mm x 80 mm, 0.371kg","""Silent Triangle"" 1/2 minute impulse dial movement by Gents of Leicester, patented 1925",WHOLE,SCM - Time Measurement +1986-1695,dipleidoscope,"Dipleidoscope, signed Plossl In Wien",Plossl (maker),,"Wien, Austria",,overall: 165 mm x 95 mm,"Dipleidoscope, signed Plossl In Wien",WHOLE,SCM - Time Measurement +1987-213,,Electric clock of the Bain type,"Bain, Alexander",1840-1877,,,"overall: 405 mm x 205 mm x 195 mm,",Electric clock of the Bain type,WHOLE,SCM - Time Measurement +1987-238,,Millisecond Stopclock type TSA3314 by Venner Electronics Lim,Venner Electronics Ltd. (maker),1963,,,,"Millisecond Stopclock type TSA3314 by Venner Electronics Limited, 1963",WHOLE,SCM - Time Measurement +1987-239,,Frequency and time measuring instrument type TSA3436 by Venn,Venner Electronics Ltd. (maker),1956,,,,"Frequency and time measuring instrument type TSA3436 by Venner Electronics Limited, 1965 with cover",WHOLE,SCM - Time Measurement +1987-241,,"MKV11b quartz timer by Hurd-Brown Limited, Bolton c.1955",Hurd-Brown Ltd. (maker),c. 1955,"Bolton, Bolton borough, Greater Manchester, England, United Kingdom; Lancashire, England, United Kingdom",,"overall: 260 mm x 270 mm x 537 mm,","MKV11b quartz timer by Hurd-Brown Limited, Bolton c.1955",WHOLE,SCM - Time Measurement +1987-240,automatic timer,Loughborough-Hayes automatic timing apparatus. Used by the R,,,,,,Loughborough-Hayes automatic timing apparatus. Used by the RAC to time motor sporting events from 1936 to 1962. Comprising; 1) Rythmic starter motor and lights. 2) Start and finish photocells. 3) 2 `hockey stick' switches. 4) Tuning fork. 5) Amplifier for maintaining the tuning fork and driving the chronography. 6) Chronograph. 7) Control box. 8) Connecting wires and loudspeaker,WHOLE,SCM - Time Measurement +1987-294,,Two-dial clock by the Self-Winding Clock Co; as used on the,Self-Winding Clock Co. (maker),,,,,Two-dial clock by the Self-Winding Clock Co; as used on the London underground,WHOLE,SCM - Time Measurement +1987-295,,"Master clock of the ""Silent Electric"" type made by the Magne","British Vacuum Cleaner and Engineering Co. Ltd., Magneto Time division (maker)",,,,"overall: 1600 mm x 315 mm x 170 mm,","Master clock of the ""Silent Electric"" type made by the Magneto Time division of the British Vacuum Cleaner and Engineering Co. Ltd.",WHOLE,SCM - Time Measurement +1883-68,model - representation; pocket watch,Model by Dent of mechanism for setting hands and winding up,E. Dent & Co.,,,,"overall: 170 mm 56 mm,",Model by Dent of mechanism for setting hands and winding up a keyless watch,WHOLE,SCM - Time Measurement +1984-633,escapement models,"Model of Swiss lever escapement, and clockwork winding key",,,,,,"Model of Swiss lever escapement, and clockwork winding key",WHOLE,SCM - Time Measurement +1984-1143,Synchronous motor clock,Synchronous mains electric clock of the non self-starting ty,Ferranti Ltd.,c. 1936,,,,Synchronous mains electric clock of the non self-starting type by Ferranti with 24 hour alarm and illuminated dial c.1936,WHOLE,SCM - Time Measurement +1984-1275,balance wheel digital wristwatch,"Digital wristwatch with ""jumping hour"", lever escapement, Sw",,1932,,,,"Digital wristwatch with ""jumping hour"", lever escapement, Swiss, c.1932",WHOLE,SCM - Time Measurement +1984-1415,solar powered quartz analogue wristwatch,"Quartz Analogue ""no battery"" wristwatch by Pulsar Quartz (CA",Pulsar Quartz (maker),1984,,,"overall: 105 mm x 75 mm x 57 mm,","Quartz Analogue ""no battery"" wristwatch by Pulsar Quartz (CAL. V103), 1984, in presentation box, powered by an amorphous silicon photocell with reserve power provided by a capacitor.",WHOLE,SCM - Time Measurement +1984-1611,Quartz clock,"Analogue quartz clock with voice controlled alarm by Braun,",Braun (maker),1984,,,"overall: 85 mm x 65 mm x 38 mm,","Analogue quartz clock with voice controlled alarm by Braun, 1984, type 47763/AB30vs with original packing and instructional manual, supplied by Selfridges",WHOLE,SCM - Time Measurement +1974-386,astronomical clock; replica,"Reconstruction of Dondi's Astronomical Clock, 1974",Thwaites and Reed Ltd.,1974,"Brighton, Brighton and Hove, England, United Kingdom","ink; brass (copper, zinc alloy); steel (metal)","clock: 1185 x 780 mm, 122 kg; rewind unit: 460 x 640 x 350 mm","Reconstruction of Dondi clock, which represents a working model of the universe. Its movements, dials and calender are kept in motion by the weight driven clock, 1974",WHOLE,SCM - Time Measurement +1984-1688,,Electric clock of the bulle type probably made by The Britis,British Horo-Electric Ltd. (maker),1930-1939,,,,"Electric clock of the bulle type probably made by The British Horo Electric Company, 1930' s",WHOLE,SCM - Time Measurement +1985-73,Mean-time sundial,"Sol-horometer, by Pilkington and Gibbs, Preston, design pate",Pilkington and Gibbs Ltd. (maker),,"Preston, Lancashire, England, United Kingdom",,overall: 245 mm x 235 mm,"Sol-horometer, by Pilkington and Gibbs, Preston, design patented in 1911",WHOLE,SCM - Time Measurement +1985-100,Horizontal quadrant altitude sundial,Silver altitude sundial in leather case,"Cole, Humfrey",1568-1590,"London, England, United Kingdom",silver (metal); leather; possibly bronze or brass,"overall: 23 mm x 93 mm x 86 mm, weight: 0.16kg","Altitude sundial, in silver, for latitude 51°30 secs. (London), signed Humfray Colle, in original tooled leather case, by Humfrey Cole, London, England, 1568-1590 (see note).",WHOLE,SCM - Time Measurement +1907-153,sand glass,"Single sandglass in 4 pillared wood mount, running time 15 1",,,,,overall: 138 mm x 71 mm,"Single sandglass in 4 pillared wood mount, running time 15 1/2 minutes, Horne Type B, height 138mm.",WHOLE,SCM - Time Measurement +1909-135,,"Electric clock by Alexander Bain, in case","Bain, Alexander",,,,,"Electric clock by Alexander Bain, in case",WHOLE,SCM - Time Measurement +1909-199,chronosphere; terrestrial globe,"The ""Empire"" clock, to show the time at various longitudes,",,,,,,"The ""Empire"" clock, to show the time at various longitudes, with parts",WHOLE,SCM - Time Measurement +1909-474,electrically-corrected subsidiary clock,Electrically operated clock controller,"Lund, J.",1876-1905,United Kingdom,"wooden base; brass (copper, zinc alloy); steel (metal); enamel; glass",overall: 270 mm x 280 mm x 150 mm,"Electrically operated clock controller by J. Lund, United Kingdom, 1876-1905.",WHOLE,SCM - Time Measurement +1911-209,sand glass,Sand glass (old sermon glass),,,,glass; sand,,Sand glass (old sermon glass),WHOLE,SCM - Time Measurement +1912-224,electrically-driven pendulum master clock; self-winding mechanism,Van der Plancke master clock,La Précision Cie,patented 1885,"Brussels, Belgium, Belgium",,"overall: 165 mm x 110 mm x 95 mm,",Van der Plancke master clock,WHOLE,SCM - Time Measurement +1912-225,electrically-driven subsidiary clock; impulse dial mechanism,Van der Plancke impulse dial mechanism,La Précision Cie,patented 1885,"Brussels, Belgium","brass (copper, zinc alloy); steel (metal); copper (alloy); plastic (unidentified); textile","overall (lying flat): 75 mm x 116 mm x 81 mm, 0.573kg",Van der Plancke impulse dial mechanism,WHOLE,SCM - Time Measurement +1912-228,electrically-driven subsidiary clock; impulse dial mechanism,"Peyer Favarger, Hipp dial movement","Favarger, Peyer",,,,,"Peyer Favarger, Hipp dial movement",WHOLE,SCM - Time Measurement +1912-230,electrically-driven subsidiary clock; impulse dial mechanism,"Morse electrical clock, dial mechanism","Morse, J. S.",patented 1903,,,overall: 95 mm x 105 mm,"Morse electrical clock, dial mechanism",WHOLE,SCM - Time Measurement +1913-564,,Electric time piece with hands but without dial (no pendulum,,,,,,Electric time piece with hands but without dial (no pendulum),WHOLE,SCM - Time Measurement +1880-40,equatorial sundial; horizontal ring sundial,"Sundial, brass, baseplate 7 1/4in. by 6in., late 17th centur","Kolwein, M.",1671-1700,"Vienna, Wien, Austria",tilted; mounted; horizontal; chronological; brass (alloy); inscription; engraved,height: 160 x width: 155 x depth: 185 x dial diameter: 135 mm,"Sundial, brass, baseplate 7 1/4in. by 6in., late 17th century. Engraved (M. Kolwein fecit Vienna 48 Gral 14 min)",WHOLE,SCM - Time Measurement +1880-42,nocturnal,"Nocturnal, brass gilt, diameter 2 3/4in. Italian, early 17th",,1601-1700,,brass; gilding,diameter: 70 mm,"Nocturnal, brass gilt, diameter 2 3/4in. Italian, early 17th century",WHOLE,SCM - Time Measurement +1880-44,perpetual calendar,Ornate brass Perpetual Calendar,,1801-1830,France,"brass (copper, zinc alloy); silvered","overall: 5 mm x 93 mm x 136.525 mm, weight: 0.175kg","Perpetual Calendar, brass scroll-work chased. Revolving plates silvered. Length 5 3/8-inches. Made in France, 1801-1830.",WHOLE,SCM - Time Measurement +1880-45,mechanical equinoctial sundial,"Sundial, brass, originally silvered, base plate 9in. by 6 7/","Modestin, Joseph",1701-1800,Czech Republic,brass (alloy); inscription; engraved; chronological; tilted,overall: 180 mm x 175 mm x 260 mm,"Sundial, brass, originally silvered, base plate 9in. by 6 7/8in. Engraved Joseph Modestin in Chindin (Bohemia), German, 18th century. Sights of alidate and one small brass screen missing",WHOLE,SCM - Time Measurement +1880-46,equinoctial sundial,"Sundial with compass, brass gilt, silvered circles. Diameter","Toda, M.",1671-1700,Germany,brass (alloy); gilding; circles (plane figures); ornament; silvered; inscription; engraved; glass; adjustable; chronological,diameter: 153 mm,"Sundial with compass, brass gilt, silvered circles. Diameter 6in. Engraved No.116 Se 61812, Toda M. Uda Rymoe. German, late 17th century (cover glass of compass box cracked)",WHOLE,SCM - Time Measurement +1883-95,mechanical clock components; striking clock mechanism,Clock with pendulum showing action of snail plate and repeat,,,,,overall: 980 mm,Clock with pendulum showing action of snail plate and repeater.,WHOLE,SCM - Time Measurement +1883-120,perpetual calendar,German Perpetual Calendar in gilt metal,,1701-1800,Germany,metal (unknown); gilding,"overall: 12 mm x 65 mm x 63.5 mm, weight: 0.035kg","Perpetual calendar, gilt metal, 2½ x 9/16-inches, Germany, 1701-1800.",WHOLE,SCM - Time Measurement +1883-121,equinoctial sundial,Universal pocket sundial,"Martin, Johann",1701-1721,"Augsburg, Germany",silver (metal); silver gilt,"overall: 15 mm x 44.45 mm, weight: 0.055kg","Universal pocket sundial, silver with gilt hour ring and pin gnomon, diameter 1¾-inches, by Johann Martin, Augsburg, Germany, 1701-1721 (see note).",WHOLE,SCM - Time Measurement +1883-122,universal equinoctial sundial,"Sundial, made as a locket, gilt metal, part silver","Cocart, Juan",1596,"Madrid, Spain",metal (unknown); gilt; silver,"overall: 13 mm x 44.45 mm x 44.45 mm, weight: 0.095kg","Sundial, made as a locket, gilt metal, part silver, 1¾-inches square, by Juan Cocart, madrid, Spain, 1596 (see note).",WHOLE,SCM - Time Measurement +1883-124,sundial,"Column Sundial in Gilt Bronze, Unsigned, 1531-1570",Unknown maker,1531-1570,"Augsburg, Schwaben, Bavaria, Germany",bronze; gilding; vertical; cubic; cylindrical; horizontal; rotating; magnetic; chronological; imagery; engraved,"overall: 228.6 mm x 50.8 mm diameter, weight: 0.8kg","Column sun-dial, gilt bronze (639-65). 9in. high, diam. of pillar = 2in. V and A. Museum Reg. Imperfect, no compass or cover glass, 1531-1570",WHOLE,SCM - Time Measurement +1883-128,sundial,"Italian Cubical Sundial, Unsigned, 1550-1570",Unknown maker,1550-1570,Italy,"brass (copper, zinc alloy); wood; painting (coating); arabesques; patterns (design elements); chronological; cubic","overall: 215.9 mm x 160 mm x 133 mm, weight: 0.95kg","Cubical sun-dial (30-81 V. and A. M. Reg), in wood, painted in distemper, Italian, 1550-1570.",WHOLE,SCM - Time Measurement +1883-132,sundial,"Column Sundial with Dragon Design, Unsigned, 1601-1700",Unknown maker,1601-1700,Europe,"bronze (copper, tin alloy) gilt; metal; chronological; motif; mounted; gilding; cylindrical; square (geometric figure); chronological","overall: 231.775 mm x 115 mm x 75 mm, weight: 1.2kg","Column sun-dial (21-1879 V and A. M. Reg), height 9 1/8inches, 1601-1700, gilt metal, on square base, surmounted by figure of dragon",WHOLE,SCM - Time Measurement +1883-137,horizontal sundial,Brass sundial,"Bion, Nicolas",1680-1733,"Paris, France","brass (copper, zinc alloy); glass","overall: 13 mm x 120 mm x 89 mm, weight: 0.12kg","Pocket sun-dial, brass, by Nicolas Bion, Paris, France, 1680-1733.",WHOLE,SCM - Time Measurement +1883-139,Universal horizontal sundial,"Sun-dial Brass, French (23-79 V. and A. M. Reg), late 17th o",,1671-1730,,,"overall: 210 mm x 195 mm x 325 mm,","Sun-dial Brass, French (23-79 V. and A. M. Reg), late 17th or early 18th century with four levelling screws (compass needle and gloves missing)",WHOLE,SCM - Time Measurement +1883-140,sundial,Tablet sun-dial in gilt metal,,1597,Germany,metal (unknown); gilding; string,"overall: 11 mm x 61 mm x 85 mm, weight: 0.185kg","Tablet sun-dial, gilt metal, string gnomon, 3 3/8 x 2 3/8-inches, Germany, 1597. For use at latitude 50°. Engraved on base with circular tables of Julian and Gregorian epacts 1597-1615, and lunar circle. Bead threaded onto gnomon allows determination of planetary or Jewish hours (see note).",WHOLE,SCM - Time Measurement +A616989,bistouries,,Eggington (maker),1801-1900,"Manchester, Manchester urban district, Greater Manchester, England, United Kingdom",steel; ebony,length 168 mm; width 5 mm; height 20 mm,"Bistoury, curved and probe-ended, steel and ebony, by Eggington of Manchester, 19th century",WHOLE,SCM - Surgery +1884-79,regulator clocks; weight-driven pendulum clocks; grasshopper escapements,"Movement of regulator clock by Vulliamy, about 1760","Vulliamy, Benjamin, 1747-1811",1760,"London, Greater London, England, United Kingdom",escapement pallets: hardwood; case: mahogany; glass,,"Clock made by Benjamin Vulliamy for His Majesty George III, and used in his Observatory at Kew. In polished mahogany case, with a side plate and glass top for case",WHOLE,SCM - Time Measurement +1884-80,weight-driven pendulum clocks; anchor escapements,"Harrison's eight-day wooden clock movement, 1715.","Harrison, John (maker)",1715,Barrow-upon-Humber; Lincolnshire; England,frame and wheelwork (not escape wheel): oak; pinions and arbors: boxwood; pivots: steel; brass,,"Original eight day clock by Harrison, date 1715, wheel work mostly of wood. With correspondence concerning Harrison clocks",WHOLE,SCM - Time Measurement +1887-13,magnetic horizontal sundial,Magnetic sundial in brass case,,1801-1900,"England, United Kingdom","brass (copper, zinc alloy); silvered brass; agate; glass","overall: 40 mm x 95.25 mm, weight: 0.385kg","Horizontal, magnetic sundial, silvered, in brass case, diameter 3.75-inches, dial made in England, 1801-1900 (see note).",WHOLE,SCM - Time Measurement +1887-27,chronograph - timer,Boulenges chronograph for the determination of the velocity,"Boulengé, P. le",1867,"Liège, Wallonia, Belgium",record tubes: zinc,,"Boulenges chronograph for the determination of the velocity of projectiles, with zinc tubes for records, includes additional zinc tubes and an illustration",WHOLE,SCM - Time Measurement +1883-67,chronometer; instrument component; model - representation,"Model representing Earnshaw's detent chronometer escapement, 1950-1883",E. Dent & Co.,1950-1883,"London, Greater London, England, United Kingdom","brass (copper, zinc alloy); glass; steel (metal); metal (unknown)",overall: 1150 mm x 65 mm,"Model of chronometer escapement, for use with a projecting latern, made by Dent, 1950-1883. Represents the detent chronometer escapement, invented by Thomas Earnshaw 1777-1787. This escapement was typically used in marine chronometers.",WHOLE,SCM - Time Measurement +1880-52,plate horizontal sundial; noon gun,"Sundial, Gnomon fixed on a cannon over touch hole of which a",,1782,France,cast bronze; glass,base: 216 mm square,"Sundial, Gnomon fixed on a cannon over touch hole of which a lens is fixed. French, 1782, of cast bronze. Base 8 1/2"" square",WHOLE,SCM - Time Measurement +1880-53,equatorial sundial; table azimuth sundial,Bloud sundial,"Bloud, Charles",1650-1686,"Dieppe, France",ivory; silver (metal),"overall: 16 mm x 63.5 mm x 82.55 mm, weight: 0.145kg","Tablet azimuth sundial, with compass, engraved. Ivory, 3¼ x 2½-inches, by Charles (Carolus) Bloud, Dieppe, France, 1650-1686. With equatorial dial in the upper leaf (see note).",WHOLE,SCM - Time Measurement +1880-54,diptych sundial,Diptych dials,,1648,Germany,"ivory; bronze (copper, tin alloy); string",overall: 19 mm x 63.5 mm x 107.95 mm,"Tablet sundial with compass, ivory with coloured engraving, 4¼ x 2½-inches, Germany, 1648 (see note).",WHOLE,SCM - Time Measurement +1880-55,diptych sundial,Tablet sundial of ivory,Unknown maker,1601-1700,Germany,"ivory; metal (unknown); string; bronze (copper, tin alloy)","overall: 11 mm x 69.85 mm x 76.2 mm, weight: 0.11kg","Tablet sundial with compass, engraved ivory, highly decorative with religious images, 3 x 2¾-inches, Germany, 1601-1700. With subsidiary dial (see note).",WHOLE,SCM - Time Measurement +1883-29,pendulum clocks; models,"Pendulum clock designed by Galileo in 1642 and made by his son in 1649, model.","Galilei, Galileo, 1564-1642; Galilei, Vincenzio, 1606-1649",1642-1649 (original); 1883 (model),Florence; Italy,"steel (metal); brass (copper, zinc alloy)","overall: 351 mm x 185 mm x 90 mm, weight: 2.4kg","Model showing the first idea of the application of the pendulum to the clock designed by Galileo in 1642, made his son Vincenzo in 1649 and illustrated by Vincenzo Viviani, Italy. This model is by Eustachio Porcellotti, Florence, Italy, 1883.",WHOLE,SCM - Time Measurement +1883-54,anchor escapement; clock mechanism; model,"Model of recoil escapement of clock, with pendulum and woode",,,,,,"Model of recoil escapement of clock, with pendulum and wooden stand, having a hollow cylindrical bob, marked ""Mech Lab 100""",WHOLE,SCM - Time Measurement +1883-65,mock-up; escapement,"Model of Graham's Cylinder Escapement, 1850-1883",E. Dent & Co.,1850-1883,"London, Greater London, England, United Kingdom","brass (copper, zinc alloy); steel (metal); glass","overall: 85 mm x 110 mm x 165 mm, 1.675kg","Model by Dent of Graham's cylinder escapement for use with lantern, 1850-1883",WHOLE,SCM - Time Measurement +1883-66,mock-up; escapement,"Model of a Lever Escapement , 1850-1883",E. Dent & Co.,1850-1883,"London, Greater London, England, United Kingdom","brass (copper, zinc alloy); glass","overall: 140 mm x 85 mm x 65 mm, 1.025kg","Model by Dent of lever escapement for use with lantern, 1850-1883",WHOLE,SCM - Time Measurement +1916-229,pocket watch; repeater - timepiece,1/4-repeater in case,Lieutaud,1803,"Aix-en-Provence, Bouches-du-Rhône, Provence-Alpes-Cote d'Azur, France",silver,,"1/4-repeater verge by Lieutand a Aix, in silver case, London, hall mark 1803, donated by Evan Roberts in 1916",WHOLE,SCM - Time Measurement +1913-567,electrically-driven clock; Hipp butterfly escapement,Clock with Hipp pendulum (an electric driven clock with Hipp,"Hipp, M.",,"Neuchâtel, Neuchâtel, Switzerland",,,Clock with Hipp pendulum (an electric driven clock with Hipp butterfly escapement) with a door of back of case,WHOLE,SCM - Time Measurement +1913-580,electrically-driven subsidiary clock,Bain's subsidiary electric clock,"Bain, Alexander",1875-1885,United Kingdom,"cast iron; brass (copper, zinc alloy); steel (metal); rope",overall: 259 mm x 375 mm x 225 mm,"Subsidiary electric clock (no weight, hands, pulley and suspension spring) by Alexander Bain, United Kingdom, 1875-1885.",WHOLE,SCM - Time Measurement +1913-581,movement - clockwork,'Pond' electric clock movement (no dial),Self Winding Clock Company,1905-1913,"New York, United States","cast iron; brass (copper, zinc alloy); steel (metal); leather",overall: 204 mm x 205 mm x 105 mm,"'Pond' electric clock (movement only, no dial), by Self Winding Clock Company, New York, United States, 1905-1913.",WHOLE,SCM - Time Measurement +1914-453,tower clock; weight-driven balance wheel clock,15th Century Iron striking clock with 17th century escapemen,,1401-1500; after 1650,,wrought iron,,"15th Century Iron striking clock with 17th century escapement and other later modifications (on stand). (Arrangement for driving hands incomplete, no driving weights) Including count wheel",WHOLE,SCM - Time Measurement +1914-887,diptych sundial,Wooden pocket sundial for use at various latitudes,,1776-1800,Germany,wood (unidentified); string,"overall: 16 mm x 50 mm x 81 mm, weight: 0.04kg","Wooden pocket sundial. Horizontal and vertical dials for use at various latitudes on moving style, Germany, 1776-1800 (see note).",WHOLE,SCM - Time Measurement diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 0000000..e903a24 --- /dev/null +++ b/examples/README.md @@ -0,0 +1 @@ +`100-objects-v1.csv` was obtained from https://raw.githubusercontent.com/xapian/xapian-docsprint/main/data/100-objects-v1.csv and converted to `100-objects.sexp` using `csv2sexp.py`. diff --git a/examples/csv2sexp.py b/examples/csv2sexp.py new file mode 100644 index 0000000..9fc09e0 --- /dev/null +++ b/examples/csv2sexp.py @@ -0,0 +1,30 @@ +### guile-xapian --- Guile bindings for Xapian +### Copyright © 2026 Arun Isaac <arunisaac@systemreboot.net> +### +### This file is part of guile-xapian. +### +### guile-xapian is free software: you can redistribute it and/or +### modify it under the terms of the GNU General Public License as +### published by the Free Software Foundation, either version 2 of the +### License, or (at your option) any later version. +### +### guile-xapian is distributed in the hope that it will be useful, +### but WITHOUT ANY WARRANTY; without even the implied warranty of +### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +### General Public License for more details. +### +### You should have received a copy of the GNU General Public License +### along with guile-xapian. If not, see +### <https://www.gnu.org/licenses/>. + +import csv, sys + +def write (str): + return '"{}"'.format(str.replace('"', '\\"')) + +print('(') +for row in csv.DictReader(sys.stdin): + print('({})'.format(' '.join([write(row['DESCRIPTION']), + write(row['TITLE']), + write(row['id_NUMBER'])]))) +print(')') diff --git a/except.i b/except.i new file mode 100644 index 0000000..a2486b8 --- /dev/null +++ b/except.i @@ -0,0 +1,50 @@ +/* guile-xapian --- Guile bindings for Xapian + * Copyright © 2023, 2026 Arun Isaac <arunisaac@systemreboot.net> + * + * This file is part of guile-xapian. + * + * guile-xapian is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 2 of the + * License, or (at your option) any later version. + * + * guile-xapian is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with guile-xapian. If not, see + * <https://www.gnu.org/licenses/>. + */ + +%{ +void handle_exception() { + string msg; + try { + throw; + } catch (const Xapian::Error &e) { + // TODO: Handle each Xapian error class separately and raise + // different scheme conditions for each. + msg = e.get_description(); + } catch (const std::exception &e) { + msg = "std::exception: "; + msg += e.what(); + } catch (...) { + msg = "unknown error in Xapian"; + } + scm_call_1(scm_c_public_ref("xapian error", "raise-xapian-exception"), + scm_from_stringn(msg.c_str(), + msg.length(), + "us-ascii", + SCM_FAILED_CONVERSION_ESCAPE_SEQUENCE)); +} +%} + +%exception { + try { + $action + } catch (...) { + handle_exception(); + } +} diff --git a/guix.scm b/guix.scm index fd87684..83600d1 100644..120000 --- a/guix.scm +++ b/guix.scm @@ -1,37 +1 @@ -;;; guile-xapian --- Guile bindings for Xapian -;;; Copyright © 2021 Arun Isaac <arunisaac@systemreboot.net> -;;; -;;; This file is part of guile-xapian. -;;; -;;; guile-xapian is free software: you can redistribute it and/or -;;; modify it under the terms of the GNU General Public License as -;;; published by the Free Software Foundation, either version 2 of the -;;; License, or (at your option) any later version. -;;; -;;; guile-xapian is distributed in the hope that it will be useful, -;;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -;;; General Public License for more details. -;;; -;;; You should have received a copy of the GNU General Public License -;;; along with guile-xapian. If not, see -;;; <https://www.gnu.org/licenses/>. - -;;; Run the following command to enter a development environment for -;;; guile-xapian: -;;; -;;; $ guix shell -Df guix.scm - -(use-modules (guix gexp) - (guix git-download) - (guix packages) - (gnu packages autotools) - (gnu packages guile-xyz)) - -(define %source-dir (dirname (current-filename))) - -(package - (inherit guile-xapian) - (source (local-file %source-dir - #:recursive? #t - #:select? (git-predicate %source-dir)))) +.guix/guile-xapian-package.scm \ No newline at end of file diff --git a/release-email.scm b/release-email.scm new file mode 100755 index 0000000..98748c9 --- /dev/null +++ b/release-email.scm @@ -0,0 +1,92 @@ +#! /usr/bin/env guile +!# + +;;; guile-xapian --- Guile bindings for Xapian +;;; Copyright © 2026 Arun Isaac <arunisaac@systemreboot.net> +;;; +;;; This file is part of guile-xapian. +;;; +;;; guile-xapian is free software: you can redistribute it and/or +;;; modify it under the terms of the GNU General Public License as +;;; published by the Free Software Foundation, either version 2 of the +;;; License, or (at your option) any later version. +;;; +;;; guile-xapian is distributed in the hope that it will be useful, +;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;;; General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with guile-xapian. If not, see +;;; <https://www.gnu.org/licenses/>. + +(use-modules (rnrs io ports) + (srfi srfi-1) + (srfi srfi-26) + (srfi srfi-28) + (srfi srfi-171) + (ice-9 match) + (ice-9 popen) + (web uri)) + +(define (call-with-input-pipe command proc) + "Call @var{proc} with input pipe to @var{command}. @var{command} is a +list of program arguments." + (match command + ((prog args ...) + (let ((port #f)) + (dynamic-wind + (lambda () + (set! port (apply open-pipe* OPEN_READ prog args))) + (cut proc port) + (lambda () + (unless (zero? (close-pipe port)) + (error "Command invocation failed" command)))))))) + +(let* ((version + (match (call-with-input-pipe (list "git" "tag") + (cut port-transduce + (tmap identity) + rcons + get-line + <>)) + (() + (error "No git tags found")) + (tags + (string-trim (last tags) #\v)))) + (body (format " +Hi all, + +guile-xapian ~a has been released. + +guile-xapian provides Guile bindings for Xapian[1], a search engine +library used in popular applications such as the notmuch email +system. Xapian is a highly adaptable toolkit which allows developers to +easily add advanced indexing and search facilities to their own +applications. It has built-in support for several families of weighting +models and also supports a rich set of boolean query operators. + +[1]: https://xapian.org/ + +Please find links to the project home page and tarball below. The +changes in this release are described in the NEWS file in the tarball. + +https://guile-xapian.systemreboot.net/ +https://guile-xapian.systemreboot.net/releases/guile-xapian-~a.tar.lz +https://guile-xapian.systemreboot.net/releases/guile-xapian-~a.tar.lz.asc + +Cheers! +" + version version version))) + (system* "xdg-open" + (string-append "mailto:guile-xapian@systemreboot.net?" + (string-join + (map (match-lambda + ((key . value) + (string-append key "=" (uri-encode value)))) + `(("to" . "guile-user@gnu.org") + ("subject" . ,(format "guile-xapian ~a released" + version)) + ("body" . ,body))) + "&")))) + diff --git a/std_string_view.i b/std_string_view.i new file mode 100644 index 0000000..cd3027e --- /dev/null +++ b/std_string_view.i @@ -0,0 +1,63 @@ +/* ----------------------------------------------------------------------------- + * std_string_view.i + * + * std::string_view typemaps for Guile + * ----------------------------------------------------------------------------- */ + +%{ +#include <string> +#include <string_view> +%} + +namespace std { + + %naturalvar string_view; + + %typemap(in) string_view (char *$1_ptr) { + size_t $1_len; + $1_ptr = scm_to_utf8_stringn($input, &$1_len); + $1 = std::string_view($1_ptr, $1_len); + } + + %typemap(freearg) string_view %{ + SWIG_free($1_ptr); + %} + + %typemap(out) string_view %{ + $result = scm_from_utf8_stringn($1.data(), $1.size()); + %} + + %typemap(in) const string_view& (char *$1_ptr, $*1_ltype view) { + size_t $1_len; + $1_ptr = scm_to_utf8_stringn($input, &$1_len); + view = std::string_view($1_ptr, $1_len); + $1 = &view; + } + + %typemap(out) const string_view& %{ + $result = scm_from_utf8_stringn($1->data(), $1->size()); + %} + + %typemap(varout) string_view %{ + $result = scm_from_utf8_stringn($1.data(), $1.size()); + %} + + // for throwing of any kind of string_view, string_view ref's and + // string_view pointers we convert all to Guile strings + %typemap(throws) string_view, string_view&, const string_view& %{ + scm_throw(scm_from_locale_symbol("swig-exception"), + scm_list_1(scm_from_utf8_stringn($1.data(), $1.size()))); + %} + + %typemap(throws) string_view*, const string_view* %{ + scm_throw(scm_from_locale_symbol("swig-exception"), + scm_list_1(scm_from_utf8_stringn($1->data(), $1->size()))); + %} + + %typemap(typecheck,precedence=SWIG_TYPECHECK_STRINGVIEW) string_view, const string_view& { + $1 = scm_is_string($input); + } + + class string_view; + +} diff --git a/tests/examples.scm b/tests/examples.scm new file mode 100644 index 0000000..3abb348 --- /dev/null +++ b/tests/examples.scm @@ -0,0 +1,94 @@ +;;; guile-xapian --- Guile bindings for Xapian +;;; Copyright © 2026 Arun Isaac <arunisaac@systemreboot.net> +;;; +;;; This file is part of guile-xapian. +;;; +;;; guile-xapian is free software: you can redistribute it and/or +;;; modify it under the terms of the GNU General Public License as +;;; published by the Free Software Foundation, either version 2 of the +;;; License, or (at your option) any later version. +;;; +;;; guile-xapian is distributed in the hope that it will be useful, +;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;;; General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with guile-xapian. If not, see +;;; <https://www.gnu.org/licenses/>. + +(use-modules (rnrs io ports) + (srfi srfi-26) + (srfi srfi-64) + (ice-9 match) + (ice-9 popen)) + +(define (call-with-input-pipe command proc) + "Call @var{proc} with input pipe to @var{command}. @var{command} is a +list of program arguments." + (match command + ((prog args ...) + (let ((port #f)) + (dynamic-wind + (lambda () + (set! port (apply open-pipe* OPEN_READ prog args))) + (cut proc port) + (lambda () + (unless (zero? (close-pipe port)) + (error "Command invocation failed" command)))))))) + +(define (search . query) + (call-with-input-pipe (cons* "guile" "examples/search.scm" "/tmp/db" query) + (lambda (port) + ;; port-transduce might be shorter and more preferable. But we'd + ;; like to support guile 2.2, and port-transduce does not exist + ;; in guile 2.2. + (let loop ((result '())) + (let ((line (get-line port))) + (if (eof-object? line) + (reverse result) + (loop (cons line result)))))))) + +(test-begin "examples") + +(test-equal "index" + 0 + (status:exit-val + (system* "guile" + "examples/index.scm" + "examples/100-objects.sexp" + "/tmp/db"))) + +(test-equal "search watch" + (list "0: #004 Watch with Chinese duplex escapement" + "1: #018 Solar/Sidereal verge watch with epicyclic maintaining power" + "2: #013 Watch timer by P" + "3: #033 A device by Favag of Neuchatel which enables a stop watch to" + "4: #015 Ingersoll \"Dan Dare\" automaton pocket watch with pin-pallet" + "5: #036 Universal 'Tri-Compax' chronographic wrist watch" + "6: #046 Model by Dent of mechanism for setting hands and winding up") + (search "watch")) + +(test-equal "search Dent watch" + (list "0: #046 Model by Dent of mechanism for setting hands and winding up" + "1: #004 Watch with Chinese duplex escapement" + "2: #018 Solar/Sidereal verge watch with epicyclic maintaining power" + "3: #013 Watch timer by P" + "4: #094 Model of a Lever Escapement , 1850-1883" + "5: #093 Model of Graham's Cylinder Escapement, 1850-1883" + "6: #033 A device by Favag of Neuchatel which enables a stop watch to" + "7: #015 Ingersoll \"Dan Dare\" automaton pocket watch with pin-pallet" + "8: #086 Model representing Earnshaw's detent chronometer escapement, 1950-1883" + "9: #036 Universal 'Tri-Compax' chronographic wrist watch") + (search "Dent" "watch")) + +(test-equal "search title:sunwatch" + (list "0: #001 Ansonia Sunwatch (pocket compas dial)") + (search "title:sunwatch")) + +(test-equal "search description:\"leather case\" AND title:sundial" + (list "0: #055 Silver altitude sundial in leather case" + "1: #084 Magnetic sundial in brass case") + (search "description:leather case" "AND" "title:sundial")) + +(test-end "examples") diff --git a/tests/smoketest.scm b/tests/smoketest.scm new file mode 100644 index 0000000..7f8e394 --- /dev/null +++ b/tests/smoketest.scm @@ -0,0 +1,300 @@ +;;; guile-xapian --- Guile bindings for Xapian +;;; Copyright © 2026 Arun Isaac <arunisaac@systemreboot.net> +;;; +;;; This file is part of guile-xapian. +;;; +;;; guile-xapian is free software: you can redistribute it and/or +;;; modify it under the terms of the GNU General Public License as +;;; published by the Free Software Foundation, either version 2 of the +;;; License, or (at your option) any later version. +;;; +;;; guile-xapian is distributed in the hope that it will be useful, +;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;;; General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with guile-xapian. If not, see +;;; <https://www.gnu.org/licenses/>. + +;;; This test suite is a more or less faithful port of +;;; xapian-bindings/python3/smoketest.py from v2.1.0 of the xapian +;;; repo. Keep this updated with new releases of xapian. + +(use-modules ((rnrs conditions) #:select (&error) #:prefix rnrs:) + (srfi srfi-26) + (srfi srfi-64) + (ice-9 ftw) + (xapian xapian) + ;; Prefix with xapian: to avoid overriding guile core + ;; bindings. + ((xapian wrap) #:select (major-version minor-version) #:prefix xapian:) + ((xapian wrap) #:select (revision + version-string + BAD-VALUENO + new-Query + Query-MatchAll + Query-MatchNothing + Query-OP-AND + Query-OP-ELITE-SET + Query-OP-VALUE-RANGE + Query-OP-WILDCARD + Query-OP-SCALE-WEIGHT + Stem-apply + Stem-get-description + Query-get-description + Database-get-metadata + WritableDatabase-set-metadata + Document-add-posting + Enquire-set-collapse-key + Enquire-set-sort-by-value))) + +(define (fold-count item result) + (1+ result)) + +(test-begin "smoketest") + +(test-equal "version number reporting" + (string-join (map number->string (list (xapian:major-version) + (xapian:minor-version) + (revision))) + ".") + (version-string)) + +(test-equal "stemmer description" + "Xapian::Stem(english)" + (Stem-get-description (make-stem "english"))) + +(test-expect-fail "document does not transparently handle a zero byte") +(let* ((data "a\0b") + (doc (make-document #:data data))) + (test-equal "document does not transparently handle a zero byte" + data + (document-data (make-document #:data data)))) + +(call-with-in-memory-database + (lambda (db) + (let ((doc (make-document #:data "is there anybody out there?"))) + (add-document! db doc) + (test-equal "document count" + 1 + (database-document-count db))))) + +(test-equal "OR query description 1" + "Query((smoke OR test OR terms))" + (Query-get-description (query-or (query "smoke") (query "test") (query "terms")))) + +(test-equal "OR query description 2" + "Query((a OR b))" + (Query-get-description (query-or (query "a") (query "b")))) + +(test-equal "value range query description" + "Query(VALUE_RANGE 0 1 4)" + (Query-get-description (new-Query (Query-OP-VALUE-RANGE) 0 "1" "4"))) + +(let* ((query1 (query-phrase (query "smoke") + (query "test") + (query "tuple"))) + (query2 (query-xor (query "smoke") + query1 + (query "string")))) + (test-equal "phrase query description" + "Query((smoke PHRASE 3 test PHRASE 3 tuple))" + (Query-get-description query1)) + + (test-equal "XOR query description" + "Query((smoke XOR (smoke PHRASE 3 test PHRASE 3 tuple) XOR string))" + (Query-get-description query2)) + + (test-equal "number of terms" + 4 + (termlist-fold fold-count + 0 + (query-termlist query2)))) + +;; TODO: Check error reporting of database opening functions as in +;; smoketest.py. + +(test-equal "match all query description" + "Query(<alldocuments>)" + (Query-get-description (Query-MatchAll))) + +(test-equal "match nothing query description" + "Query()" + (Query-get-description (Query-MatchNothing))) + +(test-equal "wildcard query description 1" + "Query(WILDCARD SYNONYM wild)" + (Query-get-description (new-Query (Query-OP-WILDCARD) "wild"))) + +(test-equal "wildcard query description 2" + "Query(WILDCARD SYNONYM wild)" + (Query-get-description (new-Query (Query-OP-WILDCARD) "wild" 0))) + +(call-with-in-memory-database + (lambda (db) + (let ((enq (enquire db (query-or (query "there") (query "is")))) + (doc (make-document #:data "is there anybody out there?"))) + (test-assert "set BAD_VALUENO collapse key" + (Enquire-set-collapse-key enq (BAD-VALUENO))) + (Document-add-posting doc "is" 1) + (Document-add-posting doc "there" 2) + (Document-add-posting doc "anybody" 3) + (Document-add-posting doc "out" 4) + (Document-add-posting doc "there" 5) + (add-document! db doc) + (test-equal "mset size" + 1 + (mset-fold fold-count + 0 + (enquire-mset enq #:maximum-items 10))) + ;; TODO: Test matching terms. + ;; TODO: Test mset size. + ;; TODO: Test expand terms. + ;; TODO: Test number of terms in database. + ;; TODO: Test number of terms in database allterms. + ;; TODO: Test database postlist. + ;; TODO: Test database postlist with empty term. + ;; TODO: Test database termlist. + ;; TODO: Test term iterator skip_to. + ;; TODO: Test number of document values. + ;; TODO: Check exception handling for Xapian::DocNotFoundError. + ))) + +(test-equal "value of OP_ELITE_SET" + 10 + (Query-OP-ELITE-SET)) + +;; TODO: Test match decider. +;; TODO: Test expand decider. +;; TODO: Check min_wt argument to get_eset() works. +;; TODO: Check QueryParser parsing error. + +(test-equal "parse pure NOT query" + "Query((0 * <alldocuments> AND_NOT test@1))" + (Query-get-description (parse-query "NOT test" + #:stemmer (make-stem "none") + #:boolean? #t + #:pure-not? #t))) + +(test-equal "parse query with partial matching 1" + "Query((Zfoo@1 AND (WILDCARD SYNONYM ox OR Zox@2)))" + (Query-get-description (parse-query "foo ox" + #:stemmer (make-stem "en") + #:default-operator (Query-OP-AND) + #:partial? #t))) + +(test-equal "parse query with partial matching 2" + "Query((Zfoo@1 AND (WILDCARD SYNONYM outside OR Zoutsid@2)))" + (Query-get-description (parse-query "foo outside" + #:stemmer (make-stem "en") + #:default-operator (Query-OP-AND) + #:partial? #t))) + +(test-equal "unicode query description" + "Query((foo OR bar£))" + (Query-get-description (query-or (query "foo") (query "bar£")))) + +(test-equal "parse query with unicode characters" + "Query((0 * <alldocuments> AND_NOT Zt\u00e9st@1))" + (Query-get-description (parse-query "NOT tést" + #:stemmer (make-stem "en") + #:boolean? #t + #:pure-not? #t))) + +(let* ((data "Unicode with an accént") + (doc (make-document #:data data))) + (Document-add-posting doc + (Stem-apply (make-stem "en") "outér") + 1) + (test-equal "unicode document data" + data + (document-data doc)) + + (test-equal "unicode document termlist" + (list "outér") + (termlist-fold (lambda (term result) + (cons (term-string term) + result)) + '() + (document-termlist doc)))) + +;; TODO: Check simple stopper. +;; TODO: custom Stopper + +(test-equal "index text" + '(("foo" 2 (1 4)) + ("baz" 1 (3)) + ("bar" 1 (2))) + (let* ((doc (make-document)) + (term-generator (make-term-generator #:stem (make-stem "none") + #:document doc))) + (index-text! term-generator "foo bar baz foo") + (termlist-fold (lambda (term result) + (cons (list (term-string term) + (term-wdf term) + (reverse + (positionlist-fold (lambda (position result) + (cons (position-termpos position) + result)) + '() + (term-positionlist term)))) + result)) + '() + (document-termlist doc)))) + +(test-equal "date value range query description" + "Query(VALUE_RANGE 1 19991203 20011204)" + (Query-get-description + (parse-query "12/03/99..12/04/01" + #:stemmer (make-stem "none") + #:range-processors (list (prefixed-date-range-processor 1 #:prefer-mdy? #t))))) + +(let* ((test-field-processor + (field-processor (lambda (str) + (if (string= str "spam") + (error "already spam") + (query "spam"))))) + (prefixes `(("spam" . ,test-field-processor))) + (boolean-prefixes `(("boolspam" . ,test-field-processor)))) + (test-equal "field processor" + "Query(spam)" + (Query-get-description + (parse-query "spam:ignored" + #:stemmer (make-stem "none") + #:prefixes prefixes + ;; TODO: Add boolean prefixes with other options + ;; too. + #:boolean-prefixes boolean-prefixes))) + + (test-error "failing field processor" + rnrs:&error + (parse-query "spam:spam" + #:stemmer (make-stem "none") + #:prefixes prefixes + #:boolean-prefixes boolean-prefixes))) + +(call-with-in-memory-database + (lambda (db) + (test-equal "get empty database metadata" + "" + (Database-get-metadata db "foo")) + + (WritableDatabase-set-metadata db "foo" "foo") + + (test-equal "get database metadata" + "foo" + (Database-get-metadata db "foo")) + + ;; TODO: Test empty metadata keys. + )) + +(test-equal "scale weight query description" + "Query(5 * foo)" + (Query-get-description (new-Query (Query-OP-SCALE-WEIGHT) + (query "foo") + 5))) + +;; TODO: Test custom stemmer. + +(test-end "smoketest") diff --git a/website/releases/guile-xapian-0.4.0.tar.lz b/website/releases/guile-xapian-0.4.0.tar.lz new file mode 100644 index 0000000..90bc498 --- /dev/null +++ b/website/releases/guile-xapian-0.4.0.tar.lz Binary files differdiff --git a/website/releases/guile-xapian-0.4.0.tar.lz.asc b/website/releases/guile-xapian-0.4.0.tar.lz.asc new file mode 100644 index 0000000..0f841d8 --- /dev/null +++ b/website/releases/guile-xapian-0.4.0.tar.lz.asc @@ -0,0 +1,11 @@ +-----BEGIN PGP SIGNATURE----- + +iQEzBAABCAAdFiEEf3MDQ/Lwnzx3v3nTLiXui2GAK7MFAmY+K9sACgkQLiXui2GA +K7O/HQgAqOwIuIVufN7psmLx/+hPm/PC7H+Q4bvhrpP35chbsxLfhxtv7kuhldBZ +Lkyqbx5zPsqDILUQYVudAff43crakXfbBkjNP/5zG0TgRmDT2ANgKZjEmc3dxtir +Ysnc2+KIuwJMB2n+xs7QIzQyuY0R+A2GvyLq9ZiTQ4TuUvA4bfeY+YWmtuMY1b6C +FblD2CySNCotzfLlY2cn5KUWt2bVneSneItHO3aVwE+73+0RfnQvjb6PBqYlCwWz +wlNo5H75uijD4bx0fI9MaQI9cKHRre3XlkAWZKwoCGMtl9oOubfotmOQe/GqU82q +5x3DmPyegxj4ONK9nTHUu4G6oCcalg== +=WmP/ +-----END PGP SIGNATURE----- diff --git a/website/releases/guile-xapian-0.5.0.tar.lz b/website/releases/guile-xapian-0.5.0.tar.lz new file mode 100644 index 0000000..23d41fd --- /dev/null +++ b/website/releases/guile-xapian-0.5.0.tar.lz Binary files differdiff --git a/website/releases/guile-xapian-0.5.0.tar.lz.asc b/website/releases/guile-xapian-0.5.0.tar.lz.asc new file mode 100644 index 0000000..89bc999 --- /dev/null +++ b/website/releases/guile-xapian-0.5.0.tar.lz.asc @@ -0,0 +1,11 @@ +-----BEGIN PGP SIGNATURE----- + +iQEzBAABCAAdFiEEf3MDQ/Lwnzx3v3nTLiXui2GAK7MFAmq1Yy0ACgkQLiXui2GA +K7MwtQgAjYgZThH1o938liQHJXGew4puFdwMBRQ4ePZIZTmilvWdWqCweVtflG6T +lTDttBd3aAM1Zyr4+uOsqRdOpwxNvoJfpNy+c8PupTvr00ntyrCgPWXlY4Q4AiWH +PM+HtIp9kPoB+hklGwG3POylwsi6UKWi8iHEgq7DYUOG43ZLgtvfzTx8sSdXMB30 +Q5o15h+jophNcWWlJmla1U9SL3pwtVdoOm254L1y0DXQXMqmbRlnXam8KLi60axA +HYcYncTtcejPrXRe+nTX+FEj6SEek/C9qCydYUXs3Pl2nj28HhQtJr+Kc+EaIr4Z +j4S823hZ3BER0lSwGIPsZMkZpMTzuw== +=5nIr +-----END PGP SIGNATURE----- diff --git a/website/releases/guile-xapian-0.6.0.tar.lz b/website/releases/guile-xapian-0.6.0.tar.lz new file mode 100644 index 0000000..70aeff3 --- /dev/null +++ b/website/releases/guile-xapian-0.6.0.tar.lz Binary files differdiff --git a/website/releases/guile-xapian-0.6.0.tar.lz.asc b/website/releases/guile-xapian-0.6.0.tar.lz.asc new file mode 100644 index 0000000..80c636d --- /dev/null +++ b/website/releases/guile-xapian-0.6.0.tar.lz.asc @@ -0,0 +1,11 @@ +-----BEGIN PGP SIGNATURE----- + +iQEzBAABCAAdFiEEf3MDQ/Lwnzx3v3nTLiXui2GAK7MFAmrG+agACgkQLiXui2GA +K7N0wAf8C6Gb/D6tObboiDA87S8VrmAaK9/ym6f1wSV5AkjDIfJFF7Bh4odb2CBH +5ZPs0USsrPjSzlQzX+fZR7Zf+tgGVl4N4nh7WX9apuzsLP2Q2FNOJPx0SVx1GrCP +94Q9R58taOMXWReNgRgI0Db1de0VzGxcXcN7PErYYPGcbp2Ug9OgRhPScciC/vdM +lzSU31RY/Sr1IOk7ADBRXarZA6SA4Nfn7XGLewqghJ2u/qqwU7Psyp+FfR3vak+i +HHBgdg7opFswolzWX44YbBFBj04nOSiZOwPUVYYtx8X8aQkcTc0PIJO8seqmvLIV +A2xF8V8K1EUkXgO3nTz5AN5Xtf72xg== +=Ew5X +-----END PGP SIGNATURE----- diff --git a/xapian-head.i b/xapian-head.i index c079f93..65b99df 100644 --- a/xapian-head.i +++ b/xapian-head.i @@ -1,8 +1,8 @@ %{ -/** @file xapian-head.i +/** @file * @brief Header for SWIG interface file for Xapian. */ -/* Copyright (C) 2005,2006,2007,2008,2009,2011,2012,2013,2014,2015,2016 Olly Betts +/* Copyright (C) 2005,2006,2007,2008,2009,2011,2012,2013,2014,2015,2016,2017 Olly Betts * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -15,9 +15,8 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 - * USA + * along with this program; if not, see + * <https://www.gnu.org/licenses/>. */ // Disable any deprecation warnings for Xapian methods/functions/classes. @@ -32,53 +31,28 @@ using namespace std; -// If a backend has been disabled in xapian-core (manually or automatically) we -// include a stub definition here so the bindings can still be built. +// If the remote backend has been disabled in xapian-core (manually or +// automatically) we include a stub definition here so the bindings can still +// be built. namespace Xapian { -%} -#ifndef XAPIAN_BINDINGS_SKIP_DEPRECATED_DB_FACTORIES -%{ - -#ifndef XAPIAN_HAS_CHERT_BACKEND - namespace Chert { - static Database open(const string &) { - throw FeatureUnavailableError("Chert backend not supported"); - } - static WritableDatabase open(const string &, int, int = 0) { - throw FeatureUnavailableError("Chert backend not supported"); - } - } -#endif - -#ifndef XAPIAN_HAS_INMEMORY_BACKEND - namespace InMemory { - static WritableDatabase open() { - throw FeatureUnavailableError("InMemory backend not supported"); - } - } -#endif - -%} -#endif -%{ #ifndef XAPIAN_HAS_REMOTE_BACKEND namespace Remote { - static Database open(const string &, unsigned int, useconds_t = 0, useconds_t = 0) { - throw FeatureUnavailableError("Remote backend not supported"); - } + static Database open(const string &, unsigned int, unsigned = 0, unsigned = 0) { + throw FeatureUnavailableError("Remote backend not supported"); + } - static WritableDatabase open_writable(const string &, unsigned int, useconds_t = 0, useconds_t = 0, int = 0) { - throw FeatureUnavailableError("Remote backend not supported"); - } + static WritableDatabase open_writable(const string &, unsigned int, unsigned = 0, unsigned = 0, int = 0) { + throw FeatureUnavailableError("Remote backend not supported"); + } - static Database open(const string &, const string &, useconds_t = 0) { - throw FeatureUnavailableError("Remote backend not supported"); - } + static Database open(const string &, const string &, unsigned = 0) { + throw FeatureUnavailableError("Remote backend not supported"); + } - static WritableDatabase open_writable(const string &, const string &, useconds_t = 0, int = 0) { - throw FeatureUnavailableError("Remote backend not supported"); - } + static WritableDatabase open_writable(const string &, const string &, unsigned = 0, int = 0) { + throw FeatureUnavailableError("Remote backend not supported"); + } } #endif @@ -89,6 +63,7 @@ using namespace std; %include exception.i %include stl.i +%include std_string_view.i // Disable errors about not including headers individually. #define XAPIAN_IN_XAPIAN_H @@ -99,15 +74,20 @@ using namespace std; #define XAPIAN_DEPRECATED_CLASS #define XAPIAN_DEPRECATED_CLASS_EX #define XAPIAN_VISIBILITY_DEFAULT +#define XAPIAN_VISIBILITY_INTERNAL #define XAPIAN_CONST_FUNCTION #define XAPIAN_PURE_FUNCTION -#define XAPIAN_NOEXCEPT -#define XAPIAN_NOTHROW(D) D + +// This works around buggy behaviour in SWIG's preprocessor, and only works +// because we currently only use XAPIAN_NONNULL() with an empty argument: +// +// https://github.com/swig/swig/pull/1111 +// +// The correct version is: +// #define XAPIAN_NONNULL(L) +#define XAPIAN_NONNULL() // Ignore these which SWIG seems to add pointless type entries for due them // being used in the SWIG typemap for std::pair. %ignore first_type; %ignore second_type; - -// Treat POSIX useconds_t as unsigned. -%apply unsigned { useconds_t }; diff --git a/xapian-headers.i b/xapian-headers.i index 4b393a1..8ffb403 100644 --- a/xapian-headers.i +++ b/xapian-headers.i @@ -1,7 +1,7 @@ %{ /* xapian-headers.i: Getting SWIG to parse Xapian's C++ headers. * - * Copyright 2004,2006,2011,2012,2013,2014,2015,2016,2019 Olly Betts + * Copyright 2004-2024 Olly Betts * Copyright 2014 Assem Chelli * * This program is free software; you can redistribute it and/or @@ -15,9 +15,8 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 - * USA + * along with this program; if not, see + * <https://www.gnu.org/licenses/>. */ %} @@ -54,6 +53,7 @@ %ignore NS::CLASS::CLASS(Internal*); %ignore NS::CLASS::CLASS(Internal&); %ignore NS::CLASS::operator=; + %ignore NS::CLASS::CLASS(CLASS &&); %enddef #else %define STANDARD_IGNORES(NS, CLASS) @@ -62,6 +62,7 @@ %ignore NS::CLASS::CLASS(Internal&); %ignore NS::CLASS::operator=; %ignore NS::CLASS::CLASS(const CLASS &); + %ignore NS::CLASS::CLASS(CLASS &&); %enddef #endif @@ -76,6 +77,19 @@ #define INC_OR_DEC(METHOD, OP, NS, CLASS, RET_TYPE) void METHOD() { OP(*self); } #endif +#ifdef SWIGPERL +/* In Perl, use inc() and dec() instead of next() and prev(). */ +#define NEXT_METHOD inc +#define PREV_METHOD dec +#define OPERATOR_EQ(NS, CLASS) bool equal(const NS::CLASS & o) const { return *self == o; } +#define OPERATOR_NE(NS, CLASS) bool nequal(const NS::CLASS & o) const { return *self != o; } +#else +#define NEXT_METHOD next +#define PREV_METHOD prev +#define OPERATOR_EQ(NS, CLASS) bool equals(const NS::CLASS & o) const { return *self == o; } +#define OPERATOR_NE(NS, CLASS) +#endif + /* For other languages, SWIG already renames operator() suitably. */ #if defined SWIGGUILE || defined SWIGJAVA || defined SWIGPHP || defined SWIGTCL %rename(apply) *::operator(); @@ -92,9 +106,10 @@ %ignore NS::CLASS::operator++; %ignore NS::CLASS::operator*; %extend NS::CLASS { - bool equals(const NS::CLASS & o) const { return *self == o; } - RET_TYPE DEREF_METHOD() const { return **self; } - INC_OR_DEC(next, ++, NS, CLASS, RET_TYPE) + OPERATOR_EQ(NS, CLASS) + OPERATOR_NE(NS, CLASS) + RET_TYPE DEREF_METHOD() const { return **self; } + INC_OR_DEC(NEXT_METHOD, ++, NS, CLASS, RET_TYPE) } %enddef @@ -106,7 +121,7 @@ %ignore NS::CLASS::operator+; %ignore NS::CLASS::operator-; %extend NS::CLASS { - INC_OR_DEC(prev, --, NS, CLASS, RET_TYPE) + INC_OR_DEC(PREV_METHOD, --, NS, CLASS, RET_TYPE) } %enddef @@ -166,8 +181,8 @@ CONSTANT(int, Xapian, DB_NO_SYNC); CONSTANT(int, Xapian, DB_FULL_SYNC); CONSTANT(int, Xapian, DB_DANGEROUS); CONSTANT(int, Xapian, DB_NO_TERMLIST); -CONSTANT(int, Xapian, DB_BACKEND_CHERT); CONSTANT(int, Xapian, DB_BACKEND_GLASS); +CONSTANT(int, Xapian, DB_BACKEND_HONEY); CONSTANT(int, Xapian, DB_BACKEND_INMEMORY); CONSTANT(int, Xapian, DB_BACKEND_STUB); CONSTANT(int, Xapian, DB_RETRY_LOCK); @@ -186,9 +201,6 @@ CONSTANT(int, Xapian, DOC_ASSUME_VALID); * them. */ /* %include <xapian/error.h> */ -/* ErrorHandler isn't currently wrapped. */ -/* %include <xapian/errorhandler.h> */ - INPUT_ITERATOR_METHODS(Xapian, PositionIterator, Xapian::termpos, get_termpos) %include <xapian/positioniterator.h> @@ -219,13 +231,11 @@ STANDARD_IGNORES(Xapian, Query) %ignore *::operator^=; %ignore *::operator*=; %ignore *::operator/=; -#if defined SWIGCSHARP || defined SWIGGUILE || defined SWIGJAVA || defined SWIGLUA || defined SWIGPHP %ignore *::operator&; %ignore *::operator|; %ignore *::operator^; %ignore *::operator*; %ignore *::operator/; -#endif %ignore Xapian::Query::LEAF_TERM; %ignore Xapian::Query::LEAF_POSTING_SOURCE; %ignore Xapian::Query::LEAF_MATCH_ALL; @@ -241,8 +251,15 @@ STANDARD_IGNORES(Xapian, Query) #endif #ifndef XAPIAN_MIXED_SUBQUERIES_BY_ITERATOR_TYPEMAP %ignore Query(op op_, XapianSWIGQueryItor qbegin, XapianSWIGQueryItor qend, - Xapian::termcount parameter = 0); + Xapian::termcount parameter = 0); #endif +%ignore Xapian::Query::Query(const std::string&, Xapian::termcount = 1, Xapian::termpos = 0); +%ignore Xapian::Query::Query(const char*, Xapian::termcount = 1, Xapian::termpos = 0); +%extend Xapian::Query { + Query(op op_, std::string_view a, std::string_view b) { + return new Xapian::Query(op_, a, b); + } +} %include <xapian/query.h> // Suppress warning that Xapian::Internal::intrusive_base is unknown. @@ -258,12 +275,12 @@ STANDARD_IGNORES(Xapian, Stem) STANDARD_IGNORES(Xapian, TermGenerator) %ignore Xapian::TermGenerator::operator=; /* Ignore forms which use Utf8Iterator, as we don't wrap that class. */ -%ignore Xapian::TermGenerator::index_text(const Xapian::Utf8Iterator &); -%ignore Xapian::TermGenerator::index_text(const Xapian::Utf8Iterator &, Xapian::termcount); -%ignore Xapian::TermGenerator::index_text(const Xapian::Utf8Iterator &, Xapian::termcount, const std::string &); -%ignore Xapian::TermGenerator::index_text_without_positions(const Xapian::Utf8Iterator &); -%ignore Xapian::TermGenerator::index_text_without_positions(const Xapian::Utf8Iterator &, Xapian::termcount); -%ignore Xapian::TermGenerator::index_text_without_positions(const Xapian::Utf8Iterator &, Xapian::termcount, const std::string &); +%ignore Xapian::TermGenerator::index_text(const Xapian::Utf8Iterator&); +%ignore Xapian::TermGenerator::index_text(const Xapian::Utf8Iterator&, Xapian::termcount); +%ignore Xapian::TermGenerator::index_text(const Xapian::Utf8Iterator&, Xapian::termcount, std::string_view); +%ignore Xapian::TermGenerator::index_text_without_positions(const Xapian::Utf8Iterator&); +%ignore Xapian::TermGenerator::index_text_without_positions(const Xapian::Utf8Iterator&, Xapian::termcount); +%ignore Xapian::TermGenerator::index_text_without_positions(const Xapian::Utf8Iterator&, Xapian::termcount, std::string_view); %ignore Xapian::TermGenerator::TermGenerator(const TermGenerator &); %include <xapian/termgenerator.h> @@ -276,19 +293,19 @@ STANDARD_IGNORES(Xapian, MSet) #endif %extend Xapian::MSet { Xapian::docid get_docid(Xapian::doccount i) const { - return *(*self)[i]; + return *(*self)[i]; } Xapian::Document get_document(Xapian::doccount i) const { - return (*self)[i].get_document(); + return (*self)[i].get_document(); } Xapian::MSetIterator get_hit(Xapian::doccount i) const { - return (*self)[i]; + return (*self)[i]; } int get_document_percentage(Xapian::doccount i) const { - return self->convert_to_percent((*self)[i]); + return self->convert_to_percent((*self)[i]); } } @@ -305,10 +322,14 @@ RANDOM_ACCESS_ITERATOR_METHODS(Xapian, ESetIterator, std::string, get_term) STANDARD_IGNORES(Xapian, RSet) -STANDARD_IGNORES(Xapian, Enquire) +%include <xapian/rset.h> SUBCLASSABLE(Xapian, MatchDecider) +%include <xapian/matchdecider.h> + +STANDARD_IGNORES(Xapian, Enquire) + #ifdef XAPIAN_TERMITERATOR_PAIR_OUTPUT_TYPEMAP /* Instantiating the template we're going to use avoids SWIG wrapping uses * of it in SwigValueWrapper. @@ -321,16 +342,12 @@ SUBCLASSABLE(Xapian, MatchDecider) */ std::pair<Xapian::TermIterator, Xapian::TermIterator> get_matching_terms(const Xapian::MSetIterator & item) const { - return std::make_pair($self->get_matching_terms_begin(item), - $self->get_matching_terms_end(item)); + return std::make_pair($self->get_matching_terms_begin(item), + $self->get_matching_terms_end(item)); } } #endif -/* We don't wrap ErrorHandler, so ignore the optional ErrorHandler parameter. - */ -%ignore Enquire(const Database &, ErrorHandler *); - %include <xapian/enquire.h> SUBCLASSABLE(Xapian, ExpandDecider) @@ -351,12 +368,12 @@ SUBCLASSABLE(Xapian, KeyMaker) %extend Xapian::SimpleStopper { /** Load stop words from a text file (one word per line). */ SimpleStopper(const std::string &file) { - ifstream in_file(file.c_str()); - if (!in_file.is_open()) - throw Xapian::InvalidArgumentError("Stopword file not found: " + file); - istream_iterator<std::string> in_iter(in_file); - istream_iterator<std::string> eof; - return new Xapian::SimpleStopper(in_iter, eof); + ifstream in_file(file.c_str()); + if (!in_file.is_open()) + throw Xapian::InvalidArgumentError("Stopword file not found: " + file); + istream_iterator<std::string> in_iter(in_file); + istream_iterator<std::string> eof; + return new Xapian::SimpleStopper(in_iter, eof); } } @@ -365,10 +382,8 @@ SUBCLASSABLE(Xapian, FieldProcessor) %warnfilter(SWIGWARN_TYPE_UNDEFINED_CLASS) Xapian::Stopper; SUBCLASSABLE(Xapian, RangeProcessor) SUBCLASSABLE(Xapian, Stopper) -SUBCLASSABLE(Xapian, ValueRangeProcessor) // Suppress warning that Xapian::Internal::opt_intrusive_base is unknown. %warnfilter(SWIGWARN_TYPE_UNDEFINED_CLASS) Xapian::RangeProcessor; -%warnfilter(SWIGWARN_TYPE_UNDEFINED_CLASS) Xapian::ValueRangeProcessor; %warnfilter(SWIGWARN_TYPE_UNDEFINED_CLASS) Xapian::FieldProcessor; STANDARD_IGNORES(Xapian, QueryParser) %ignore Xapian::QueryParser::QueryParser(const QueryParser &); @@ -423,45 +438,55 @@ INPUT_ITERATOR_METHODS(Xapian, LatLongCoordsIterator, LatLongCoord, get_coord) STANDARD_IGNORES(Xapian, Database) STANDARD_IGNORES(Xapian, WritableDatabase) %ignore Xapian::WritableDatabase::WritableDatabase(Database::Internal *); -%ignore Xapian::Database::check(const std::string &, int, std::ostream *); -%ignore Xapian::Database::check(int fd, int, std::ostream *); +%ignore Xapian::Database::check(std::string_view, int, std::ostream*); +%ignore Xapian::Database::check(int fd, int, std::ostream*); %include <xapian/database.h> %extend Xapian::Database { - static size_t check(const std::string &path, int opts = 0) { - return Xapian::Database::check(path, opts, opts ? &std::cout : NULL); + static size_t check(std::string_view path, int opts = 0) { + return Xapian::Database::check(path, opts, opts ? &std::cout : NULL); } } #if defined SWIGCSHARP || defined SWIGJAVA -/* xapian/dbfactory.h is currently wrapped via fake class declarations in - * fake_dbfactory.i for C# and Java. */ - -#else - -#ifdef XAPIAN_BINDINGS_SKIP_DEPRECATED_DB_FACTORIES -%ignore Xapian::InMemory::open; -%ignore Xapian::Chert::open; -%ignore Xapian::Auto::open_stub; -#else - -%rename("inmemory_open") Xapian::InMemory::open; - -/* SWIG Tcl wrappers don't call destructors for classes returned by factory - * functions, so we don't wrap them so users are forced to use the - * WritableDatabase ctor instead. */ -#ifdef SWIGTCL -%ignore Xapian::Chert::open(const std::string &dir, int action, int block_size = 8192); -#endif +/* C# and Java don't allow functions outside a class so we can't use SWIG's + * %nspace feature here. Instead we pretend to SWIG that the C++ + * Xapian::Remote namespace is actually a Xapian::Remote class with public + * static functions. The code SWIG generates will work fine, and we get + * xapian.Remote.open() in Java and Xapian.Remote.open() in C#. + */ -%rename("chert_open") Xapian::Chert::open; +namespace Xapian { + +class Remote { + // Private constructor and destructor so SWIG doesn't try to call them. + Remote(); + ~Remote(); + public: + static Database open(const std::string &host, + unsigned int port, + unsigned timeout = 10000, + unsigned connect_timeout = 10000); + + static WritableDatabase open_writable(const std::string &host, + unsigned int port, + unsigned timeout = 0, + unsigned connect_timeout = 10000, + int flags = 0); + + static Database open(const std::string &program, + const std::string &args, + unsigned timeout = 10000); + + static WritableDatabase open_writable(const std::string &program, + const std::string &args, + unsigned timeout = 0, + int flags = 0); +}; -#ifndef SWIGPHP -/* PHP renames this to auto_open_stub() in php/php.i. */ -%rename("open_stub") Xapian::Auto::open_stub; -#endif +} -#endif +#else %rename("remote_open") Xapian::Remote::open; %rename("remote_open_writable") Xapian::Remote::open_writable; diff --git a/xapian.i.in b/xapian.i.in index f1ffe07..ba923d4 100644 --- a/xapian.i.in +++ b/xapian.i.in @@ -1,5 +1,5 @@ /* guile-xapian --- Guile bindings for Xapian - * Copyright © 2020 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. @@ -89,6 +89,7 @@ } %include xapian-head.i +%include except.i %include xapian-headers.i %extend Xapian::ValueIterator { @@ -140,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); diff --git a/xapian/error.scm b/xapian/error.scm new file mode 100644 index 0000000..4187dda --- /dev/null +++ b/xapian/error.scm @@ -0,0 +1,30 @@ +;;; guile-xapian --- Guile bindings for Xapian +;;; Copyright © 2023 Arun Isaac <arunisaac@systemreboot.net> +;;; +;;; This file is part of guile-xapian. +;;; +;;; guile-xapian is free software: you can redistribute it and/or +;;; modify it under the terms of the GNU General Public License as +;;; published by the Free Software Foundation, either version 2 of the +;;; License, or (at your option) any later version. +;;; +;;; guile-xapian is distributed in the hope that it will be useful, +;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;;; General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with guile-xapian. If not, see +;;; <https://www.gnu.org/licenses/>. + +(define-module (xapian error) + #:use-module (rnrs conditions) + #:use-module (rnrs exceptions) + #:export (raise-xapian-exception)) + +(define-condition-type &xapian-error &error + make-xapian-error xapian-error? + (message xapian-error-message)) + +(define (raise-xapian-exception message) + (raise (make-xapian-error message))) diff --git a/xapian/xapian.scm b/xapian/xapian.scm index 75924ae..86a39c7 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–2026 Arun Isaac <arunisaac@systemreboot.net> ;;; Copyright © 2021 Bob131 <bob@bob131.so> ;;; ;;; This file is part of guile-xapian. @@ -22,7 +22,10 @@ #:use-module (rnrs arithmetic bitwise) #:use-module (rnrs bytevectors) #:use-module (ice-9 match) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-9) #:use-module (srfi srfi-26) + #:use-module (htmlprag) #:use-module (xapian wrap) #:export (xapian-open xapian-close @@ -33,7 +36,9 @@ call-with-writable-database call-with-in-memory-database add-document! + delete-document! replace-document! + commit-database! make-document document-data document-bytes @@ -43,11 +48,24 @@ document-slot-ref-bytes document-slot-set! document-slot-set-bytes! + document-termlist make-stem make-term-generator index-text! increase-termpos! parse-query + query + query-and + query-or + query-xor + query-filter + query-phrase + query-termlist + prefixed-range-processor + suffixed-range-processor + prefixed-date-range-processor + suffixed-date-range-processor + field-processor enquire enquire-mset mset-item-docid @@ -55,7 +73,21 @@ mset-item-rank mset-item-weight mset-fold - mset-snippet)) + termlist-fold + positionlist-fold + term-string + term-wdf + term-freq + term-positionlist + position-termpos + mset-snippet + mset-sxml-snippet)) + +(define-record-type <iterable> + (iterable start end) + iterable? + (start iterable-start) + (end iterable-end)) (define xapian-open new-Database) (define xapian-close delete-Database) @@ -77,12 +109,15 @@ "Call PROC passing it an in-memory writable database. Only a writable in-memory database can be created, since a read-only in-memory database would always remain empty and is of little use." - (let ((db (inmemory-open))) - (dynamic-wind noop (cut proc db) (cut xapian-close-writable db)))) + (let ((db (new-WritableDatabase "" (DB-BACKEND-INMEMORY)))) + (dynamic-wind noop (cut proc db) (cut delete-WritableDatabase db)))) (define add-document! WritableDatabase-add-document) +(define delete-document! WritableDatabase-delete-document) (define replace-document! WritableDatabase-replace-document) +(define commit-database! WritableDatabase-commit) + (define* (make-document #:key data (terms '()) (values '())) (let ((doc (new-Document))) (when data @@ -134,6 +169,10 @@ bytevector." (current-error-port)) (Document-add-value-bytes document slot value)) +(define (document-termlist doc) + (iterable (Document-termlist-begin doc) + (Document-termlist-end doc))) + (define make-stem new-Stem) (define* (make-term-generator #:key stem document) @@ -142,13 +181,60 @@ bytevector." (TermGenerator-set-document term-generator document) term-generator)) -(define* (index-text! term-generator text #:key (wdf-increment 1) prefix) - (apply TermGenerator-index-text term-generator text wdf-increment - (if prefix (list prefix) '()))) +(define* (index-text! term-generator text #:key (wdf-increment 1) (prefix "") (positions? #t)) + "Index @var{text} using @var{term-generator}. @var{wdf-increment} is +the within document frequency increment. @var{prefix} is the term +prefix to use. If @var{positions?} is #f, position information is not +generated." + ((if positions? + TermGenerator-index-text + TermGenerator-index-text-without-positions) + term-generator text wdf-increment prefix)) (define increase-termpos! TermGenerator-increase-termpos) -(define* (parse-query querystring #:key stemmer stemming-strategy (prefixes '())) +(define* (parse-query querystring + #:key + stemmer + stemming-strategy + (prefixes '()) + (boolean-prefixes '()) + (range-processors '()) + (default-operator (Query-OP-OR)) + (boolean? #t) + (phrases? #t) + (love-hate? #t) + any-case-boolean? + wildcard? + pure-not? + partial?) + "Parse @var{querystring} and return a @code{Query} object. + +@var{prefixes} and @var{boolean-prefixes} must be association lists +mapping fields to prefixes or @code{FieldProcessor} +objects. @var{range-processors} is a list of @code{RangeProcessor} +objects. + +Use @code{default-operator} to combine non-filter query items when no +explicit operator is used. + +When @var{boolean?} is @code{#t}, boolean operators (AND, OR, etc.) +and bracketed subexpressions are supported. + +When @var{phrases?} is @code{#t}, quoted phrases are supported. + +When @var{love-hate?} is @code{#t}, @samp{+} and @samp{-} are +supported. + +When @var{any-case-boolean?} is @code{#t}, boolean operators are +supported even if they are not in capitals. + +When @var{wildcard?} is @code{#t}, wildcards are supported. + +When @var{pure-not?} is @code{#t}, pure @code{NOT} queries such as +@samp{NOT apples} are allowed. + +When @var{partial?} is @code{#t}, enable partial matching." (let ((queryparser (new-QueryParser))) (QueryParser-set-stemmer queryparser stemmer) (when stemming-strategy @@ -157,7 +243,22 @@ bytevector." ((field . prefix) (QueryParser-add-prefix queryparser field prefix))) prefixes) - (let ((query (QueryParser-parse-query queryparser querystring))) + (for-each (match-lambda + ((field . prefix) + (QueryParser-add-boolean-prefix queryparser field prefix))) + boolean-prefixes) + (for-each (cut QueryParser-add-rangeprocessor queryparser <>) + range-processors) + (QueryParser-set-default-op queryparser default-operator) + (let ((query (QueryParser-parse-query queryparser + querystring + (bitwise-ior (get-flag QueryParser-FLAG-BOOLEAN boolean?) + (get-flag QueryParser-FLAG-PHRASE phrases?) + (get-flag QueryParser-FLAG-LOVEHATE love-hate?) + (get-flag QueryParser-FLAG-BOOLEAN-ANY-CASE any-case-boolean?) + (get-flag QueryParser-FLAG-WILDCARD wildcard?) + (get-flag QueryParser-FLAG-PURE-NOT pure-not?) + (get-flag QueryParser-FLAG-PARTIAL partial?))))) (delete-QueryParser queryparser) query))) @@ -178,21 +279,168 @@ result set. MAXIMUM-ITEMS specifies the maximum number of items to return. To return all matches, pass the result of calling database-document-count on the database object." - (Enquire-get-mset enquire offset maximum-items)) + (let ((mset (Enquire-get-mset enquire offset maximum-items))) + (iterable (MSet-begin mset) + (MSet-end mset)))) (define mset-item-docid MSetIterator-get-docid) (define mset-item-document MSetIterator-get-document) (define mset-item-rank MSetIterator-get-rank) (define mset-item-weight MSetIterator-get-weight) -(define (mset-fold proc init mset) - (let loop ((head (MSet-begin mset)) - (result init)) - (cond - ((MSetIterator-equals head (MSet-end mset)) result) - (else (let ((result (proc head result))) - (MSetIterator-next head) - (loop head result)))))) +(define (iterator->fold iterator-next iterator-equals) + (lambda (proc init iterable) + (let loop ((head (iterable-start iterable)) + (result init)) + (cond + ((iterator-equals head (iterable-end iterable)) result) + (else + (let ((result (proc head result))) + (iterator-next head) + (loop head result))))))) + +(define mset-fold + (iterator->fold MSetIterator-next MSetIterator-equals)) + +(define termlist-fold + (iterator->fold TermIterator-next TermIterator-equals)) + +(define positionlist-fold + (iterator->fold PositionIterator-next PositionIterator-equals)) + +(define term-string TermIterator-get-term) +(define term-wdf TermIterator-get-wdf) +(define term-freq TermIterator-get-termfreq) + +(define (term-positionlist term) + (iterable (TermIterator-positionlist-begin term) + (TermIterator-positionlist-end term))) + +(define position-termpos PositionIterator-get-termpos) + +(define (query term) + "Return a @code{Query} object for @var{term}." + (new-Query term)) + +(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." + (guile-xapian-build-query (Query-OP-AND) 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." + (guile-xapian-build-query (Query-OP-OR) queries)) + +(define (query-xor . queries) + "Return a query matching documents which an odd number of @var{queries} +match. + +In a weighted context, the weight is the sum of the weights for +matching queries." + (guile-xapian-build-query (Query-OP-XOR) 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." + (guile-xapian-build-query (Query-OP-FILTER) queries)) + +(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." + (guile-xapian-build-query (Query-OP-PHRASE) queries)) + +(define (query-termlist query) + (iterable (Query-get-terms-begin query) + (Query-get-terms-end query))) + +(define* (prefixed-range-processor slot proc #:key (prefix "") repeated?) + "Return a @code{RangeProcessor} object that calls @var{proc} to process +its range over @var{slot}. + +@var{proc} is a procedure that, given a begin string and an end +string, must return a @code{Query} object. For open-ended ranges, +either the begin string or the end string will be @code{#f}. + +@var{prefix} is a prefix to look for to recognize values as belonging +to this range. When @var{repeated?} is @code{#t}, allow @var{prefix} +on both ends of the range---@samp{$1..$10}." + (new-GuileXapianRangeProcessorWrapper + slot + prefix + (get-flag RP-REPEATED repeated?) + proc)) + +(define* (suffixed-range-processor slot proc #:key suffix repeated?) + "Return a @code{RangeProcessor} object that calls @var{proc} to process +its range over @var{slot}. + +@var{proc} is a procedure that, given a begin string and an end +string, must return a @code{Query} object. For open-ended ranges, +either the begin string or the end string will be @code{#f}. + +@var{suffix} is a suffix to look for to recognize values as belonging +to this range. When @var{repeated?} is @code{#t}, allow @var{suffix} +on both ends of the range—@samp{2kg..12kg}." + (new-GuileXapianRangeProcessorWrapper + slot + suffix + (bitwise-ior (RP-SUFFIX) + (get-flag RP-REPEATED repeated?)) + proc)) + +(define* (prefixed-date-range-processor slot #:key (prefix "") repeated? prefer-mdy? (epoch-year 1970)) + "Return a @code{DateRangeProcessor} object that handles date ranges on +@var{slot}. + +@var{prefix} and @var{repeated?} are the same as in +@code{prefixed-range-processor}. + +When @var{prefer-mdy?} is @code{#t}, interpret ambiguous dates as +month/day/year rather than day/month/year. + +@var{epoch-year} is the year to use as the epoch for dates with +two-digit years." + (new-DateRangeProcessor slot + prefix + (bitwise-ior (get-flag RP-REPEATED repeated?) + (get-flag RP-DATE-PREFER-MDY prefer-mdy?)) + epoch-year)) + +(define* (suffixed-date-range-processor slot #:key suffix repeated? prefer-mdy? (epoch-year 1970)) + "Return a @code{DateRangeProcessor} object that handles date ranges on +@var{slot}. + +@var{suffix} and @var{repeated?} are the same as in +@code{suffixed-range-processor}. + +@var{prefer-mdy?} and @var{epoch-year} are the same as in +@code{prefixed-date-range-processor}." + (new-DateRangeProcessor slot + suffix + (bitwise-ior (RP-SUFFIX) + (get-flag RP-REPEATED repeated?) + (get-flag RP-DATE-PREFER-MDY prefer-mdy?)) + epoch-year)) + +(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)) @@ -204,9 +452,70 @@ on the database object." (background-model? #t) (exhaustive? #t) (empty-without-match? #t) (cjk-ngram? #t)) + "Generate a snippet from @var{text}. @var{mset} is the xapian +@code{MSet} object representing a list of search results. + +@var{length} is the number of bytes of @var{text} to aim to select. + +The same stemmer used to build the query should be specified as +@var{stemmer}. + +@var{highlight-start} and @var{highlight-end} are inserted +respectively before and after the highlit terms. + +If the chosen snippet seems to start or end mid-sentence, then +@var{omit} is prepended or appended to indicate this. + +If @var{background-model?} is @code{#true}, the relevance of non-query +terms are modelled to prefer snippets containing a more interesting +background. + +If @var{exhaustive?} is @code{#true}, exhaustively evaluate candidate +snippets. Else, snippet generation will stop once a @emph{good enough} +snippet has been found. + +If @var{empty-without-match?} is @code{#true}, return the empty string +if not a single term was found in @var{text}. Else, return a substring +of text without any highlit terms. + +If @var{cjk-ngram?} is @code{#true}, enable generation of n-grams from +CJK text. + +See @code{MSet::snippet} in @file{xapian/mset.h} of the xapian source +for more details." (MSet-snippet mset text length stemmer (bitwise-ior (get-flag MSet-SNIPPET-BACKGROUND-MODEL background-model?) (get-flag MSet-SNIPPET-EXHAUSTIVE exhaustive?) (get-flag MSet-SNIPPET-EMPTY-WITHOUT-MATCH empty-without-match?) (get-flag MSet-SNIPPET-CJK-NGRAM cjk-ngram?)) highlight-start highlight-end omit)) + +(define* (mset-sxml-snippet mset text #:key (length 500) (stemmer (make-stem "none")) + (highlight-proc (lambda (text) + `(b ,text))) + (omit "...") (background-model? #t) (exhaustive? #t) + (empty-without-match? #t) (cjk-ngram? #t)) + "Generate a snippet in SXML form from @var{text}. + +@var{highlight-proc} is a function that is passed the highlit text. It +should return a SXML tree highlighting that text. + +Arguments @var{mset}, @var{length}, @var{stemmer}, @var{omit}, +@var{background-model?}, @var{exhaustive?}, @var{empty-without-match?} +and @var{cjk-ngram?} are the same as in the @code{mset-snippet} +function." + ;; mset-snippet returns serialized HTML. So, we reverse it with + ;; html->sxml. + (match (html->sxml (mset-snippet mset text)) + (('*TOP* children ...) + (append-map (match-lambda + ;; Apply highlight-proc if highlit text. + (('b text) + (list (highlight-proc text))) + ;; Add (br) if end of line. + ((? (cut string-suffix? "\n" <>) text) + (list (string-trim-right text #\newline) + '(br))) + ;; Else, return verbatim. + (text (list text))) + children)))) |
