turbolucene._Indexer

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

# Class _Indexer

source code

Responsible for updating and maintaining the search engine index.

A single _Indexer thread is created to handle all index modifications.

Once the thread is started, messages are sent to it by calling the instance with a task and an object, where the task is one of the following strings:

- `add`: Adds the object to the index.
- `remove`: Removes the object from the index.
- `update`: Updates the index of an object.

and the object is any object that `make_document` knows how to handle.

To properly shutdown the thread, send the `stop` task with `None` as the object. (This is normally handled by the turbolucene._stop function.)

To optimize the index, which can take a while, pass the `optimize` task with `None` for the object. (This is normally handled by the TurboGears scheduler as set up by _schedule_optimization.)

See Also: turbolucene.start for details about `make_document`.

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, make_document) Initialize the message queue and the PyLucene indexes. | source code
__call__(self, task, object_=None, language=None) Pass `task`, `object_` and `language` to the thread for processing. | source code
Threaded methods
run(self) Main thread loop to do dispatching based on messages in the queue. | source code
_add(self, object_, language, document=None) Add a new object to the index. | source code
_remove(self, object_, language, document=None) Remove an object from the index. | source code
_update(self, object_, language) Update an object in the index by replacing it. | source code
_optimize(self) Optimize all of the indexes. | source code
_stop(self) Shutdown all of the indexes. | source code

Properties | [hide private]
Inherited from `object`: `__class__`

Method Details | [hide private]

### __init__(self, make_document) (Constructor) | source code
Initialize the message queue and the PyLucene indexes. One PyLucene index is created/opened for each of the configured supported languages. This method uses the `turbolucene.default_language`, `turbolucene.languages` and `turbolucene.force_lock_release` configuration settings. Parameters: `make_document` (callable) - A callable that takes the object to index as a parameter and returns an appropriate Document object. Overrides: PyLucene.PythonThread.__init__ Note: Instantiating this class starts the thread automatically. See Also: turbolucene (module docstring) for details about configuration settings. turbolucene.start for details about `make_document`. _get_index_path for details about the directory location of each index. _analyzer_factory for details about the analyzer used for each index.

### __call__(self, task, object_=None, language=None) (Call operator) | source code
Pass `task`, `object_` and `language` to the thread for processing. If `language` is `None`, then the default language configured in `turbolucene.default_language` is used. If `task` is `stop`, then the _Indexer thread is shutdown and this method will wait until the shutdown is complete. Parameters: `task` (`str`) - The task to perform. `object_` - Any object that `make_document` knows how to handle. (Default: `None`) `language` (`str`) - The ISO language code of the language of the object. This specifies which PyLucene index to use. See Also: turbolucene (module docstring) for details about configuration settings. turbolucene.start for details about `make_document`.

### run(self) | source code
Main thread loop to do dispatching based on messages in the queue. This method expects that the queue will contain 3-tuples in the form of (task, object, language), where task is one of `add`, `update`, `remove`, `optimize` or `stop`, entry is any object that `make_document` can handle or `None` in the case of `optimize` and `stop`, and language is the ISO language code of the indexer. If the task is `stop`, then the thread shuts down. Overrides: threading.Thread.run Note: This method is run in the thread. See Also: _add, _update, _remove, _optimize and _stop for details about each respective task. turbolucene.start for details about `make_document`.

### _add(self, object_, language, document=None) | source code
Add a new object to the index. If `document` is not provided, then this method passes the object off to `make_document` and then indexes the resulting Document object. Otherwise it just indexes the `document` object. Parameters: `object_` - The object to be indexed. It will be passed to `make_document` (unless `document` is provided). `language` (`str`) - The ISO language code of the indexer to use. `document` (Document) - A pre-built Document object for the given object, if it exists. This is used internally by _update. (Default: `None`) Note: This method is run in the thread. See Also: turbolucene.start for details about `make_document`.

### _remove(self, object_, language, document=None) | source code
Remove an object from the index. If `document` is not provided, then this method passes the object off to `make_document` and then removes the resulting Document object from the index. Otherwise it just removes the `document` object. Parameters: `object_` - The object to be removed from the index. It will be passed to `make_document` (unless `document` is provided). `language` (`str`) - The ISO language code of the indexer to use. `document` (Document) - A pre-built Document object for the given object, if it exists. This is used internally by _update. (Default: `None`) Note: This method is run in the thread. See Also: turbolucene.start for details about `make_document`.

### _update(self, object_, language) | source code
Update an object in the index by replacing it. This method updates the index by removing and then re-adding the object. Parameters: `object_` - The object to update in the index. It will be passed to `make_document` and the resulting Document object will be updated. `language` (`str`) - The ISO language code of the indexer to use. Note: This method is run in the thread. See Also: _remove and _add for details about the removal and re-addition. turbolucene.start for details about `make_document`.

### _optimize(self) | source code
Optimize all of the indexes. This can take a while. Note: This method is run in the thread.

### _stop(self) | source code
Shutdown all of the indexes. Note: This method is run in the thread.