[Xapian-discuss] Writing a MatchDecider and exposing it to PHP

Paul Dixon pdixon at astreetpress.com
Tue Mar 20 11:16:42 GMT 2012


I would like to write a MatchDecider in C++ and expose it to PHP.

I'm able to compile a simple extension and use SWIG to expose a simple
function to PHP, but I can't seem to hit upon the right incantation to
expose my MatchDecider class.


I have a header file declaring my decider, MyDecider.h

	#ifndef _INC_MYDECIDER_H
	#define _INC_MYDECIDER_H

	#include <xapian/enquire.h>
	#include <xapian/types.h>

	class MyDecider : public Xapian::MatchDecider {

	    Xapian::valueno valuenum;
	    bool inclusive;

	  public:
	     MyDecider  (Xapian::valueno slot, bool inclusive_)
		: valuenum(slot), inclusive(inclusive_) { }

	    bool operator()(const Xapian::Document& doc) const;
	};


	#endif



I have a very simple SWIG interface file, MyDecider.i


	%module mydecider


	%{
	extern int demo_function(int x);
	#include <xapian.h>
	#include "mydecider.h"
	%}


	extern int demo_function(int x);
	#include <xapian.h>
	#include "mydecider.h"


This successfully exports my 'demo_function' to PHP, but not the
MyDecider class ($d=new MyDecider fails with a class not found error)

I'm sure I'm doing something wrong in my SWIG interface file, but I'm
very new to it...clues welcomed!



More information about the Xapian-discuss mailing list