use of org.apache.solr.client.solrj.SolrServer in project qi4j-sdk by Qi4j.
the class SolrEntityQueryMixin method findEntities.
@Override
public Iterable<EntityReference> findEntities(Class<?> resultType, @Optional Specification<Composite> whereClause, @Optional OrderBy[] orderBySegments, @Optional Integer firstResult, @Optional Integer maxResults, Map<String, Object> variables) throws EntityFinderException {
try {
QuerySpecification expr = (QuerySpecification) whereClause;
SolrServer server = solr.solrServer();
NamedList<Object> list = new NamedList<Object>();
list.add("q", expr.query());
list.add("rows", maxResults != 0 ? maxResults : 10000);
list.add("start", firstResult);
if (orderBySegments != null && orderBySegments.length > 0) {
for (OrderBy orderBySegment : orderBySegments) {
String propName = ((Member) orderBySegment.property().accessor()).getName() + "_for_sort";
String order = orderBySegment.order() == OrderBy.Order.ASCENDING ? "asc" : "desc";
list.add("sort", propName + " " + order);
}
}
SolrParams solrParams = SolrParams.toSolrParams(list);
logger.debug("Search:" + list.toString());
QueryResponse query = server.query(solrParams);
SolrDocumentList results = query.getResults();
List<EntityReference> references = new ArrayList<EntityReference>(results.size());
for (SolrDocument result : results) {
references.add(EntityReference.parseEntityReference(result.getFirstValue("id").toString()));
}
return references;
} catch (SolrServerException e) {
throw new EntityFinderException(e);
}
}
use of org.apache.solr.client.solrj.SolrServer in project jackrabbit-oak by apache.
the class SolrIndexEditorProvider method getIndexEditor.
@Override
public Editor getIndexEditor(@Nonnull String type, @Nonnull NodeBuilder definition, @Nonnull NodeState root, @Nonnull IndexUpdateCallback callback) throws CommitFailedException {
SolrIndexEditor editor = null;
if (SolrQueryIndex.TYPE.equals(type)) {
try {
// if index definition contains a persisted configuration, use that
if (isPersistedConfiguration(definition)) {
NodeState nodeState = definition.getNodeState();
OakSolrConfiguration configuration = new OakSolrNodeStateConfiguration(nodeState);
SolrServerConfigurationProvider configurationProvider = new NodeStateSolrServerConfigurationProvider(definition.getChildNode("server").getNodeState());
SolrServer solrServer = new OakSolrServer(configurationProvider);
editor = getEditor(configuration, solrServer, callback);
} else {
// otherwise use the default configuration providers (e.g. defined via code or OSGi)
OakSolrConfiguration configuration = oakSolrConfigurationProvider.getConfiguration();
editor = getEditor(configuration, solrServerProvider.getIndexingSolrServer(), callback);
}
} catch (Exception e) {
log.warn("could not get Solr index editor from {}", definition.getNodeState(), e);
}
}
return editor;
}
use of org.apache.solr.client.solrj.SolrServer in project jackrabbit-oak by apache.
the class SolrServerProviderService method getServer.
private SolrServer getServer() {
SolrServer solrServer = null;
if (serverType != null && !"none".equals(serverType)) {
SolrServerConfigurationProvider solrServerConfigurationProvider = solrServerConfigurationProviders.get(serverType);
if (solrServerConfigurationProvider != null) {
try {
solrServer = new OakSolrServer(solrServerConfigurationProvider);
log.info("created new SolrServer {}", solrServer);
} catch (Exception e) {
log.error("could not get a SolrServerProvider of type {}", serverType, e);
}
}
}
return solrServer;
}
use of org.apache.solr.client.solrj.SolrServer in project jackrabbit-oak by apache.
the class SolrQueryIndex method query.
@Override
public Cursor query(final IndexPlan plan, final NodeState root) {
Cursor cursor;
try {
Filter filter = plan.getFilter();
final Set<String> relPaths = filter.getFullTextConstraint() != null ? getRelativePaths(filter.getFullTextConstraint()) : Collections.<String>emptySet();
final String parent = relPaths.size() == 0 ? "" : relPaths.iterator().next();
final int parentDepth = getDepth(parent);
String path = plan.getPlanName();
OakSolrConfiguration configuration = getConfiguration(path, root);
SolrServer solrServer = getServer(path, root);
LMSEstimator estimator = getEstimator(path);
AbstractIterator<SolrResultRow> iterator = getIterator(filter, plan, parent, parentDepth, configuration, solrServer, estimator);
cursor = new SolrRowCursor(iterator, plan, filter.getQueryEngineSettings(), estimator, solrServer, configuration);
} catch (Exception e) {
throw new RuntimeException(e);
}
return cursor;
}
use of org.apache.solr.client.solrj.SolrServer in project jackrabbit-oak by apache.
the class RemoteSolrServerProvider method getIndexingSolrServer.
@CheckForNull
@Override
public SolrServer getIndexingSolrServer() throws Exception {
SolrServer server = getSolrServer();
if (server instanceof HttpSolrServer) {
String url = ((HttpSolrServer) server).getBaseURL();
server = new ConcurrentUpdateSolrServer(url, 1000, Runtime.getRuntime().availableProcessors());
}
return server;
}
Aggregations