mhs-xapian 1.0.18a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +3 -0
- data/AUTHORS +1 -0
- data/COPYING +340 -0
- data/ChangeLog +5876 -0
- data/HACKING +101 -0
- data/INSTALL +293 -0
- data/Makefile +722 -0
- data/Makefile.am +26 -0
- data/Makefile.in +722 -0
- data/NEWS +2110 -0
- data/README +59 -0
- data/Rakefile +51 -0
- data/TODO +47 -0
- data/aclocal.m4 +7675 -0
- data/config.guess +1501 -0
- data/config.h +56 -0
- data/config.h.in +55 -0
- data/config.status +1298 -0
- data/config.sub +1705 -0
- data/configure +18536 -0
- data/configure.ac +944 -0
- data/csharp/.deps/xapian_wrap.Plo +1 -0
- data/csharp/AssemblyInfo.cs +40 -0
- data/csharp/AssemblyInfo.cs.in +40 -0
- data/csharp/Auto.cs +46 -0
- data/csharp/BM25Weight.cs +107 -0
- data/csharp/BoolWeight.cs +103 -0
- data/csharp/Database.cs +275 -0
- data/csharp/DateValueRangeProcessor.cs +61 -0
- data/csharp/Document.cs +177 -0
- data/csharp/ESet.cs +94 -0
- data/csharp/ESetIterator.cs +117 -0
- data/csharp/Enquire.cs +274 -0
- data/csharp/ExpandDecider.cs +76 -0
- data/csharp/Flint.cs +58 -0
- data/csharp/InMemory.cs +46 -0
- data/csharp/MSet.cs +193 -0
- data/csharp/MSetIterator.cs +141 -0
- data/csharp/Makefile +868 -0
- data/csharp/Makefile.am +106 -0
- data/csharp/Makefile.in +868 -0
- data/csharp/MatchDecider.cs +76 -0
- data/csharp/MultiValueSorter.cs +63 -0
- data/csharp/NumberValueRangeProcessor.cs +61 -0
- data/csharp/PositionIterator.cs +101 -0
- data/csharp/PostingIterator.cs +125 -0
- data/csharp/Quartz.cs +58 -0
- data/csharp/Query.cs +150 -0
- data/csharp/QueryParser.cs +174 -0
- data/csharp/RSet.cs +102 -0
- data/csharp/Remote.cs +100 -0
- data/csharp/SWIGTYPE_p_std__string.cs +30 -0
- data/csharp/SWIGTYPE_p_std__vectorTXapian__Query_t.cs +30 -0
- data/csharp/SWIGTYPE_p_std__vectorTstd__string_t.cs +30 -0
- data/csharp/SimpleStopper.cs +64 -0
- data/csharp/SmokeTest.cs +178 -0
- data/csharp/Sorter.cs +76 -0
- data/csharp/Stem.cs +66 -0
- data/csharp/Stopper.cs +91 -0
- data/csharp/StringValueRangeProcessor.cs +53 -0
- data/csharp/TermGenerator.cs +152 -0
- data/csharp/TermIterator.cs +125 -0
- data/csharp/TradWeight.cs +107 -0
- data/csharp/ValueIterator.cs +102 -0
- data/csharp/ValueRangeProcessor.cs +76 -0
- data/csharp/Version.cs +60 -0
- data/csharp/Weight.cs +93 -0
- data/csharp/WritableDatabase.cs +153 -0
- data/csharp/Xapian.cs +65 -0
- data/csharp/XapianPINVOKE.cs +1527 -0
- data/csharp/docs/Makefile +450 -0
- data/csharp/docs/Makefile.am +16 -0
- data/csharp/docs/Makefile.in +450 -0
- data/csharp/docs/examples/SimpleExpand.cs +109 -0
- data/csharp/docs/examples/SimpleIndex.cs +71 -0
- data/csharp/docs/examples/SimpleSearch.cs +78 -0
- data/csharp/docs/index.html +211 -0
- data/csharp/util.i +233 -0
- data/csharp/xapian_wrap.cc +10338 -0
- data/csharp/xapian_wrap.h +93 -0
- data/depcomp +632 -0
- data/extconf.rb +20 -0
- data/generic/except.i +80 -0
- data/generic/generic.mk +48 -0
- data/install-sh +520 -0
- data/java-swig/.deps/xapian_wrap.Plo +1 -0
- data/java-swig/Auto.java +35 -0
- data/java-swig/BM25Weight.java +81 -0
- data/java-swig/BoolWeight.java +77 -0
- data/java-swig/Database.java +195 -0
- data/java-swig/DateValueRangeProcessor.java +51 -0
- data/java-swig/Document.java +135 -0
- data/java-swig/ESet.java +71 -0
- data/java-swig/ESetIterator.java +71 -0
- data/java-swig/Enquire.java +246 -0
- data/java-swig/ExpandDecider.java +59 -0
- data/java-swig/Flint.java +43 -0
- data/java-swig/InMemory.java +35 -0
- data/java-swig/MSet.java +143 -0
- data/java-swig/MSetIterator.java +87 -0
- data/java-swig/Makefile +781 -0
- data/java-swig/Makefile.am +132 -0
- data/java-swig/Makefile.in +781 -0
- data/java-swig/MatchDecider.java +59 -0
- data/java-swig/MultiValueSorter.java +51 -0
- data/java-swig/NumberValueRangeProcessor.java +51 -0
- data/java-swig/PositionIterator.java +63 -0
- data/java-swig/PostingIterator.java +83 -0
- data/java-swig/Quartz.java +43 -0
- data/java-swig/Query.java +189 -0
- data/java-swig/QueryParser.java +214 -0
- data/java-swig/RSet.java +79 -0
- data/java-swig/Remote.java +71 -0
- data/java-swig/SWIGTYPE_p_std__string.java +25 -0
- data/java-swig/SimpleStopper.java +51 -0
- data/java-swig/SmokeTest.java +161 -0
- data/java-swig/Sorter.java +59 -0
- data/java-swig/Stem.java +51 -0
- data/java-swig/Stopper.java +63 -0
- data/java-swig/StringValueRangeProcessor.java +43 -0
- data/java-swig/TermGenerator.java +158 -0
- data/java-swig/TermIterator.java +83 -0
- data/java-swig/TradWeight.java +81 -0
- data/java-swig/ValueIterator.java +67 -0
- data/java-swig/ValueRangeProcessor.java +59 -0
- data/java-swig/Version.java +47 -0
- data/java-swig/Weight.java +68 -0
- data/java-swig/WritableDatabase.java +123 -0
- data/java-swig/Xapian.java +39 -0
- data/java-swig/XapianConstants.java +15 -0
- data/java-swig/XapianJNI.java +508 -0
- data/java-swig/run-java-test +6 -0
- data/java-swig/xapian_wrap.cc +12594 -0
- data/java-swig/xapian_wrap.h +91 -0
- data/java/Makefile +660 -0
- data/java/Makefile.am +35 -0
- data/java/Makefile.in +660 -0
- data/java/README +76 -0
- data/java/SmokeTest.java +148 -0
- data/java/native/.deps/Database.Plo +1 -0
- data/java/native/.deps/Document.Plo +1 -0
- data/java/native/.deps/ESet.Plo +1 -0
- data/java/native/.deps/ESetIterator.Plo +1 -0
- data/java/native/.deps/Enquire.Plo +1 -0
- data/java/native/.deps/MSet.Plo +1 -0
- data/java/native/.deps/MSetIterator.Plo +1 -0
- data/java/native/.deps/PositionIterator.Plo +1 -0
- data/java/native/.deps/Query.Plo +1 -0
- data/java/native/.deps/RSet.Plo +1 -0
- data/java/native/.deps/Stem.Plo +1 -0
- data/java/native/.deps/TermIterator.Plo +1 -0
- data/java/native/.deps/WritableDatabase.Plo +1 -0
- data/java/native/.deps/org_xapian_XapianJNI.Plo +1 -0
- data/java/native/.deps/utils.Plo +1 -0
- data/java/native/Database.cc +222 -0
- data/java/native/Document.cc +173 -0
- data/java/native/ESet.cc +79 -0
- data/java/native/ESetIterator.cc +82 -0
- data/java/native/Enquire.cc +271 -0
- data/java/native/MSet.cc +169 -0
- data/java/native/MSetIterator.cc +107 -0
- data/java/native/Makefile +594 -0
- data/java/native/Makefile.am +51 -0
- data/java/native/Makefile.in +594 -0
- data/java/native/PositionIterator.cc +64 -0
- data/java/native/Query.cc +180 -0
- data/java/native/RSet.cc +98 -0
- data/java/native/Stem.cc +75 -0
- data/java/native/TermIterator.cc +107 -0
- data/java/native/WritableDatabase.cc +118 -0
- data/java/native/XapianObjectHolder.h +115 -0
- data/java/native/org_xapian_XapianJNI.cc +78 -0
- data/java/native/org_xapian_XapianJNI.h +1369 -0
- data/java/native/utils.cc +51 -0
- data/java/native/xapian_jni.h +116 -0
- data/java/org/xapian/Database.java +148 -0
- data/java/org/xapian/Document.java +135 -0
- data/java/org/xapian/ESet.java +66 -0
- data/java/org/xapian/ESetIterator.java +97 -0
- data/java/org/xapian/Enquire.java +136 -0
- data/java/org/xapian/ExpandDecider.java +30 -0
- data/java/org/xapian/MSet.java +104 -0
- data/java/org/xapian/MSetIterator.java +132 -0
- data/java/org/xapian/Makefile +580 -0
- data/java/org/xapian/Makefile.am +38 -0
- data/java/org/xapian/Makefile.in +580 -0
- data/java/org/xapian/MatchDecider.java +30 -0
- data/java/org/xapian/PositionIterator.java +89 -0
- data/java/org/xapian/Query.java +190 -0
- data/java/org/xapian/RSet.java +89 -0
- data/java/org/xapian/Stem.java +80 -0
- data/java/org/xapian/TermIterator.java +142 -0
- data/java/org/xapian/WritableDatabase.java +92 -0
- data/java/org/xapian/Xapian.java +114 -0
- data/java/org/xapian/XapianJNI.java +444 -0
- data/java/org/xapian/errors/AssertionError.java +40 -0
- data/java/org/xapian/errors/DatabaseCorruptError.java +40 -0
- data/java/org/xapian/errors/DatabaseError.java +40 -0
- data/java/org/xapian/errors/DatabaseLockError.java +40 -0
- data/java/org/xapian/errors/DatabaseModifiedError.java +40 -0
- data/java/org/xapian/errors/DatabaseOpeningError.java +40 -0
- data/java/org/xapian/errors/DocNotFoundError.java +40 -0
- data/java/org/xapian/errors/FeatureUnavailableError.java +40 -0
- data/java/org/xapian/errors/InternalError.java +40 -0
- data/java/org/xapian/errors/InvalidArgumentError.java +40 -0
- data/java/org/xapian/errors/InvalidOperationError.java +40 -0
- data/java/org/xapian/errors/LogicError.java +40 -0
- data/java/org/xapian/errors/Makefile +416 -0
- data/java/org/xapian/errors/Makefile.am +32 -0
- data/java/org/xapian/errors/Makefile.in +416 -0
- data/java/org/xapian/errors/NetworkError.java +40 -0
- data/java/org/xapian/errors/NetworkTimeoutError.java +40 -0
- data/java/org/xapian/errors/RangeError.java +40 -0
- data/java/org/xapian/errors/RuntimeError.java +40 -0
- data/java/org/xapian/errors/UnimplementedError.java +40 -0
- data/java/org/xapian/errors/XapianError.java +40 -0
- data/java/org/xapian/errors/XapianRuntimeError.java +49 -0
- data/java/org/xapian/examples/Makefile +391 -0
- data/java/org/xapian/examples/Makefile.am +8 -0
- data/java/org/xapian/examples/Makefile.in +391 -0
- data/java/org/xapian/examples/SimpleIndex.java +68 -0
- data/java/org/xapian/examples/SimpleSearch.java +71 -0
- data/java/run-java-test +6 -0
- data/libtool +7618 -0
- data/ltmain.sh +6956 -0
- data/mhs-xapian.gemspec +368 -0
- data/missing +378 -0
- data/php/.deps/xapian_wrap.Plo +1 -0
- data/php/Makefile +871 -0
- data/php/Makefile.am +82 -0
- data/php/Makefile.in +871 -0
- data/php/docs/Makefile +453 -0
- data/php/docs/Makefile.am +19 -0
- data/php/docs/Makefile.in +453 -0
- data/php/docs/examples/simpleexpand.php4 +108 -0
- data/php/docs/examples/simpleexpand.php5 +104 -0
- data/php/docs/examples/simpleindex.php4 +76 -0
- data/php/docs/examples/simpleindex.php5 +73 -0
- data/php/docs/examples/simplesearch.php4 +75 -0
- data/php/docs/examples/simplesearch.php5 +72 -0
- data/php/docs/index.html +313 -0
- data/php/except.i +98 -0
- data/php/php4/php_xapian.h +323 -0
- data/php/php4/xapian.php +32 -0
- data/php/php4/xapian_wrap.cc +27656 -0
- data/php/php5/php_xapian.h +319 -0
- data/php/php5/xapian.php +1566 -0
- data/php/php5/xapian_wrap.cc +24330 -0
- data/php/smoketest.php +246 -0
- data/php/smoketest4.php +84 -0
- data/php/smoketest5.php +79 -0
- data/php/util.i +187 -0
- data/python/.deps/xapian_wrap.Plo +1 -0
- data/python/Makefile +891 -0
- data/python/Makefile.am +105 -0
- data/python/Makefile.in +891 -0
- data/python/doccomments.i +5134 -0
- data/python/docs/Makefile +448 -0
- data/python/docs/Makefile.am +14 -0
- data/python/docs/Makefile.in +448 -0
- data/python/docs/examples/simpleexpand.py +98 -0
- data/python/docs/examples/simpleindex.py +65 -0
- data/python/docs/examples/simplematchdecider.py +78 -0
- data/python/docs/examples/simplesearch.py +65 -0
- data/python/docs/index.html +420 -0
- data/python/except.i +290 -0
- data/python/extra.i +1048 -0
- data/python/extracomments.i +28 -0
- data/python/generate-python-exceptions +189 -0
- data/python/generate-python-exceptions.in +189 -0
- data/python/modern/xapian.py +5662 -0
- data/python/modern/xapian_wrap.cc +35170 -0
- data/python/modern/xapian_wrap.h +244 -0
- data/python/pythontest.py +1110 -0
- data/python/smoketest.py +328 -0
- data/python/testsuite.py +382 -0
- data/python/util.i +517 -0
- data/ruby/.deps/xapian_wrap.Plo +494 -0
- data/ruby/.libs/_xapian.bundle +0 -0
- data/ruby/.libs/_xapian.bundle.dSYM/Contents/Info.plist +25 -0
- data/ruby/.libs/_xapian.bundle.dSYM/Contents/Resources/DWARF/_xapian.bundle +0 -0
- data/ruby/.libs/_xapian.la +35 -0
- data/ruby/.libs/_xapian.lai +35 -0
- data/ruby/Makefile +854 -0
- data/ruby/Makefile.am +62 -0
- data/ruby/Makefile.in +854 -0
- data/ruby/_xapian.la +35 -0
- data/ruby/docs/Makefile +487 -0
- data/ruby/docs/Makefile.am +50 -0
- data/ruby/docs/Makefile.in +487 -0
- data/ruby/docs/examples/simpleexpand.rb +98 -0
- data/ruby/docs/examples/simpleindex.rb +60 -0
- data/ruby/docs/examples/simplematchdecider.rb +74 -0
- data/ruby/docs/examples/simplesearch.rb +63 -0
- data/ruby/docs/index.html +197 -0
- data/ruby/smoketest.rb +211 -0
- data/ruby/util.i +232 -0
- data/ruby/xapian.rb +280 -0
- data/ruby/xapian_wrap.cc +25837 -0
- data/ruby/xapian_wrap.h +65 -0
- data/ruby/xapian_wrap.lo +12 -0
- data/skiptest +2 -0
- data/stamp-h1 +1 -0
- data/tcl8/.deps/xapian_wrap.Plo +1 -0
- data/tcl8/Makefile +835 -0
- data/tcl8/Makefile.am +49 -0
- data/tcl8/Makefile.in +835 -0
- data/tcl8/docs/Makefile +448 -0
- data/tcl8/docs/Makefile.am +14 -0
- data/tcl8/docs/Makefile.in +448 -0
- data/tcl8/docs/examples/simpleexpand.tcl +104 -0
- data/tcl8/docs/examples/simpleindex.tcl +68 -0
- data/tcl8/docs/examples/simplesearch.tcl +66 -0
- data/tcl8/docs/index.html +208 -0
- data/tcl8/except.i +48 -0
- data/tcl8/pkgIndex.tcl +1 -0
- data/tcl8/pkgIndex.tcl.in +1 -0
- data/tcl8/run-tcl-test +15 -0
- data/tcl8/runtest.tcl +29 -0
- data/tcl8/smoketest.tcl +155 -0
- data/tcl8/util.i +76 -0
- data/tcl8/xapian_wrap.cc +20900 -0
- data/xapian-bindings.spec +206 -0
- data/xapian-bindings.spec.in +206 -0
- data/xapian-version.h +1 -0
- data/xapian-version.h.in +1 -0
- data/xapian.i +939 -0
- metadata +395 -0
data/ruby/smoketest.rb
ADDED
@@ -0,0 +1,211 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
#
|
3
|
+
# smoketest.rb - test Xapian bindings for Ruby
|
4
|
+
# Original version by Paul Legato (plegato@nks.net), 4/17/2006
|
5
|
+
#
|
6
|
+
# Originally based on smoketest.php from the PHP4 bindings.
|
7
|
+
#
|
8
|
+
# Copyright (C) 2006 Networked Knowledge Systems, Inc.
|
9
|
+
# Copyright (C) 2008,2009 Olly Betts
|
10
|
+
#
|
11
|
+
# This program is free software; you can redistribute it and/or
|
12
|
+
# modify it under the terms of the GNU General Public License as
|
13
|
+
# published by the Free Software Foundation; either version 2 of the
|
14
|
+
# License, or (at your option) any later version.
|
15
|
+
#
|
16
|
+
# This program is distributed in the hope that it will be useful,
|
17
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19
|
+
# GNU General Public License for more details.
|
20
|
+
#
|
21
|
+
# You should have received a copy of the GNU General Public License
|
22
|
+
# along with this program; if not, write to the Free Software
|
23
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
|
24
|
+
# USA
|
25
|
+
|
26
|
+
require 'test/unit'
|
27
|
+
require 'xapian'
|
28
|
+
|
29
|
+
class TestMatchDecider < Xapian::MatchDecider
|
30
|
+
def __call__(doc)
|
31
|
+
return doc.value(0) == "yes"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class XapianSmoketest < Test::Unit::TestCase
|
36
|
+
|
37
|
+
def setup
|
38
|
+
@stem = Xapian::Stem.new("english")
|
39
|
+
|
40
|
+
@doc = Xapian::Document.new()
|
41
|
+
@doc.data = "is there anybody out there?"
|
42
|
+
@doc.add_posting(@stem.call("is"), 1)
|
43
|
+
@doc.add_posting(@stem.call("there"), 2)
|
44
|
+
@doc.add_posting(@stem.call("anybody"), 3)
|
45
|
+
@doc.add_posting(@stem.call("out"), 4)
|
46
|
+
@doc.add_posting(@stem.call("there"), 5)
|
47
|
+
@doc.add_term("XYzzy")
|
48
|
+
|
49
|
+
@db = Xapian::inmemory_open()
|
50
|
+
@db.add_document(@doc)
|
51
|
+
|
52
|
+
@enq = Xapian::Enquire.new(@db)
|
53
|
+
end # setup
|
54
|
+
|
55
|
+
def test_version
|
56
|
+
# Test the version number reporting functions give plausible results.
|
57
|
+
@v = sprintf("%d.%d.%d", Xapian::major_version(), Xapian::minor_version(),
|
58
|
+
Xapian::revision())
|
59
|
+
@v2 = Xapian::version_string()
|
60
|
+
assert_equal(@v2, @v)
|
61
|
+
end # test_version
|
62
|
+
|
63
|
+
def test_stem
|
64
|
+
assert_equal("Xapian::Stem(english)", @stem.description())
|
65
|
+
|
66
|
+
assert_equal("is", @stem.call("is"))
|
67
|
+
assert_equal("go", @stem.call("going"))
|
68
|
+
assert_equal("want", @stem.call("wanted"))
|
69
|
+
assert_equal("refer", @stem.call("reference"))
|
70
|
+
end # test_stem
|
71
|
+
|
72
|
+
# subtests are those on which some test_foo() method depends.
|
73
|
+
def test_000_document
|
74
|
+
assert_not_nil(@doc)
|
75
|
+
|
76
|
+
assert_equal("is there anybody out there?", @doc.data())
|
77
|
+
|
78
|
+
assert_equal(@doc.termlist_count(), 5)
|
79
|
+
assert_equal("XYzzy", @doc.terms().first.term)
|
80
|
+
|
81
|
+
@doc.add_term("foo")
|
82
|
+
assert_equal(6, @doc.termlist_count())
|
83
|
+
assert_equal(@doc.terms.size(), @doc.termlist_count())
|
84
|
+
|
85
|
+
end # test_document
|
86
|
+
|
87
|
+
def test_001_database
|
88
|
+
assert_not_nil(@db)
|
89
|
+
assert_equal("WritableDatabase()", @db.description())
|
90
|
+
assert_equal(1, @db.doccount())
|
91
|
+
end # test_database
|
92
|
+
|
93
|
+
def test_002_queries
|
94
|
+
assert_equal("Xapian::Query((smoke OR test OR terms))",
|
95
|
+
Xapian::Query.new(Xapian::Query::OP_OR ,["smoke", "test", "terms"]).description())
|
96
|
+
|
97
|
+
phraseQuery = Xapian::Query.new(Xapian::Query::OP_PHRASE ,["smoke", "test", "tuple"])
|
98
|
+
xorQuery = Xapian::Query.new(Xapian::Query::OP_XOR, [ Xapian::Query.new("smoke"), phraseQuery, "string" ])
|
99
|
+
|
100
|
+
assert_equal("Xapian::Query((smoke PHRASE 3 test PHRASE 3 tuple))", phraseQuery.description())
|
101
|
+
assert_equal("Xapian::Query((smoke XOR (smoke PHRASE 3 test PHRASE 3 tuple) XOR string))", xorQuery.description())
|
102
|
+
|
103
|
+
assert_equal([Xapian::Term.new("smoke", 1),
|
104
|
+
Xapian::Term.new("string", 1),
|
105
|
+
Xapian::Term.new("test", 1),
|
106
|
+
Xapian::Term.new("tuple", 1)], xorQuery.terms())
|
107
|
+
|
108
|
+
assert_equal(Xapian::Query::OP_ELITE_SET, 10)
|
109
|
+
end # test_queries
|
110
|
+
|
111
|
+
def test_003_enquire
|
112
|
+
@enq = Xapian::Enquire.new(@db)
|
113
|
+
assert_not_nil(@enq)
|
114
|
+
|
115
|
+
@enq.query = Xapian::Query.new(Xapian::Query::OP_OR, "there", "is")
|
116
|
+
mset = @enq.mset(0, 10)
|
117
|
+
|
118
|
+
assert_equal(1, mset.size())
|
119
|
+
|
120
|
+
# Feature test for Enquire.matching_terms()
|
121
|
+
assert_equal(2, @enq.matching_terms(mset.hit(0)).size())
|
122
|
+
assert_equal([Xapian::Term.new("is", 1), Xapian::Term.new("there", 1)],
|
123
|
+
@enq.matching_terms(mset.hit(0)))
|
124
|
+
end # test_enquire
|
125
|
+
|
126
|
+
def test_004_mset_iterator
|
127
|
+
@enq = Xapian::Enquire.new(@db)
|
128
|
+
assert_not_nil(@enq)
|
129
|
+
|
130
|
+
@enq.query = Xapian::Query.new(Xapian::Query::OP_OR, "there", "is")
|
131
|
+
mset = @enq.mset(0, 10)
|
132
|
+
|
133
|
+
assert_equal(mset.matches().size(), mset.size())
|
134
|
+
end
|
135
|
+
|
136
|
+
|
137
|
+
def test_005_eset_iterator
|
138
|
+
rset = Xapian::RSet.new
|
139
|
+
|
140
|
+
rset.add_document(1)
|
141
|
+
|
142
|
+
@enq = Xapian::Enquire.new(@db)
|
143
|
+
@enq.query = Xapian::Query.new(Xapian::Query::OP_OR, "there", "is")
|
144
|
+
|
145
|
+
eset = @enq.eset(10, rset)
|
146
|
+
assert_not_nil(eset)
|
147
|
+
|
148
|
+
assert_equal(3, eset.terms.size())
|
149
|
+
end # test_eset_iter
|
150
|
+
|
151
|
+
# Feature test for Database.allterms
|
152
|
+
def test_006_database_allterms
|
153
|
+
assert_equal(5, @db.allterms.size())
|
154
|
+
end
|
155
|
+
|
156
|
+
# Feature test for Database.postlist
|
157
|
+
def test_007_database_postlist
|
158
|
+
assert_equal(1, @db.postlist("there").size())
|
159
|
+
end
|
160
|
+
|
161
|
+
# Feature test for Database.termlist
|
162
|
+
def test_008_database_termlist
|
163
|
+
assert_equal(5, @db.termlist(1).size())
|
164
|
+
end
|
165
|
+
|
166
|
+
# Feature test for Database.positionlist
|
167
|
+
def test_009_database_positionlist
|
168
|
+
assert_equal(2, @db.positionlist(1, "there").size())
|
169
|
+
end
|
170
|
+
|
171
|
+
# Feature test for Document.values
|
172
|
+
def test_010_document_values
|
173
|
+
assert_equal(0, @doc.values().size())
|
174
|
+
end
|
175
|
+
|
176
|
+
def test_011_matchdecider
|
177
|
+
@doc = Xapian::Document.new()
|
178
|
+
@doc.data = "Two"
|
179
|
+
@doc.add_posting(@stem.call("out"), 1)
|
180
|
+
@doc.add_posting(@stem.call("source"), 2)
|
181
|
+
@doc.add_value(0, "yes")
|
182
|
+
@db.add_document(@doc)
|
183
|
+
|
184
|
+
@query = Xapian::Query.new(@stem.call("out"))
|
185
|
+
enquire = Xapian::Enquire.new(@db)
|
186
|
+
enquire.query = @query
|
187
|
+
mset = enquire.mset(0, 10, nil, TestMatchDecider.new)
|
188
|
+
assert_equal(mset.size(), 1)
|
189
|
+
assert_equal(mset.docid(0), 2)
|
190
|
+
end
|
191
|
+
|
192
|
+
def test_012_metadata
|
193
|
+
assert_equal(@db.get_metadata('Foo'), '')
|
194
|
+
@db.set_metadata('Foo', 'Foo')
|
195
|
+
assert_equal(@db.get_metadata('Foo'), 'Foo')
|
196
|
+
end
|
197
|
+
|
198
|
+
def test_013_scaleweight
|
199
|
+
query = Xapian::Query.new("foo")
|
200
|
+
query2 = Xapian::Query.new(Xapian::Query::OP_SCALE_WEIGHT, query, 5);
|
201
|
+
assert_equal(query2.description(), "Xapian::Query(5 * foo)")
|
202
|
+
end
|
203
|
+
|
204
|
+
def test_014_sortable_serialise
|
205
|
+
# In Xapian 1.0.13/1.1.1 and earlier, the SWIG generated wrapper code
|
206
|
+
# didn't handle integer values > MAXINT for double parameters.
|
207
|
+
v = 51767811298
|
208
|
+
assert_equal(v, Xapian::sortable_unserialise(Xapian::sortable_serialise(v)))
|
209
|
+
end
|
210
|
+
|
211
|
+
end # class XapianSmoketest
|
data/ruby/util.i
ADDED
@@ -0,0 +1,232 @@
|
|
1
|
+
%{
|
2
|
+
/* ruby/util.i: custom Ruby typemaps for xapian-bindings
|
3
|
+
*
|
4
|
+
* Original version by Paul Legato (plegato@nks.net), 4/17/06.
|
5
|
+
* Based on the php4 and python util.i files.
|
6
|
+
*
|
7
|
+
* Copyright (C) 2006 Networked Knowledge Systems, Inc.
|
8
|
+
* Copyright (C) 2006,2007,2009 Olly Betts
|
9
|
+
*
|
10
|
+
* This program is free software; you can redistribute it and/or
|
11
|
+
* modify it under the terms of the GNU General Public License as
|
12
|
+
* published by the Free Software Foundation; either version 2 of the
|
13
|
+
* License, or (at your option) any later version.
|
14
|
+
*
|
15
|
+
* This program is distributed in the hope that it will be useful,
|
16
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18
|
+
* GNU General Public License for more details.
|
19
|
+
*
|
20
|
+
* You should have received a copy of the GNU General Public License
|
21
|
+
* along with this program; if not, write to the Free Software
|
22
|
+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
|
23
|
+
* USA
|
24
|
+
*
|
25
|
+
*/
|
26
|
+
|
27
|
+
%}
|
28
|
+
|
29
|
+
// Use SWIG directors for Ruby wrappers.
|
30
|
+
#define XAPIAN_SWIG_DIRECTORS
|
31
|
+
|
32
|
+
// We don't use the Iterator and ConstIterator wrappers which SWIG now offers,
|
33
|
+
// so disable them to reduce the generated C++ wrapper code.
|
34
|
+
#define SWIG_NO_EXPORT_ITERATOR_METHODS
|
35
|
+
|
36
|
+
/////////////////////////////////////
|
37
|
+
// Rename function and method names to match Ruby conventions
|
38
|
+
// e.g. from get_data to data and from set_data to data=
|
39
|
+
|
40
|
+
// Getters
|
41
|
+
%rename("available_languages") get_available_languages;
|
42
|
+
%rename("avlength") get_avlength;
|
43
|
+
%rename("collapse_count") get_collapse_count;
|
44
|
+
%rename("collection_freq") get_collection_freq;
|
45
|
+
%rename("context") get_context;
|
46
|
+
%rename("data") get_data;
|
47
|
+
%rename("default_op") get_default_op;
|
48
|
+
%rename("description") get_description;
|
49
|
+
%rename("docid") get_docid;
|
50
|
+
%rename("document_id") get_document_id;
|
51
|
+
%rename("document_percentage") get_document_percentage;
|
52
|
+
%rename("doccount") get_doccount;
|
53
|
+
%rename("doclength") get_doclength;
|
54
|
+
%rename("document") get_document;
|
55
|
+
%rename("ebound") get_ebound;
|
56
|
+
%rename("errno") get_errno;
|
57
|
+
%rename("eset") get_eset;
|
58
|
+
%rename("firstitem") get_firstitem;
|
59
|
+
%rename("hit") get_hit;
|
60
|
+
%rename("lastdocid") get_lastdocid;
|
61
|
+
%rename("length") get_length;
|
62
|
+
%rename("matches_estimated") get_matches_estimated;
|
63
|
+
%rename("matches_lower_bound") get_matches_lower_bound;
|
64
|
+
%rename("matches_upper_bound") get_matches_upper_bound;
|
65
|
+
%rename("matching_terms") get_matching_terms;
|
66
|
+
%rename("max_attained") get_max_attained;
|
67
|
+
%rename("max_possible") get_max_possible;
|
68
|
+
%rename("maxextra") get_maxextra;
|
69
|
+
%rename("maxpart") get_maxpart;
|
70
|
+
%rename("mset") get_mset;
|
71
|
+
%rename("msg") get_msg;
|
72
|
+
%rename("op_name") get_op_name;
|
73
|
+
%rename("percent") get_percent;
|
74
|
+
%rename("query") get_query;
|
75
|
+
%rename("rank") get_rank;
|
76
|
+
%rename("sumextra") get_sumextra;
|
77
|
+
%rename("sumpart") get_sumpart;
|
78
|
+
%rename("sumpart_needs_doclength") get_sumpart_needs_doclength;
|
79
|
+
%rename("termfreq") get_termfreq;
|
80
|
+
%rename("terms") get_terms;
|
81
|
+
%rename("term") get_term;
|
82
|
+
%rename("termpos") get_termpos;
|
83
|
+
%rename("termname") get_termname;
|
84
|
+
%rename("termweight") get_termweight;
|
85
|
+
%rename("type") get_type;
|
86
|
+
%rename("value") get_value;
|
87
|
+
%rename("valueno") get_valueno;
|
88
|
+
%rename("wdf") get_wdf;
|
89
|
+
%rename("weight") get_weight;
|
90
|
+
|
91
|
+
// These are 'dangerous' methods; i.e. they can cause a segfault if used
|
92
|
+
// improperly. We prefix with _dangerous_ so that Ruby users will not use them
|
93
|
+
// inadvertently.
|
94
|
+
//
|
95
|
+
// There is a safe wrapper for their functionality provided in xapian.rb.
|
96
|
+
|
97
|
+
// in Xapian::Document and Xapian::Database
|
98
|
+
%rename("_dangerous_termlist_begin") termlist_begin;
|
99
|
+
%rename("_dangerous_termlist_end") termlist_end;
|
100
|
+
// in Xapian::Query
|
101
|
+
%rename("_dangerous_terms_begin") get_terms_begin;
|
102
|
+
%rename("_dangerous_terms_end") get_terms_end;
|
103
|
+
// in Xapian::Enquire
|
104
|
+
%rename("_dangerous_matching_terms_begin") get_matching_terms_begin;
|
105
|
+
%rename("_dangerous_matching_terms_end") get_matching_terms_end;
|
106
|
+
// in Xapian::Database
|
107
|
+
%rename("_dangerous_allterms_begin") allterms_begin;
|
108
|
+
%rename("_dangerous_allterms_end") allterms_end;
|
109
|
+
// in Xapian::Database
|
110
|
+
%rename("_dangerous_postlist_begin") postlist_begin;
|
111
|
+
%rename("_dangerous_postlist_end") postlist_end;
|
112
|
+
// in Xapian::Database
|
113
|
+
%rename("_dangerous_positionlist_begin") positionlist_begin;
|
114
|
+
%rename("_dangerous_positionlist_end") positionlist_end;
|
115
|
+
// in Xapian::Document
|
116
|
+
%rename("_dangerous_values_begin") values_begin;
|
117
|
+
%rename("_dangerous_values_end") values_end;
|
118
|
+
|
119
|
+
|
120
|
+
// MSetIterators are not dangerous, just inconvenient to use within a Ruby
|
121
|
+
// idiom.
|
122
|
+
%rename ("_begin") begin;
|
123
|
+
%rename ("_end") end;
|
124
|
+
%rename ("_back") back;
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
// Setters
|
129
|
+
%rename("collapse_key=") set_collapse_key;
|
130
|
+
%rename("cutoff!") set_cutoff;
|
131
|
+
%rename("data=") set_data;
|
132
|
+
%rename("database=") set_database;
|
133
|
+
%rename("default_op=") set_default_op;
|
134
|
+
%rename("docid_order=") set_docid_order;
|
135
|
+
%rename("document=") set_document;
|
136
|
+
%rename("query=") set_query(const Query &);
|
137
|
+
%rename("query!") set_query(const Query &, termcount qlen);
|
138
|
+
%rename("sort_by_relevance!") set_sort_by_relevance;
|
139
|
+
%rename("sort_by_relevance_then_value!") set_sort_by_relevance_then_value;
|
140
|
+
%rename("sort_by_value_then_relevance!") set_sort_by_value_then_relevance;
|
141
|
+
%rename("sort_by_value!") set_sort_by_value;
|
142
|
+
%rename("stemmer=") set_stemmer;
|
143
|
+
%rename("stemming_strategy=") set_stemming_strategy;
|
144
|
+
%rename("stopper=") set_stopper;
|
145
|
+
%rename("weighting_scheme=") set_weighting_scheme;
|
146
|
+
|
147
|
+
// Booleans
|
148
|
+
%predicate empty;
|
149
|
+
|
150
|
+
// Other deprecated methods
|
151
|
+
%ignore Xapian::xapian_version_string();
|
152
|
+
%ignore Xapian::xapian_major_version();
|
153
|
+
%ignore Xapian::xapian_minor_version();
|
154
|
+
%ignore Xapian::xapian_revision();
|
155
|
+
|
156
|
+
#define XAPIAN_MIXED_VECTOR_QUERY_INPUT_TYPEMAP
|
157
|
+
/*
|
158
|
+
* Check to see what is equivalent to a C++ Vector for the purposes of a Query
|
159
|
+
* instantiation.
|
160
|
+
* At the moment, we take Ruby Arrays.
|
161
|
+
*/
|
162
|
+
%typemap(typecheck, precedence=500) const vector<Xapian::Query> & {
|
163
|
+
$1 = (TYPE($input) == T_ARRAY);
|
164
|
+
|
165
|
+
/* Says Olly:
|
166
|
+
* Currently, the only wrapped method which takes a Ruby array is the
|
167
|
+
* "extra" constructor Query(OP, ARRAY), where ARRAY can contain any mix of
|
168
|
+
* strings and Query objects.
|
169
|
+
*
|
170
|
+
* If we ever had a method (or function) which had two overloaded forms
|
171
|
+
* only differentiated by what type of array can be passed we'd need to
|
172
|
+
* look at the type of the array element in the typecheck typemaps.
|
173
|
+
*/
|
174
|
+
}
|
175
|
+
|
176
|
+
/*
|
177
|
+
* Convert Ruby Arrays to C++ Vectors for Query instantiation.
|
178
|
+
*/
|
179
|
+
%typemap(in) const vector<Xapian::Query> & (vector<Xapian::Query> v) {
|
180
|
+
if (TYPE($input) != T_ARRAY) {
|
181
|
+
SWIG_exception(SWIG_ValueError, "expected array of queries");
|
182
|
+
}
|
183
|
+
|
184
|
+
int numitems = RARRAY_LEN($input);
|
185
|
+
v.reserve(numitems);
|
186
|
+
for (int i = 0; i < numitems; ++i) {
|
187
|
+
VALUE arrayEntry = rb_ary_entry($input, i);
|
188
|
+
if (TYPE(arrayEntry) == T_STRING) {
|
189
|
+
v.push_back(Xapian::Query(string(RSTRING_PTR(arrayEntry),
|
190
|
+
RSTRING_LEN(arrayEntry))));
|
191
|
+
}
|
192
|
+
else {
|
193
|
+
// array element may be a Xapian::Query object. Add it if it is,
|
194
|
+
// otherwise error out.
|
195
|
+
Xapian::Query *subq = 0;
|
196
|
+
if (SWIG_ConvertPtr(arrayEntry, (void **)&subq,
|
197
|
+
SWIGTYPE_p_Xapian__Query, 0) < 0) {
|
198
|
+
subq = 0;
|
199
|
+
}
|
200
|
+
if (!subq) {
|
201
|
+
SWIG_exception(SWIG_ValueError, "elements of Arrays passed to Query must be either Strings or other Queries");
|
202
|
+
}
|
203
|
+
v.push_back(*subq);
|
204
|
+
}
|
205
|
+
|
206
|
+
}
|
207
|
+
|
208
|
+
$1 = &v;
|
209
|
+
}
|
210
|
+
|
211
|
+
|
212
|
+
#if 0
|
213
|
+
// We don't want to generate get_matching_terms this way for Ruby - instead
|
214
|
+
// we define it in xapian.rb.
|
215
|
+
/*
|
216
|
+
* Convert a begin/end pair of TermIterators into Arrays of Terms.
|
217
|
+
*/
|
218
|
+
#define XAPIAN_TERMITERATOR_PAIR_OUTPUT_TYPEMAP
|
219
|
+
%typemap(out) std::pair<Xapian::TermIterator, Xapian::TermIterator> {
|
220
|
+
$result = rb_ary_new();
|
221
|
+
|
222
|
+
for (Xapian::TermIterator i = $1.first; i != $1.second; ++i) {
|
223
|
+
VALUE str = rb_str_new((*i).data(), (*i).size());
|
224
|
+
rb_ary_push($result, str);
|
225
|
+
}
|
226
|
+
}
|
227
|
+
#endif
|
228
|
+
|
229
|
+
// For MatchDecider::operator() and ExpandDecider::operator().
|
230
|
+
%typemap(directorout) int = bool;
|
231
|
+
|
232
|
+
/* vim:set syntax=cpp:set noexpandtab: */
|
data/ruby/xapian.rb
ADDED
@@ -0,0 +1,280 @@
|
|
1
|
+
# :title:Ruby Xapian bindings
|
2
|
+
# =Ruby Xapian bindings
|
3
|
+
#
|
4
|
+
# Original version by Paul Legato (plegato@nks.net), 4/20/06.
|
5
|
+
#
|
6
|
+
# Copyright (C) 2006 Networked Knowledge Systems, Inc.
|
7
|
+
#
|
8
|
+
# This program is free software; you can redistribute it and/or
|
9
|
+
# modify it under the terms of the GNU General Public License as
|
10
|
+
# published by the Free Software Foundation; either version 2 of the
|
11
|
+
# License, or (at your option) any later version.
|
12
|
+
#
|
13
|
+
# This program is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU General Public License
|
19
|
+
# along with this program; if not, write to the Free Software
|
20
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
|
21
|
+
# USA
|
22
|
+
#
|
23
|
+
# ==Underscore methods
|
24
|
+
# Note: Methods whose names start with an underscore character _ are internal
|
25
|
+
# methods from the C++ API. Their functionality is not accessible in a
|
26
|
+
# Ruby-friendly way, so this file provides wrapper code to make it easier to
|
27
|
+
# use them from a Ruby programming idiom. Most are also dangerous insofar as
|
28
|
+
# misusing them can cause your program to segfault. In particular, all of
|
29
|
+
# Xapian's *Iterator classes are wrapped into nice Ruby-friendly Arrays.
|
30
|
+
#
|
31
|
+
# It should never be necessary to use any method whose name starts with an
|
32
|
+
# underscore from user-level code. Make sure you are _VERY_ certain that you
|
33
|
+
# know exactly what you're doing if you do use one of these methods. Beware.
|
34
|
+
# You've been warned...
|
35
|
+
#
|
36
|
+
|
37
|
+
|
38
|
+
module Xapian
|
39
|
+
######## load the SWIG-generated library
|
40
|
+
require '_xapian'
|
41
|
+
|
42
|
+
|
43
|
+
# iterate over two dangerous iterators (i.e. those that can cause segfaults
|
44
|
+
# if used improperly.)
|
45
|
+
# Return the results as an Array.
|
46
|
+
# Users should never need to use this method.
|
47
|
+
#
|
48
|
+
# Takes a block that returns some appropriate Ruby object to wrap the
|
49
|
+
# underlying Iterator
|
50
|
+
def _safelyIterate(dangerousStart, dangerousEnd) #:nodoc:
|
51
|
+
retval = Array.new
|
52
|
+
|
53
|
+
item = dangerousStart
|
54
|
+
lastTerm = dangerousEnd
|
55
|
+
|
56
|
+
return retval if dangerousStart.equals(dangerousEnd)
|
57
|
+
|
58
|
+
begin
|
59
|
+
retval.push(yield(item))
|
60
|
+
item.next()
|
61
|
+
end while not item.equals(lastTerm) # must use primitive C++ comparator
|
62
|
+
|
63
|
+
return retval
|
64
|
+
end # _safelyIterate
|
65
|
+
module_function :_safelyIterate
|
66
|
+
|
67
|
+
#--
|
68
|
+
### safe Ruby wrapper for the dangerous C++ Xapian::TermIterator class
|
69
|
+
class Xapian::Term
|
70
|
+
attr_accessor :term, :wdf, :termfreq
|
71
|
+
|
72
|
+
def initialize(term, wdf=nil, termfreq=nil)
|
73
|
+
@term = term
|
74
|
+
@wdf = wdf
|
75
|
+
@termfreq = termfreq
|
76
|
+
end
|
77
|
+
|
78
|
+
def ==(other)
|
79
|
+
return other.is_a?(Xapian::Term) && other.term == @term && other.wdf == @wdf && other.termfreq == @termfreq
|
80
|
+
end
|
81
|
+
end # class Term
|
82
|
+
|
83
|
+
### Ruby wrapper for a Match, i.e. a Xapian::MSetIterator (Match Set) in C++.
|
84
|
+
# it's no longer an iterator in the Ruby version, but we want to preserve its
|
85
|
+
# non-iterative data.
|
86
|
+
# (MSetIterator is not dangerous, but it is inconvenient to use from a Ruby
|
87
|
+
# idiom, so we wrap it..)
|
88
|
+
class Xapian::Match
|
89
|
+
attr_accessor :docid, :document, :rank, :weight, :collapse_count, :percent
|
90
|
+
|
91
|
+
def initialize(docid, document, rank, weight, collapse_count, percent)
|
92
|
+
@docid = docid
|
93
|
+
@document = document
|
94
|
+
@rank = rank
|
95
|
+
@weight = weight
|
96
|
+
@collapse_count = collapse_count
|
97
|
+
@percent = percent
|
98
|
+
end # initialize
|
99
|
+
|
100
|
+
def ==(other)
|
101
|
+
return other.is_a?(Xapian::Match) && other.docid == @docid && other.rank == @rank &&
|
102
|
+
other.weight == @weight && other.collapse_count == @collapse_count && other.percent == @percent
|
103
|
+
end
|
104
|
+
end # class Xapian::Match
|
105
|
+
|
106
|
+
# Ruby wrapper for an ExpandTerm, i.e. a Xapian::ESetIterator in C++
|
107
|
+
# Not dangerous, but inconvenient to use from a Ruby programming idiom, so we
|
108
|
+
# wrap it.
|
109
|
+
class Xapian::ExpandTerm
|
110
|
+
attr_accessor :name, :weight
|
111
|
+
|
112
|
+
def initialize(name, weight)
|
113
|
+
@name = name
|
114
|
+
@weight = weight
|
115
|
+
end # initialize
|
116
|
+
|
117
|
+
def ==(other)
|
118
|
+
return other.is_a?(Xapian::ExpandTerm) && other.name == @name && other.weight == @weight
|
119
|
+
end
|
120
|
+
|
121
|
+
end # Xapian::ExpandTerm
|
122
|
+
|
123
|
+
# Ruby wrapper for Xapian::ValueIterator
|
124
|
+
class Xapian::Value
|
125
|
+
attr_accessor :value, :valueno
|
126
|
+
|
127
|
+
def initialize(value, valueno)
|
128
|
+
@value = value
|
129
|
+
@valueno = valueno
|
130
|
+
end # initialize
|
131
|
+
|
132
|
+
def ==(other)
|
133
|
+
return other.is_a?(Xapian::Value) && other.value == @value && other.valueno == @valueno
|
134
|
+
end
|
135
|
+
end # Xapian::Value
|
136
|
+
|
137
|
+
# Refer to the
|
138
|
+
# {Xapian::Document C++ API documentation}[http://xapian.org/docs/apidoc/html/classXapian_1_1Document.html]
|
139
|
+
# for methods not specific to Ruby.
|
140
|
+
#--
|
141
|
+
# Extend Xapian::Document with a nice wrapper for its nasty input_iterators
|
142
|
+
class Xapian::Document
|
143
|
+
def terms
|
144
|
+
Xapian._safelyIterate(self._dangerous_termlist_begin(), self._dangerous_termlist_end()) { |item|
|
145
|
+
Xapian::Term.new(item.term, item.wdf)
|
146
|
+
}
|
147
|
+
end # terms
|
148
|
+
|
149
|
+
def values
|
150
|
+
Xapian._safelyIterate(self._dangerous_values_begin(), self._dangerous_values_end()) { |item|
|
151
|
+
Xapian::Value.new(item.value, item.valueno)
|
152
|
+
}
|
153
|
+
end # terms
|
154
|
+
|
155
|
+
end # class Xapian::Document
|
156
|
+
|
157
|
+
# Refer to the
|
158
|
+
# {Xapian::Query C++ API documentation}[http://xapian.org/docs/apidoc/html/classXapian_1_1Query.html]
|
159
|
+
# for methods not specific to Ruby.
|
160
|
+
#--
|
161
|
+
# Extend Xapian::Query with a nice wrapper for its dangerous iterators
|
162
|
+
class Xapian::Query
|
163
|
+
def terms
|
164
|
+
Xapian._safelyIterate(self._dangerous_terms_begin(), self._dangerous_terms_end()) { |item|
|
165
|
+
Xapian::Term.new(item.term, item.wdf)
|
166
|
+
# termfreq is not supported by TermIterators from Queries
|
167
|
+
}
|
168
|
+
end
|
169
|
+
end # Xapian::Query
|
170
|
+
|
171
|
+
# Refer to the
|
172
|
+
# {Xapian::Enquire C++ API documentation}[http://xapian.org/docs/apidoc/html/classXapian_1_1Enquire.html]
|
173
|
+
# for methods not specific to Ruby.
|
174
|
+
#--
|
175
|
+
# Extend Xapian::Enquire with a nice wrapper for its dangerous iterators
|
176
|
+
class Xapian::Enquire
|
177
|
+
# Get matching terms for some document.
|
178
|
+
# document can be either a Xapian::DocID or a Xapian::MSetIterator
|
179
|
+
def matching_terms(document)
|
180
|
+
Xapian._safelyIterate(self._dangerous_matching_terms_begin(document),
|
181
|
+
self._dangerous_matching_terms_end(document)) { |item|
|
182
|
+
Xapian::Term.new(item.term, item.wdf)
|
183
|
+
}
|
184
|
+
end
|
185
|
+
end # Xapian::Enquire
|
186
|
+
|
187
|
+
# Refer to the
|
188
|
+
# {Xapian::MSet C++ API documentation}[http://xapian.org/docs/apidoc/html/classXapian_1_1MSet.html]
|
189
|
+
# for methods not specific to Ruby.
|
190
|
+
#--
|
191
|
+
# MSetIterators are not dangerous, just inconvenient to use within a Ruby
|
192
|
+
# programming idiom. So we wrap them.
|
193
|
+
class Xapian::MSet
|
194
|
+
def matches
|
195
|
+
Xapian._safelyIterate(self._begin(),
|
196
|
+
self._end()) { |item|
|
197
|
+
Xapian::Match.new(item.docid, item.document, item.rank, item.weight, item.collapse_count, item.percent)
|
198
|
+
}
|
199
|
+
|
200
|
+
end # matches
|
201
|
+
end # Xapian::MSet
|
202
|
+
|
203
|
+
# Refer to the
|
204
|
+
# {Xapian::ESet C++ API documentation}[http://xapian.org/docs/apidoc/html/classXapian_1_1ESet.html]
|
205
|
+
# for methods not specific to Ruby.
|
206
|
+
#--
|
207
|
+
# ESetIterators are not dangerous, just inconvenient to use within a Ruby
|
208
|
+
# programming idiom. So we wrap them.
|
209
|
+
class Xapian::ESet
|
210
|
+
def terms
|
211
|
+
Xapian._safelyIterate(self._begin(),
|
212
|
+
self._end()) { |item|
|
213
|
+
# note: in the ExpandTerm wrapper, we implicitly rename
|
214
|
+
# ESetIterator#termname() (defined in xapian.i) to ExpandTerm#term()
|
215
|
+
Xapian::ExpandTerm.new(item.termname, item.weight)
|
216
|
+
}
|
217
|
+
|
218
|
+
end # terms
|
219
|
+
end # Xapian::ESet
|
220
|
+
|
221
|
+
|
222
|
+
#--
|
223
|
+
# Wrapper for the C++ class Xapian::PostingIterator
|
224
|
+
class Xapian::Posting
|
225
|
+
attr_accessor :docid, :doclength, :wdf
|
226
|
+
|
227
|
+
def initialize(docid, doclength, wdf)
|
228
|
+
@docid = docid
|
229
|
+
@doclength = doclength
|
230
|
+
@wdf = wdf
|
231
|
+
end
|
232
|
+
|
233
|
+
def ==(other)
|
234
|
+
return other.is_a?(Xapian::Posting) && other.docid == @docid && other.doclength == @doclength &&
|
235
|
+
other.wdf == @wdf
|
236
|
+
end
|
237
|
+
end # Xapian::Posting
|
238
|
+
|
239
|
+
# Refer to the
|
240
|
+
# {Xapian::Database C++ API documentation}[http://xapian.org/docs/apidoc/html/classXapian_1_1Database.html]
|
241
|
+
# for methods not specific to Ruby.
|
242
|
+
#--
|
243
|
+
# Wrap some dangerous iterators.
|
244
|
+
class Xapian::Database
|
245
|
+
# Returns an Array of all Xapian::Terms for this database.
|
246
|
+
def allterms
|
247
|
+
Xapian._safelyIterate(self._dangerous_allterms_begin(),
|
248
|
+
self._dangerous_allterms_end()) { |item|
|
249
|
+
Xapian::Term.new(item.term, 0, item.termfreq)
|
250
|
+
}
|
251
|
+
end # allterms
|
252
|
+
|
253
|
+
# Returns an Array of Xapian::Postings for the given term.
|
254
|
+
# term is a string.
|
255
|
+
def postlist(term)
|
256
|
+
Xapian._safelyIterate(self._dangerous_postlist_begin(term),
|
257
|
+
self._dangerous_postlist_end(term)) { |item|
|
258
|
+
Xapian::Posting.new(item.docid, item.doclength, item.wdf)
|
259
|
+
}
|
260
|
+
end # postlist(term)
|
261
|
+
|
262
|
+
# Returns an Array of Terms for the given docid.
|
263
|
+
def termlist(docid)
|
264
|
+
Xapian._safelyIterate(self._dangerous_termlist_begin(docid),
|
265
|
+
self._dangerous_termlist_end(docid)) { |item|
|
266
|
+
Xapian::Term.new(item.term, item.wdf, item.termfreq)
|
267
|
+
}
|
268
|
+
end # termlist(docid)
|
269
|
+
|
270
|
+
# Returns an Array of Xapian::Termpos objects for the given term (a String)
|
271
|
+
# in the given docid.
|
272
|
+
def positionlist(docid, term)
|
273
|
+
Xapian._safelyIterate(self._dangerous_positionlist_begin(docid, term),
|
274
|
+
self._dangerous_positionlist_end(docid, term)) { |item|
|
275
|
+
item.termpos
|
276
|
+
}
|
277
|
+
end # positionlist
|
278
|
+
end # Xapian::Database
|
279
|
+
|
280
|
+
end # Xapian module
|