Package amplee.indexer
Really simple indexing implementation for amplee
I assume something bigger such as Lucene would be much more
efficient.
For example:
>>> import time
>>> from amplee.indexer import *
>>> ind = Indexer()
>>> container = ShelveContainer('/tmp/cache.p')
>>> pi = PublishedIndex('pi', container=container, granularity=DateIndex.month)
>>> container2 = ShelveContainer('/tmp/cache2.p')
>>> ai = AuthorIndex('ai', container=container2)
>>> ind.register(pi)
>>> ind.register(ai)
# With the indexer daemon >>> ind.start_daemon(interval=1.0)
>>> try: >>> index(member) >>> time.sleep(3)
>>> finally: >>> ind.stop_daemon()
# Or without >>> ind.process(member)
>>> from datetime import datetime
>>> start = datetime(2006, 10, 8, 14, 00, 12)
>>> end = datetime(2008, 10, 8, 16, 00, 12)
>>> r0 = pi.between(start, end)
>>> print r0
>>> r1 = ai.lookup('Jon Doe')
>>> print r1
# You can even concatenate both set of results into one >>>
print r0 & r1
# Or substract (assuming r2) >>> print r0 & r2 - r1
Once you get a result dictionnary you can do something like this:
>>> collection_name, member_id = r.pop()
>>> c0 = service.get_collection(collection_name)
>>> member = c0.get_member(member_id)
Or to get a list of member instances.
>>> items = ind.to_dict(r)
>>> for collection_name in items:
c = service.get_collection(collection_name)
members = c.reload_members_from_list(items[collection_name])
| Function Summary |
| |
index(member)
Add the member to queue of elements to be indexed. |
index(member)
Add the member to queue of elements to be indexed.
The ``member`` is an instance of any of the member classes provided
by amplee.
Note that qe-queuing will be asynchronized and thus this function
will return before the member is actually indexed.
-
|