org.modeshape.graph.search
Class SearchEngineIndexer

java.lang.Object
  extended by org.modeshape.graph.search.SearchEngineIndexer

@NotThreadSafe
public class SearchEngineIndexer
extends Object

A utility class that can be used to update the indexes of a search engine by crawling parts of the source. Each instance is created to make a series of atomic updates to the search engine using a single connection to the source.


Field Summary
protected static int DEFAULT_MAX_DEPTH_PER_READ
          The default maximum depth of each subgraph read operation is 100 .
 
Constructor Summary
SearchEngineIndexer(ExecutionContext context, SearchEngine searchEngine, RepositoryConnectionFactory connectionFactory)
          Create an indexer that will update the indexes in the supplied search engine by crawling content, using the supplied connection factory to obtain connections.
 
Method Summary
protected  void checkNotClosed()
           
protected  void checkRequestForErrors(Request request)
           
 void close()
          Close this indexer and release all resources.
 String getSourceName()
          Get the name of the source containing the content.
 SearchEngineIndexer index(String workspaceName)
          Index all of the content in the named workspace within the source.
 SearchEngineIndexer index(String workspaceName, Location location)
          Crawl and index the full subgraph content starting at the supplied location in the named workspace.
 SearchEngineIndexer index(String workspaceName, Location location, int depth)
          Crawl and index the content starting at the supplied location in the named workspace, to the designated depth.
 SearchEngineIndexer index(String workspaceName, Path path)
          Crawl and index the full subgraph content starting at the supplied path in the named workspace.
 SearchEngineIndexer index(String workspaceName, Path path, int depth)
          Crawl and index the content starting at the supplied path in the named workspace, to the designated depth.
 SearchEngineIndexer indexAllWorkspaces()
          Index (or re-index) all of the content in all of the workspaces within the source.
protected  void indexProperties(String workspaceName, Location location)
           
protected  void indexSubgraph(String workspaceName, Location startingLocation, int depth)
           
 boolean isClosed()
          Return whether this indexer has already been closed.
 void process(ChangeRequest searchEngineRequest)
          Send the supplied change request directly to the search engine's processor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_MAX_DEPTH_PER_READ

protected static final int DEFAULT_MAX_DEPTH_PER_READ
The default maximum depth of each subgraph read operation is 100 .

See Also:
Constant Field Values
Constructor Detail

SearchEngineIndexer

public SearchEngineIndexer(ExecutionContext context,
                           SearchEngine searchEngine,
                           RepositoryConnectionFactory connectionFactory)
Create an indexer that will update the indexes in the supplied search engine by crawling content, using the supplied connection factory to obtain connections.

As soon as this indexer is created, it establishes a connection to the underlying source and is ready to being retrieving content from the source and using it to update the indexes. Therefore, the instance must be closed when completed.

Parameters:
context - the context in which the indexing operations are to be performed
searchEngine - the search engine that is to be updated
connectionFactory - the factory for creating connections to the repository containing the content
Throws:
IllegalArgumentException - if the search engine or connection factory references are null
Method Detail

getSourceName

public String getSourceName()
Get the name of the source containing the content.

Returns:
the source name; never null

index

public SearchEngineIndexer index(String workspaceName)
                          throws RepositorySourceException,
                                 SearchEngineException
Index all of the content in the named workspace within the source. This method operates synchronously and returns when the requested indexing is completed.

Parameters:
workspaceName - the name of the workspace
Returns:
this object for convenience in method chaining; never null
Throws:
IllegalArgumentException - if the context or workspace name is null, or if the depth per read is not positive
RepositorySourceException - if there is a problem accessing the content
SearchEngineException - if there is a problem updating the indexes
InvalidWorkspaceException - if the workspace does not exist

indexAllWorkspaces

public SearchEngineIndexer indexAllWorkspaces()
                                       throws RepositorySourceException,
                                              SearchEngineException
Index (or re-index) all of the content in all of the workspaces within the source. This method operates synchronously and returns when the requested indexing is completed.

Returns:
this object for convenience in method chaining; never null
Throws:
RepositorySourceException - if there is a problem accessing the content
SearchEngineException - if there is a problem updating the indexes
IllegalArgumentException - if the context is null, or if depth per read is not positive

index

public SearchEngineIndexer index(String workspaceName,
                                 Path path)
Crawl and index the full subgraph content starting at the supplied path in the named workspace.

Parameters:
workspaceName - the name of the workspace
path - the path of the content to be indexed
Returns:
this object for convenience in method chaining; never null
Throws:
IllegalArgumentException - if the workspace name or location are null, or if the depth is less than 1
IllegalStateException - if this object has already been closed
InvalidWorkspaceException - if there is no workspace with the supplied name

index

public SearchEngineIndexer index(String workspaceName,
                                 Path path,
                                 int depth)
Crawl and index the content starting at the supplied path in the named workspace, to the designated depth.

Parameters:
workspaceName - the name of the workspace
path - the path of the content to be indexed
depth - the depth of the content to be indexed
Returns:
this object for convenience in method chaining; never null
Throws:
IllegalArgumentException - if the workspace name or location are null, or if the depth is less than 1
IllegalStateException - if this object has already been closed
InvalidWorkspaceException - if there is no workspace with the supplied name

index

public SearchEngineIndexer index(String workspaceName,
                                 Location location)
Crawl and index the full subgraph content starting at the supplied location in the named workspace.

Parameters:
workspaceName - the name of the workspace
location - the location of the content to be indexed
Returns:
this object for convenience in method chaining; never null
Throws:
IllegalArgumentException - if the workspace name or location are null, or if the depth is less than 1
InvalidWorkspaceException - if there is no workspace with the supplied name

index

public SearchEngineIndexer index(String workspaceName,
                                 Location location,
                                 int depth)
Crawl and index the content starting at the supplied location in the named workspace, to the designated depth.

Parameters:
workspaceName - the name of the workspace
location - the location of the content to be indexed
depth - the depth of the content to be indexed
Returns:
this object for convenience in method chaining; never null
Throws:
IllegalArgumentException - if the workspace name or location are null, or if the depth is less than 1
IllegalStateException - if this object has already been closed
InvalidWorkspaceException - if there is no workspace with the supplied name

indexSubgraph

protected void indexSubgraph(String workspaceName,
                             Location startingLocation,
                             int depth)

indexProperties

protected void indexProperties(String workspaceName,
                               Location location)

process

public final void process(ChangeRequest searchEngineRequest)
Send the supplied change request directly to the search engine's processor.

Parameters:
searchEngineRequest -

checkRequestForErrors

protected final void checkRequestForErrors(Request request)
                                    throws RepositorySourceException,
                                           RuntimeException
Throws:
RepositorySourceException
RuntimeException

checkNotClosed

protected final void checkNotClosed()
                             throws IllegalStateException
Throws:
IllegalStateException

isClosed

public boolean isClosed()
Return whether this indexer has already been closed.

Returns:
true if this has been closed, or false if it is still usable
See Also:
close()

close

public void close()
Close this indexer and release all resources. This method has no effect if it is called when this indexer is alread closed.

See Also:
isClosed()


Copyright © 2008-2010 JBoss, a division of Red Hat. All Rights Reserved.