The C# bindings for Xapian are packaged in the Xapian
namespace
and largely follow the C++ API, with the following differences and
additions. C# strings and other types, etc., are converted automatically
in the bindings, so generally it should just work as expected.
The examples
subdirectory contains examples showing how to use the
C# bindings based on the simple examples from xapian-examples
:
SimpleIndex.cs,
SimpleSearch.cs.
Methods are renamed to use the "CamelCase" capitalisation convention which C#
normally uses. So in C# you use GetDescription
instead of
get_description
.
Exceptions are thrown as SWIG exceptions instead of Xapian exceptions. This isn't done well at the moment; in future we will throw wrapped Xapian exceptions. For now, it's probably easier to catch all exceptions and try to take appropriate action based on their associated string.
The C#-wrapped iterators work much like their C++ counterparts, with operators "++", "--", "==", and "!=" overloaded. E.g.:
Xapian.MSetIterator m = mset.begin(); while (m != mset.end()) { // do something ++m; }
C++ iterators are often dereferenced to get information, eg
(*it)
. In C# these are all mapped to named methods, as
follows:
Iterator | Dereferencing method |
PositionIterator | GetTermPos() |
PostingIterator | GetDocId() |
TermIterator | GetTerm() |
ValueIterator | GetValue() |
MSetIterator | GetDocId() |
ESetIterator | GetTermName() |
Other methods, such as MSetIterator.GetDocument()
, are
available unchanged.
MSet objects have some additional methods to simplify access (these work using the C++ array dereferencing):
Method name | Explanation |
GetHit(index) | returns MSetIterator at index |
GetDocumentPercentage(index) | ConvertToPercent(GetHit(index)) |
GetDocument(index) | GetHit(index).GetDocument() |
GetDocumentId(index) | GetHit(index).GetDocId() |
Xapian::Auto::open_stub()
is wrapped as Xapian.Auto.OpenStub()
Xapian::Quartz::open()
is wrapped as Xapian.Quartz.Open()
Xapian::InMemory::open()
is wrapped as Xapian.InMemory.Open()
Xapian::Remote::open()
is wrapped as Xapian.Remote.Open()
(only
the TCP version is currently wrapped, the "program" version isn't).
The Xapian::DB_*
constants are currently wrapped in a Xapian
class within the Xapian namespace, so have a double Xapian prefix!
So Xapian::DB_CREATE_OR_OPEN
is available as
Xapian.Xapian.DB_CREATE_OR_OPEN
.
The Query::OP_*
constants are wrapped a little oddly too:
Query::OP_OR
is wrapped as Xapian.Query.op.OP_OR
.
The naming here needs sorting out...
In C++ there's a Xapian::Query constructor which takes a query operator and start/end iterators specifying a number of terms or queries, plus an optional parameter. This isn't currently wrapped in C#.
Last updated $Date: 2005-12-12T02:56:23.742308Z $