Package turbolucene :: Class _Searcher
[hide private]
[frames] | no frames]

Class _Searcher

source code


Responsible for searching an index and returning results.

_Searcher threads are created for each search that is requested. After the search is completed, the thread dies.

To search, a _Searcher class is instantiated and then called with the query and the ISO language code for the index to search. It returns the results as a list of object id strings unless results_formatter was provided. If it was, then the list of id strings are passed to results_formatter to process and it's results are returned.

The thread is garbage collected when it goes out of scope.

The catch to all this is that a CherryPy thread cannot directly instantiate a _Searcher thread because of PyLucene restrictions. So to get around that, see the _SearcherFactory class.




See Also: turbolucene.start for details about results_formatter.

Instance Methods [hide private]

Inherited from PyLucene.PythonThread: join, start

Inherited from threading.Thread: __repr__, getName, isAlive, isDaemon, setDaemon, setName

Inherited from threading.Thread (private): _set_daemon

Inherited from threading._Verbose (private): _note

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __str__

    Public API
 
__init__(self, results_formatter)
Initialize message queues and start the thread.
source code
iterable
__call__(self, query, language=None)
Send query and language to the thread, wait and return results.
source code
    Threaded methods
 
run(self)
Search the language index for the query and send back the results.
source code
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, results_formatter)
(Constructor)

source code 
Initialize message queues and start the thread.
Overrides: PyLucene.PythonThread.__init__

Note: The thread is started as soon as the class is instantiated.

__call__(self, query, language=None)
(Call operator)

source code 

Send query and language to the thread, wait and return results.

If language is None, then the default language configured in turbolucene.default_language is used.

Parameters:
  • query (str or unicode) - The search query to give to PyLucene. All of Lucene's query syntax (field identifiers, wild cards, etc.) are available.
  • language (str) - The ISO language code of the indexer to use.
Returns: iterable
An iterable of id field strings that match the query or the results produced by results_formatter if it was provided.

See Also:

run(self)

source code 

Search the language index for the query and send back the results.

The results is an iterable of id field strings that match the query.

This method uses the turbolucene.search_fields configuration setting for the default fields to search if none are specified in the query itself, and turbolucene.default_operator for the default operator to use when joining terms.

Raises:
  • AttributeError - Raised when the configured default operator is not valid.
Overrides: threading.Thread.run
Notes:
  • This method is run in the thread.
  • The thread dies after one search.

See Also: