1 // Disable any deprecation warnings for Xapian methods/functions/classes.
2 #define XAPIAN_DEPRECATED(D) D
7 // Stop Perl headers from even thinking of doing '#define bool char' or
8 // '#define bool int', which they would do with compilers other than GCC.
17 /* Perl's embed.h defines get_context, but that mangles
18 * Xapian::Error::get_context(). */
24 using namespace Xapian;
26 // For some classes, we want extra slots to keep references to set objects in.
31 vector<SV *> matchspies;
33 Enquire_perl(const Xapian::Database & db) : real_obj(db), sorter(NULL) { }
35 void ref_sorter(SV * sv) {
41 void ref_matchspy(SV* sv) {
43 matchspies.push_back(sv);
46 void ref_clear_matchspies(SV* sv) {
47 vector<SV *>::const_iterator i;
48 for (i = matchspies.begin(); i != matchspies.end(); ++i) {
57 ref_clear_matchspies(NULL);
61 struct QueryParser_perl {
66 QueryParser_perl() : real_obj(), stopper(NULL) { }
68 void ref_stopper(SV * sv) {
74 void ref_vrp(SV * sv) {
80 SvREFCNT_dec(stopper);
82 vector<SV *>::const_iterator i;
83 for (i = vrps.begin(); i != vrps.end(); ++i) {
90 struct TermGenerator_perl {
91 TermGenerator real_obj;
94 TermGenerator_perl() : real_obj(), stopper(NULL) { }
96 void ref_stopper(SV * sv) {
102 ~TermGenerator_perl() {
103 SvREFCNT_dec(stopper);
108 #define XAPIAN_PERL_NEW(CLASS, PARAMS) (&((new CLASS##_perl PARAMS)->real_obj))
109 #define XAPIAN_PERL_CAST(CLASS, OBJ) ((CLASS##_perl*)(void*)(OBJ))
110 #define XAPIAN_PERL_REF(CLASS, OBJ, MEMB, SV) XAPIAN_PERL_CAST(CLASS, OBJ)->ref_##MEMB(SV)
111 #define XAPIAN_PERL_DESTROY(CLASS, OBJ) delete XAPIAN_PERL_CAST(CLASS, OBJ)
113 extern void handle_exception(void);
117 * Make operator() call Perl $OBJECT->stop_word
120 class PerlStopper : public Stopper {
122 PerlStopper(SV * obj) { SV_stopper_ref = newRV_inc(obj); }
123 ~PerlStopper() { sv_2mortal(SV_stopper_ref); }
124 bool operator()(const string &term) const {
131 PUSHs(SvRV(SV_stopper_ref));
132 PUSHs(sv_2mortal(newSVpv(term.data(), term.size())));
135 int count = call_method("stop_word", G_SCALAR);
140 croak("callback function should return 1 value, got %d", count);
142 // Breaks with SvTRUE(POPs) ?!?!?!
143 bool r = SvTRUE(SP[0]);
157 class perlMatchDecider : public Xapian::MatchDecider {
161 perlMatchDecider(SV *func) {
162 callback = newSVsv(func);
165 ~perlMatchDecider() {
166 SvREFCNT_dec(callback);
169 bool operator()(const Xapian::Document &doc) const {
177 SV *arg = sv_newmortal();
179 Document *pdoc = new Document(doc);
180 sv_setref_pv(arg, "Search::Xapian::Document", (void *)pdoc);
185 int count = call_sv(callback, G_SCALAR);
189 croak("callback function should return 1 value, got %d", count);
191 int decide_actual_result = POPi;
198 return decide_actual_result;
202 class perlExpandDecider : public Xapian::ExpandDecider {
206 perlExpandDecider(SV *func) {
207 callback = newSVsv(func);
210 ~perlExpandDecider() {
211 SvREFCNT_dec(callback);
214 bool operator()(const string &term) const {
222 XPUSHs(sv_2mortal(newSVpv(term.data(), term.size())));
226 int count = call_sv(callback, G_SCALAR);
230 croak("callback function should return 1 value, got %d", count);
232 int decide_actual_result = POPi;
239 return decide_actual_result;
244 MODULE = Search::Xapian PACKAGE = Search::Xapian
249 sortable_serialise(double value)
252 sortable_unserialise(string value)
266 INCLUDE: XS/BM25Weight.xs
267 INCLUDE: XS/BoolWeight.xs
268 INCLUDE: XS/Database.xs
269 INCLUDE: XS/Document.xs
270 INCLUDE: XS/Enquire.xs
272 INCLUDE: XS/MSetIterator.xs
275 INCLUDE: XS/ESetIterator.xs
277 INCLUDE: XS/MultiValueSorter.xs
279 INCLUDE: XS/QueryParser.xs
280 INCLUDE: XS/SimpleStopper.xs
282 INCLUDE: XS/Stopper.xs
283 INCLUDE: XS/TermGenerator.xs
284 INCLUDE: XS/TermIterator.xs
285 INCLUDE: XS/TradWeight.xs
286 INCLUDE: XS/PostingIterator.xs
287 INCLUDE: XS/PositionIterator.xs
288 INCLUDE: XS/ValueIterator.xs
289 INCLUDE: XS/WritableDatabase.xs
290 INCLUDE: XS/Weight.xs
292 INCLUDE: XS/DateValueRangeProcessor.xs
293 INCLUDE: XS/NumberValueRangeProcessor.xs
294 INCLUDE: XS/StringValueRangeProcessor.xs
296 INCLUDE: XS/MatchSpy.xs
297 INCLUDE: XS/ValueCountMatchSpy.xs
301 HV *mHvStash = gv_stashpv( "Search::Xapian", TRUE );
302 // Perl >= probably 5.10 doesn't need the const_cast<> here.
303 #define ENUM_CONST(P, C) newCONSTSUB( mHvStash, const_cast<char*>(#P), newSViv(C) )
305 ENUM_CONST(OP_AND, Query::OP_AND);
306 ENUM_CONST(OP_OR, Query::OP_OR);
307 ENUM_CONST(OP_AND_NOT, Query::OP_AND_NOT);
308 ENUM_CONST(OP_XOR, Query::OP_XOR);
309 ENUM_CONST(OP_AND_MAYBE, Query::OP_AND_MAYBE);
310 ENUM_CONST(OP_FILTER, Query::OP_FILTER);
311 ENUM_CONST(OP_NEAR, Query::OP_NEAR);
312 ENUM_CONST(OP_PHRASE, Query::OP_PHRASE);
313 ENUM_CONST(OP_VALUE_RANGE, Query::OP_VALUE_RANGE);
314 ENUM_CONST(OP_SCALE_WEIGHT, Query::OP_SCALE_WEIGHT);
315 ENUM_CONST(OP_ELITE_SET, Query::OP_ELITE_SET);
316 ENUM_CONST(OP_VALUE_GE, Query::OP_VALUE_GE);
317 ENUM_CONST(OP_VALUE_LE, Query::OP_VALUE_LE);
319 ENUM_CONST(DB_OPEN, DB_OPEN);
320 ENUM_CONST(DB_CREATE, DB_CREATE);
321 ENUM_CONST(DB_CREATE_OR_OPEN, DB_CREATE_OR_OPEN);
322 ENUM_CONST(DB_CREATE_OR_OVERWRITE, DB_CREATE_OR_OVERWRITE);
324 ENUM_CONST(ENQ_DESCENDING, Enquire::DESCENDING);
325 ENUM_CONST(ENQ_ASCENDING, Enquire::ASCENDING);
326 ENUM_CONST(ENQ_DONT_CARE, Enquire::DONT_CARE);
328 ENUM_CONST(FLAG_BOOLEAN, QueryParser::FLAG_BOOLEAN);
329 ENUM_CONST(FLAG_PHRASE, QueryParser::FLAG_PHRASE);
330 ENUM_CONST(FLAG_LOVEHATE, QueryParser::FLAG_LOVEHATE);
331 ENUM_CONST(FLAG_BOOLEAN_ANY_CASE, QueryParser::FLAG_BOOLEAN_ANY_CASE);
332 ENUM_CONST(FLAG_WILDCARD, QueryParser::FLAG_WILDCARD);
333 ENUM_CONST(FLAG_PURE_NOT, QueryParser::FLAG_PURE_NOT);
334 ENUM_CONST(FLAG_PARTIAL, QueryParser::FLAG_PARTIAL);
335 ENUM_CONST(FLAG_SPELLING_CORRECTION, QueryParser::FLAG_SPELLING_CORRECTION);
336 ENUM_CONST(FLAG_SYNONYM, QueryParser::FLAG_SYNONYM);
337 ENUM_CONST(FLAG_AUTO_SYNONYMS, QueryParser::FLAG_AUTO_SYNONYMS);
338 ENUM_CONST(FLAG_AUTO_MULTIWORD_SYNONYMS, QueryParser::FLAG_AUTO_SYNONYMS);
339 ENUM_CONST(FLAG_DEFAULT, QueryParser::FLAG_DEFAULT);
341 ENUM_CONST(STEM_NONE, QueryParser::STEM_NONE);
342 ENUM_CONST(STEM_SOME, QueryParser::STEM_SOME);
343 ENUM_CONST(STEM_ALL, QueryParser::STEM_ALL);
345 ENUM_CONST(FLAG_SPELLING, TermGenerator::FLAG_SPELLING);
347 ENUM_CONST(BAD_VALUENO, BAD_VALUENO);