use of org.apache.jackrabbit.core.query.QueryHandler in project jackrabbit-oak by apache.
the class IndexAccessor method getReader.
public static IndexReader getReader(RepositoryContext ctx) throws RepositoryException, IOException {
RepositoryImpl repo = ctx.getRepository();
SearchManager searchMgr = repo.getSearchManager(ctx.getRepositoryConfig().getDefaultWorkspaceName());
if (searchMgr == null) {
return null;
}
QueryHandler handler = searchMgr.getQueryHandler();
SearchIndex index = (SearchIndex) handler;
return index.getIndexReader();
}
use of org.apache.jackrabbit.core.query.QueryHandler in project jackrabbit by apache.
the class RepositoryConfigurationParser method getQueryHandlerFactory.
/**
* Parses search index configuration. Search index configuration
* uses the following format:
* <pre>
* <SearchIndex class="...">
* <param name="..." value="...">
* ...
* <FileSystem ...>
* </Search>
* </pre>
* <p>
* Both the <code>SearchIndex</code> and <code>FileSystem</code>
* elements are {@link #parseBeanConfig(Element,String) bean configuration}
* elements. If the search implementation class is not given, then
* a default implementation is used.
* <p>
* The search index is an optional feature of workspace configuration.
* If the search configuration element is not found, then this method
* returns <code>null</code>.
* <p>
* The FileSystem element in a search index configuration is optional.
* However some implementations may require a FileSystem.
*
* @param parent parent of the <code>SearchIndex</code> element
* @return query handler factory
*/
protected QueryHandlerFactory getQueryHandlerFactory(final Element parent) {
NodeList children = parent.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
final Node child = children.item(i);
if (child.getNodeType() == Node.ELEMENT_NODE && SEARCH_INDEX_ELEMENT.equals(child.getNodeName())) {
return new QueryHandlerFactory() {
public QueryHandler getQueryHandler(QueryHandlerContext context) throws RepositoryException {
Element element = (Element) child;
// Optional file system implementation
FileSystem fs = null;
if (getElement(element, FILE_SYSTEM_ELEMENT, false) != null) {
fs = getFileSystemFactory(element, FILE_SYSTEM_ELEMENT).getFileSystem();
}
// Search implementation class
String className = getAttribute(element, CLASS_ATTRIBUTE, DEFAULT_QUERY_HANDLER);
BeanConfig config = new BeanConfig(className, parseParameters(element));
QueryHandler handler = config.newInstance(QueryHandler.class);
try {
handler.init(fs, context);
return handler;
} catch (IOException e) {
throw new RepositoryException("Unable to initialize query handler: " + handler, e);
}
}
};
}
}
return null;
}
use of org.apache.jackrabbit.core.query.QueryHandler in project jackrabbit by apache.
the class SearchIndex method getIndexReader.
/**
* Returns an index reader for this search index. The caller of this method
* is responsible for closing the index reader when he is finished using
* it.
*
* @param includeSystemIndex if <code>true</code> the index reader will
* cover the complete workspace. If
* <code>false</code> the returned index reader
* will not contains any nodes under /jcr:system.
* @return an index reader for this search index.
* @throws IOException the index reader cannot be obtained.
*/
protected IndexReader getIndexReader(boolean includeSystemIndex) throws IOException {
QueryHandler parentHandler = getContext().getParentHandler();
CachingMultiIndexReader parentReader = null;
if (parentHandler instanceof SearchIndex && includeSystemIndex) {
parentReader = ((SearchIndex) parentHandler).index.getIndexReader();
}
IndexReader reader;
if (parentReader != null) {
CachingMultiIndexReader[] readers = { index.getIndexReader(), parentReader };
reader = new CombinedIndexReader(readers);
} else {
reader = index.getIndexReader();
}
return new JackrabbitIndexReader(reader);
}
use of org.apache.jackrabbit.core.query.QueryHandler in project jackrabbit by apache.
the class TestHelper method checkIndexConsistency.
public static ConsistencyCheck checkIndexConsistency(Session session) throws RepositoryException, NotExecutableException, IOException {
Repository r = session.getRepository();
if (!(r instanceof RepositoryImpl)) {
throw new NotExecutableException();
}
RepositoryImpl ri = (RepositoryImpl) r;
final String workspaceName = session.getWorkspace().getName();
QueryHandler qh = ri.getSearchManager(workspaceName).getQueryHandler();
if (!(qh instanceof SearchIndex)) {
throw new NotExecutableException("No search index");
}
SearchIndex si = (SearchIndex) qh;
return si.runConsistencyCheck();
}
Aggregations