Software: Apache/2.2.16 (Debian). PHP/5.3.3-7+squeeze19 uname -a: Linux mail.tri-specialutilitydistrict.com 2.6.32-5-amd64 #1 SMP Tue May 13 16:34:35 UTC uid=33(www-data) gid=33(www-data) groups=33(www-data) Safe-mode: OFF (not secure) /usr/share/doc/python-xapian/ drwxr-xr-x |
Viewing file: Select action/file-type: Python bindings for Xapian
The Python bindings for Xapian are packaged in the
The
The Python bindings come with a test suite, consisting of two test files:
Exceptions
Xapian exceptions are translated into Python exceptions with the same names
and inheritance hierarchy as the C++ exception classes. The base class of
all Xapian exceptions is the
This means that programs can trap all xapian exceptions using " UnicodeThe xapian Python bindings accept unicode strings as well as simple strings (ie, "str" type strings) at all places in the API which accept string data. Any unicode strings supplied will automatically be translated into UTF-8 simple strings before being passed to the Xapian core. The Xapian core is largely agnostic about character encoding, but in those places where it does process data in a character encoding dependent way it assumes that the data is in UTF-8. The Xapian Python bindings always return string data as simple strings.
Therefore, in order to avoid issues with character encodings, you should
always pass text data to Xapian as unicode strings, or UTF-8 encoded simple
strings. There is, however, no requirement for simple strings passed into
Xapian to be valid UTF-8 encoded strings, unless they are being passed to a
text processing routine (such as the query parser, or the stemming
algorithms). For example, it is perfectly valid to pass arbitrary binary
data in a simple string to the
It is often useful to normalise unicode data before passing it to Xapian -
Xapian currently has no built-in support for normalising unicode
representations of data. The standard python module
" unicodedata.normalize('NFKC', u'foo') to normalise the string "foo" before passing it to Xapian. Iterators
The iterator classes in the Xapian C++ API are wrapped in a "Pythonic" style.
The following are supported (where marked as default iterator, it means
The pythonic iterators generally return Python objects, with properties
available as attribute values, with lazy evaluation where appropriate. An
exception is the The lazy evaluation is mainly transparent, but does become visible in one situation: if you keep an object returned by an iterator, without evaluating its properties to force the lazy evaluation to happen, and then move the iterator forward, the object may no longer be able to efficiently perform the lazy evaluation. In this situation, an exception will be raised indicating that the information requested wasn't available. This will only happen for a few of the properties - most are either not evaluated lazily (because the underlying Xapian implementation doesn't evaluate them lazily, so there's no advantage in lazy evaluation), or can be accessed even after the iterator has moved. The simplest work around is simply to evaluate any properties you wish to use which are affected by this before moving the iterator. The complete set of iterator properties affected by this is:
In older releases, the pythonic iterators returned lists representing the
appropriate item when their Non-Pythonic IteratorsBefore the pythonic iterator wrappers were added, the python bindings provided thin wrappers around the C++ iterators. However, these iterators don't behave like most iterators do in Python, so the pythonic iterators were implemented to replace them. The non-pythonic iterators are still available to allow existing code to continue to work, but they're now deprecated and we plan to remove them in Xapian 1.3.0. The documentation below is provided to aid migration away from them.
All non-pythonic iterators support m=mset.begin() while m!=mset.end(): # do something m.next()
C++ iterators are often dereferenced to get information, eg
Other methods, such as MSetMSet objects have some additional methods to simplify access (these work using the C++ array dereferencing):
Additionally, the MSet has a property,
Two MSet objects are equal if they have the same number and maximum possible number of members, and if every document member of the first MSet exists at the same index in the second MSet, with the same weight. ESet
The ESet has a property,
Non-Class FunctionsThe C++ API contains a few non-class functions (the Database factory functions, and some functions reporting version information), which are wrapped like so for Python:
QueryIn 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. In Python, this is wrapped to accept any Python sequence (for example a list or tuple) to give the terms/queries, and you can specify a mixture of terms and queries if you wish. For example: subq = xapian.Query(xapian.Query.OP_AND, "hello", "world") q = xapian.Query(xapian.Query.OP_AND, [subq, "foo", xapian.Query("bar", 2)]) MatchAll and MatchNothing
As of 1.1.1, these are wrapped as Enquire
There is an additional method MatchDeciderCustom MatchDeciders can be created in Python; simply subclass xapian.MatchDecider, ensure you call the super-constructor, and define a __call__ method that will do the work. The simplest example (which does nothing useful) would be as follows: class mymatchdecider(xapian.MatchDecider): def __init__(self): xapian.MatchDecider.__init__(self) def __call__(self, doc): return 1 ValueRangeProcessorsThe ValueRangeProcessor class (and its subclasses) provide an operator() method (which is exposed in python as a __call__() method, making the class instances into callables). This method checks whether a beginning and end of a range are in a format understood by the ValueRangeProcessor, and if so, converts the beginning and end into strings which sort appropriately. ValueRangeProcessors can be defined in python (and then passed to the QueryParser), or there are several default built-in ones which can be used. Unfortunately, in C++ the operator() method takes two std::string arguments by reference, and returns values by modifying these arguments. This is not possible in Python, since strings are immutable objects. Instead, in the Python implementation, when the __call__ method is called, the resulting values of these arguments are returned as part of a tuple. The operator() method in C++ returns a value number; the return value of __call__ in python consists of a 3-tuple starting with this value number, followed by the returned "begin" value, followed by the returned "end" value. For example: vrp = xapian.NumberValueRangeProcessor(0, '$', True) a = '$10' b = '20' slot, a, b = vrp(a, b) Additionally, a ValueRangeProcessor may be implemented in Python. The Python implementation should override the __call__() method with its own implementation, and, again, since it cannot return values by reference, it should return a tuple of (value number, begin, end). For example: class MyVRP(xapian.ValueRangeProcessor): def __init__(self): xapian.ValueRangeProcessor.__init__(self) def __call__(self, begin, end): return (7, "A"+begin, "B"+end) Apache and mod_python/mod_wsgiBy default, both mod_python and mod_wsgi use a separate sub-interpreter for each application. However, Python's sub-interpreter support is incompatible with the simplified GIL state API which SWIG-generated Python bindings use by default. So to avoid deadlocks, you need to tell mod_python and mod_wsgi to run applications which use Xapian in the main interpreter as detailed below. This restriction could be removed - the details are in Xapian's bugtracker - see ticket #364 for details of what needs doing. mod_pythonYou need to set this option in the Apache configuration section for all mod_python scripts which use Xapian: PythonInterpreter main_interpreter You may also need to use Python >= 2.4 (due to problems in Python 2.3 with the APIs the code uses). mod_wsgiYou need to set the WSGIApplicationGroup option like so: WSGIApplicationGroup %{GLOBAL} The mod_wsgi documentation also discusses this issue. Last updated $Date: 2010-02-03 15:12:00 +0000 (Wed, 03 Feb 2010) $ |
:: Command execute :: | |
--[ c99shell v. 2.0 [PHP 7 Update] [25.02.2019] maintained by KaizenLouie | C99Shell Github | Generation time: 0.0167 ]-- |