3 /* perl.i
: SWIG interface file for the Perl bindings
5 * Copyright
(C
) 2009 Kosei Moriyama
6 * Copyright
(C
) 2011,2012,2013,2015,2016 Olly Betts
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.
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.
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
25 /* The XS Xapian never wrapped these
, and they're now deprecated.
*/
26 #define XAPIAN_BINDINGS_SKIP_DEPRECATED_DB_FACTORIES
28 %include ..
/xapian-head.i
30 /* Rename function next
() to increment
() since the keyword
"next" is already
32 %rename
(increment
) *::next
();
33 %rename
(increment_weight
) *::next
(double min_wt
);
35 /* Wrapping constant values.
*/
36 %constant int OP_AND
= Xapian
::Query
::OP_AND
;
37 %constant int OP_OR
= Xapian
::Query
::OP_OR
;
38 %constant int OP_AND_NOT
= Xapian
::Query
::OP_AND_NOT
;
39 %constant int OP_XOR
= Xapian
::Query
::OP_XOR
;
40 %constant int OP_AND_MAYBE
= Xapian
::Query
::OP_AND_MAYBE
;
41 %constant int OP_FILTER
= Xapian
::Query
::OP_FILTER
;
42 %constant int OP_NEAR
= Xapian
::Query
::OP_NEAR
;
43 %constant int OP_PHRASE
= Xapian
::Query
::OP_PHRASE
;
44 %constant int OP_VALUE_RANGE
= Xapian
::Query
::OP_VALUE_RANGE
;
45 %constant int OP_SCALE_WEIGHT
= Xapian
::Query
::OP_SCALE_WEIGHT
;
46 %constant int OP_ELITE_SET
= Xapian
::Query
::OP_ELITE_SET
;
47 %constant int OP_VALUE_GE
= Xapian
::Query
::OP_VALUE_GE
;
48 %constant int OP_SYNONYM
= Xapian
::Query
::OP_SYNONYM
;
49 %constant int OP_MAX
= Xapian
::Query
::OP_MAX
;
50 %constant int OP_WILDCARD
= Xapian
::Query
::OP_WILDCARD
;
51 %constant int OP_VALUE_LE
= Xapian
::Query
::OP_VALUE_LE
;
52 %constant int OP_INVALID
= Xapian
::Query
::OP_INVALID
;
53 %constant int FLAG_BOOLEAN
= Xapian
::QueryParser
::FLAG_BOOLEAN
;
54 %constant int FLAG_PHRASE
= Xapian
::QueryParser
::FLAG_PHRASE
;
55 %constant int FLAG_LOVEHATE
= Xapian
::QueryParser
::FLAG_LOVEHATE
;
56 %constant int FLAG_BOOLEAN_ANY_CASE
= Xapian
::QueryParser
::FLAG_BOOLEAN_ANY_CASE
;
57 %constant int FLAG_WILDCARD
= Xapian
::QueryParser
::FLAG_WILDCARD
;
58 %constant int FLAG_PURE_NOT
= Xapian
::QueryParser
::FLAG_PURE_NOT
;
59 %constant int FLAG_PARTIAL
= Xapian
::QueryParser
::FLAG_PARTIAL
;
60 %constant int FLAG_SPELLING_CORRECTION
= Xapian
::QueryParser
::FLAG_SPELLING_CORRECTION
;
61 %constant int FLAG_SYNONYM
= Xapian
::QueryParser
::FLAG_SYNONYM
;
62 %constant int FLAG_AUTO_SYNONYMS
= Xapian
::QueryParser
::FLAG_AUTO_SYNONYMS
;
63 %constant int FLAG_AUTO_MULTIWORD_SYNONYMS
= Xapian
::QueryParser
::FLAG_AUTO_MULTIWORD_SYNONYMS
;
64 %constant int FLAG_CJK_NGRAM
= Xapian
::QueryParser
::FLAG_CJK_NGRAM
;
65 %constant int FLAG_DEFAULT
= Xapian
::QueryParser
::FLAG_DEFAULT
;
66 %constant int STEM_NONE
= Xapian
::QueryParser
::STEM_NONE
;
67 %constant int STEM_SOME
= Xapian
::QueryParser
::STEM_SOME
;
68 %constant int STEM_ALL
= Xapian
::QueryParser
::STEM_ALL
;
69 %constant int STEM_ALL_Z
= Xapian
::QueryParser
::STEM_ALL_Z
;
70 %constant int FLAG_SPELLING
= Xapian
::TermGenerator
::FLAG_SPELLING
;
71 // FLAG_CJK_NGRAM already set above from QueryParser
(values match
).
72 %constant int WILDCARD_LIMIT_ERROR
= Xapian
::Query
::WILDCARD_LIMIT_ERROR
;
73 %constant int WILDCARD_LIMIT_FIRST
= Xapian
::Query
::WILDCARD_LIMIT_FIRST
;
74 %constant int WILDCARD_LIMIT_MOST_FREQUENT
= Xapian
::Query
::WILDCARD_LIMIT_MOST_FREQUENT
;
77 %feature
("shadow") Xapian
::Enquire
::get_mset
81 my $nargs
= scalar
(@_
);
83 my $type
= ref
( $_
[2] );
84 if
( $type eq 'Xapian
::RSet'
) {
85 # get_mset
(first
, max
, rset
)
86 splice @_
, 2, 0, (0); # insert checkatleast
89 return Xapianc
::Enquire_get_mset
( @_
);
93 %feature
("shadow") Xapian
::Enquire
::set_query
98 if
( ref
( $query
) ne 'Xapian
::Query'
) {
99 $query
= Xapian
::Query-
>new
( $query
, @_
);
100 Xapianc
::Enquire_set_query
( $self
, $query
);
103 my $nargs
= scalar
(@_
);
106 Carp
::carp
( "USAGE: \$enquire->set_query(\$query) or \$enquire->set_query(\$query, \$length)" );
109 Xapianc
::Enquire_set_query
( $self
, $query
, @_
);
113 %feature
("shadow") Xapian
::Enquire
::set_sort_by_key
115 sub set_sort_by_key
{
118 $self
{_sorter
} = $sorter
;
119 Xapianc
::Enquire_set_sort_by_key
( @_
);
123 %feature
("shadow") Xapian
::Enquire
::set_sort_by_key_then_relevance
125 sub set_sort_by_key_then_relevance
{
128 $self
{_sorter
} = $sorter
;
129 Xapianc
::Enquire_set_sort_by_key_then_relevance
( @_
);
133 %feature
("shadow") Xapian
::Enquire
::set_sort_by_relevance_then_key
135 sub set_sort_by_relevance_then_key
{
138 $self
{_sorter
} = $sorter
;
139 Xapianc
::Enquire_set_sort_by_relevance_then_key
( @_
);
144 %extend Xapian
::ESet
{
145 Xapian
::ESetIterator
FETCH(int index
) {
146 return
((*self
)[index
]);
150 /* Xapian
::ESetIterator
*/
151 %extend Xapian
::ESetIterator
{
152 std
::string get_termname
() {
153 return self-
>operator
*();
156 bool equal
(Xapian
::ESetIterator
* that
) {
157 return
((*self
) == (*that
));
160 bool nequal
(Xapian
::ESetIterator
* that
) {
161 return
((*self
) != (*that
));
166 %extend Xapian
::MSet
{
167 Xapian
::MSetIterator
FETCH(int index
) {
168 return
((*self
)[index
]);
172 /* Xapian
::MSetIterator
*/
173 %extend Xapian
::MSetIterator
{
174 bool equal
(Xapian
::MSetIterator
* that
) {
175 return
((*self
) == (*that
));
178 bool nequal
(Xapian
::MSetIterator
* that
) {
179 return
((*self
) != (*that
));
183 /* Xapian
::PositionIterator
*/
184 %extend Xapian
::PositionIterator
{
185 bool equal1
(Xapian
::PositionIterator
* that
) {
186 return
((*self
) == (*that
));
189 bool nequal1
(Xapian
::PositionIterator
* that
) {
190 return
((*self
) != (*that
));
194 /* Xapian
::PostingIterator
*/
195 %extend Xapian
::PostingIterator
{
196 bool equal
(Xapian
::PostingIterator
* that
) {
197 return
((*self
) == (*that
));
200 bool nequal
(Xapian
::PostingIterator
* that
) {
201 return
((*self
) != (*that
));
206 %feature
("shadow") Xapian
::Query
::Query
213 $query
= Xapianc
::new_Query
(@_
);
217 if
( $op
!~
/^\d
+$
/ ) {
218 Carp
::croak
( "USAGE: $class->new('term') or $class->new(OP, <args>)" );
220 if
( $op
== 8 ) { # FIXME
: 8 is OP_VALUE_RANGE
; eliminate hardcoded literal
222 Carp
::croak
( "USAGE: $class->new(OP_VALUE_RANGE, VALNO, START, END)" );
224 $query
= Xapianc
::new_Query
( @_
);
225 } elsif
( $op
== 9 ) { # FIXME
: OP_SCALE_WEIGHT
227 Carp
::croak
( "USAGE: $class->new(OP_SCALE_WEIGHT, QUERY, FACTOR)" );
229 $query
= Xapianc
::new_Query
( @_
);
230 } elsif
( $op
== 11 || $op
== 12 ) { # FIXME
: OP_VALUE_GE
, OP_VALUE_LE
; eliminate hardcoded literals
232 Carp
::croak
( "USAGE: $class->new(OP_VALUE_[GL]E, VALNO, LIMIT)" );
234 $query
= Xapianc
::new_Query
( @_
);
237 $query
= Xapian
::newN
( $op
, \@_
);
250 croak
("Argument $argnum is not a reference.");
251 if
(SvTYPE
(SvRV
($input
)) != SVt_PVAV
)
252 croak
("Argument $argnum is not an array.");
253 tempav
= (AV
*)SvRV
($input
);
254 len
= av_len
(tempav
);
255 $
1 = (SV
**) malloc
((len
+2)*sizeof
(SV
*));
256 for
(i
= 0; i
<= len
; i
++) {
257 tv
= av_fetch
(tempav
, i
, 0);
263 %typemap
(freearg
) SV
** {
268 class XapianSWIGQueryItor
{
274 XapianSWIGQueryItor
() { }
276 void begin
(AV
* array_
) {
285 XapianSWIGQueryItor
& operator++() {
290 Xapian
::Query operator
*() const
{
291 SV
**svp
= av_fetch
(array
, i
, 0);
293 croak
("Unexpected NULL returned by av_fetch()");
296 if
( sv_isa
(sv
, "Xapian::Query")) {
298 SWIG_ConvertPtr
(sv
, (void
**)&q, SWIGTYPE_p_Xapian__Query, 0);
304 const char
* ptr
= SvPV
(sv
, len
);
305 return Xapian
::Query
(string
(ptr
, len
));
308 croak
( "USAGE: Xapian::Query->new(OP, @TERMS_OR_QUERY_OBJECTS)" );
311 bool operator
==(const XapianSWIGQueryItor
& o) {
315 bool operator
!=(const XapianSWIGQueryItor
& o) {
316 return
!(*this
== o
);
319 typedef std
::input_iterator_tag iterator_category
;
320 typedef Xapian
::Query value_type
;
321 typedef Xapian
::termcount_diff difference_type
;
322 typedef Xapian
::Query
* pointer
;
323 typedef Xapian
::Query
& reference;
329 Xapian
::Query
* newN
(int op_
, SV
*q_
) {
330 Xapian
::Query
::op op
= (Xapian
::Query
::op
)op_
;
331 XapianSWIGQueryItor b
, e
;
333 AV
*q
= (AV
*) SvRV
(q_
);
336 e.end
(av_len
(q
) + 1);
339 return new Xapian
::Query
(op
, b
, e
);
340 } catch
(const Xapian
::Error
&error) {
341 croak
( "Exception: %s", error.get_msg
().c_str
() );
346 /* Xapian
::QueryParser
*/
347 %feature
("shadow") Xapian
::QueryParser
::QueryParser
351 my $qp
= Xapianc
::new_QueryParser
();
354 $qp-
>set_database
(@_
) if scalar
(@_
) == 1;
360 %feature
("shadow") Xapian
::QueryParser
::set_stopper
363 my
($self
, $stopper
) = @_
;
364 $self
{_stopper
} = $stopper
;
365 Xapianc
::QueryParser_set_stopper
( @_
);
369 %feature
("shadow") Xapian
::QueryParser
::add_rangeprocessor
371 sub add_rangeprocessor
{
372 my
($self
, $rproc
) = @_
;
373 push @
{$self
{_rproc
}}, $rproc
;
374 Xapianc
::QueryParser_add_rangeprocessor
( @_
);
378 %feature
("shadow") Xapian
::QueryParser
::add_valuerangeprocessor
380 sub add_valuerangeprocessor
{
381 my
($self
, $vrproc
) = @_
;
382 push @
{$self
{_vrproc
}}, $vrproc
;
383 Xapianc
::QueryParser_add_valuerangeprocessor
( @_
);
387 /* Xapian
::SimpleStopper
*/
388 %feature
("shadow") Xapian
::SimpleStopper
::SimpleStopper
392 my $stopper
= Xapianc
::new_SimpleStopper
();
394 bless $stopper
, $class
;
403 %extend Xapian
::SimpleStopper
{
404 bool stop_word
(std
::string term
) {
405 return
(*self
)(term
);
410 %extend Xapian
::Stem
{
411 std
::string stem_word
(std
::string word
) {
412 return
(*self
)(word
);
416 /* Xapian
::TermIterator
*/
417 %rename
(get_termname
) Xapian
::TermIterator
::get_term
;
419 %extend Xapian
::TermIterator
{
420 bool equal
(Xapian
::TermIterator
* that
) {
421 return
((*self
) == (*that
));
424 bool nequal
(Xapian
::TermIterator
* that
) {
425 return
((*self
) != (*that
));
429 /* Xapian
::ValueIterator
*/
430 %extend Xapian
::ValueIterator
{
431 bool equal
(Xapian
::ValueIterator
* that
) {
432 return
((*self
) == (*that
));
435 bool nequal
(Xapian
::ValueIterator
* that
) {
436 return
((*self
) != (*that
));
440 /* Xapian
::WritableDatabase
*/
441 %rename
(replace_document_by_term
) \
442 Xapian
::WritableDatabase
::replace_document
(const std
::string
&,
443 const Xapian
::Document
&);
444 %rename
(delete_document_by_term
) \
445 Xapian
::WritableDatabase
::delete_document
(const std
::string
&);
447 %feature
("shadow") Xapian
::WritableDatabase
::WritableDatabase
452 if
( scalar
(@_
) == 0 ) {
453 # For compatibility with Search
::Xapian
454 @_
= (''
, $Xapianc
::DB_BACKEND_INMEMORY
);
456 $self
= Xapianc
::new_WritableDatabase
(@_
);
457 bless $self
, $pkg if defined
($self
);
463 %include ..
/xapian-headers.i