Class: IndexManager

jala.IndexManager(name, dir, lang)

This class basically sits on top of a helma.Search.Index instance and provides methods for adding, removing and optimizing the underlying index. All methods generate jobs that are put into an internal queue which is processed asynchronously by a separate worker thread. This means all calls to add(), remove() and optimize() will return immediately, but the changes to the index will be done within a short delay. Please keep in mind to change the status of this IndexManager instance to REBUILDING before starting to rebuild the index, as this ensures that all add/remove/optimize jobs will stay in the queue and will only be processed after switching the status back to NORMAL. This ensures that objects that have been modified during a rebuilding process are re-indexed properly afterwards.

Constructor

new IndexManager(name, dir, lang)

Constructs a new IndexManager object.
Parameters:
Name Type Description
name String The name of the index, which is the name of the directory the index already resides or will be created in.
dir helma.File The base directory where this index's directory is already existing or will be created in. If not specified a RAM directory is used.
lang String The language of the documents in this index. This leads to the proper Lucene analyzer being used for indexing documents.
Source:
See:
  • helma.Search.createIndex

Classes

Job

Members

pending :Number

Read only reference containing the number of pending jobs
Type:
  • Number
Source:

running :Boolean

Read only reference containing the running status of this IndexManager
Type:
  • Boolean
Source:

(static, readonly) MAXTRIES :Number

Constant defining the maximum number of tries to add/remove an object to/from the underlying index.
Type:
  • Number
Source:

(static, readonly) NORMAL :Number

Constant defining normal mode of this index manager.
Type:
  • Number
Source:

(static, readonly) REBUILDING :Number

Constant defining rebuilding mode of this index manager.
Type:
  • Number
Source:

(inner) search

Main constructor body. Initializes the underlying index.
Source:

Methods

add(doc)

Queues the document object passed as argument for addition to the underlying index. This includes that all existing documents with the same identifier will be removed before the object passed as argument is added.
Parameters:
Name Type Description
doc helma.Search.Document The document object that should be added to the underlying index.
Source:
See:
Returns:
True if the job was added successfully to the internal queue, false otherwise.

getDirectory()

Returns the directory of the underlying index
Source:
Returns:
The directory of the underlying index

getIdFieldname()

Returns the name of the field containing the unique identifier of document objects in the index wrapped by this IndexManager. Defaults to "id".
Source:
See:
Returns:
The name of the id field in the index

getIndex()

Returns the underlying index.
Source:
Returns:
The index this queue is working on.

getName()

Returns the name of the index manger, which is equal to the name of the underlying index
Source:
Returns:
The name of the index manager

getQueue()

Returns the queue this index manager is using.
Source:
Returns:
The queue.

getStatus()

Returns the status of this manager.
Source:
See:
Returns:
The status of this index manager.

hasOptimizingJob()

Returns true if the underlying index is currently optimized.
Source:
Returns:
True in case the index is optimized, false otherwise.

isRebuilding()

Returns true if the underlying index is currently rebuilding.
Source:
Returns:
True in case the index is rebuilding, false otherwise.

isRunning()

Returns true if this IndexManager instance is running
Source:
Returns:
True if this IndexManager instance is running, false otherwise.

log(level, msg)

Helper function that prefixes every log message with the name of the IndexManager.
Parameters:
Name Type Description
level String An optional logging level. Accepted values
msg String The log message are "debug", "info", "warn" and "error".
Source:

optimize()

Queues the optimization of the underlying index. Normally there is no need to call this method explicitly, as the index will be optimized after all queued jobs have been processed.
Source:
Returns:
True if the optimizing job was added, false otherwise, which means that there is already an optimizing job waiting in the queue.

parseQuery(queryStr, fields, boostMap)

Parses the query string passed as argument into a lucene Query instance
Parameters:
Name Type Description
queryStr String The query string to parse
fields Array An array containing the names of the files to search in
boostMap Object An optional object containing properties whose name denotes the name of the field to boost in the query, and the value the boost value.
Source:
Returns:
The query

parseQueryFilter(query, analyzer)

Parses the query passed as argument and returns a caching filter. If an array with more than one query strings is passed as argument, this method constructs a boolean query filter where all queries in the array must match.
Parameters:
Name Type Description
query String | Array Either a query string, or an array containing one or more query strings
analyzer org.apache.lucene.analysis.Analyzer Optional analyzer to use when parsing the filter query
Source:
Returns:
A caching query filter

remove(id)

Queues the removal of all index documents whose identifier value ("id" by default) matches the number passed as argument.
Parameters:
Name Type Description
id Number The identifier value
Source:
Returns:
True if the removal job was added successfully to the queue, false otherwise.
Searches the underlying index using the searcher of this index manager
Parameters:
Name Type Description
query helma.Search.Query | org.apache.lucene.search.Query The query to execute. Can be either an instance of helma.Search.Query, or an instance of org.apache.lucene.search.Query
filter helma.Search.QueryFilter | org.apache.lucene.search.Filter An optional query filter
sortFields Array An optional array containing org.apache.lucene.search.SortField instances to use for sorting the result
Source:
Returns:
A HitCollection containing the search results

setIdFieldname()

Sets the name of the field containing the unique identifier of document objects in the index wrapped by this IndexManager.
Source:
See:

setStatus(s)

Modifies the status of this manager, which has implications on how index modifying jobs are handled. If the status is #REBUILDING, all jobs are queued until the status is set back to #NORMAL.
Parameters:
Name Type Description
s Number The new status of this manager.
Source:
See:

start()

Starts the IndexManager worker thread that processes the job queue
Source:

stop()

Stops this IndexManager instance. This function waits for 10 seconds maximum for the worker thread to stop.
Source:
Returns:
True if the worker thread stopped successfully, false otherwise