use of org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration in project jackrabbit-oak by apache.
the class FilterQueryParserTest method testMatchAllConversionWithNoConstraints.
@Test
public void testMatchAllConversionWithNoConstraints() throws Exception {
Filter filter = mock(Filter.class);
OakSolrConfiguration configuration = mock(OakSolrConfiguration.class);
QueryIndex.IndexPlan plan = mock(QueryIndex.IndexPlan.class);
SolrQuery solrQuery = FilterQueryParser.getQuery(filter, plan, configuration);
assertNotNull(solrQuery);
assertEquals("*:*", solrQuery.getQuery());
}
use of org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration in project jackrabbit-oak by apache.
the class SolrIndexEditorTest method testIndexedProperties.
@Test
public void testIndexedProperties() throws Exception {
SolrClient solrServer = TestUtils.createSolrServer();
OakSolrConfiguration configuration = TestUtils.getTestConfiguration();
IndexUpdateCallback callback = mock(IndexUpdateCallback.class);
SolrIndexEditor solrIndexEditor = new SolrIndexEditor(solrServer, configuration, callback);
NodeState before = mock(NodeState.class);
NodeState after = mock(NodeState.class);
Iterable properties = (Iterable<PropertyState>) () -> Collections.singletonList(PropertyStates.createProperty("foo1", "bar")).iterator();
when(after.getProperties()).thenReturn(properties);
solrIndexEditor.leave(before, after);
QueryResponse queryResponse = solrServer.query(new SolrQuery("foo1:*"));
assertEquals(1, queryResponse.getResults().getNumFound());
}
use of org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration in project jackrabbit-oak by apache.
the class SolrQueryIndexTest method testNoMoreThanThreeSolrRequests.
@Test
public void testNoMoreThanThreeSolrRequests() throws Exception {
NodeState root = InitialContent.INITIAL_CONTENT;
SelectorImpl selector = newSelector(root, "a");
String sqlQuery = "select [jcr:path], [jcr:score] from [nt:base] as a where" + " contains([jcr:content/*], 'founded')";
SolrClient solrServer = mock(SolrClient.class);
SolrServerProvider solrServerProvider = mock(SolrServerProvider.class);
when(solrServerProvider.getSearchingSolrServer()).thenReturn(solrServer);
OakSolrConfigurationProvider configurationProvider = mock(OakSolrConfigurationProvider.class);
OakSolrConfiguration configuration = new DefaultSolrConfiguration() {
@Override
public boolean useForPropertyRestrictions() {
return true;
}
@Override
public int getRows() {
return 10;
}
};
when(configurationProvider.getConfiguration()).thenReturn(configuration);
SolrQueryIndex solrQueryIndex = new SolrQueryIndex(null, configurationProvider, solrServerProvider);
FilterImpl filter = new FilterImpl(selector, sqlQuery, new QueryEngineSettings());
CountingResponse response = new CountingResponse(0);
when(solrServer.query(any(SolrParams.class))).thenReturn(response);
List<QueryIndex.IndexPlan> plans = solrQueryIndex.getPlans(filter, null, root);
for (QueryIndex.IndexPlan p : plans) {
Cursor cursor = solrQueryIndex.query(p, root);
assertNotNull(cursor);
while (cursor.hasNext()) {
IndexRow row = cursor.next();
assertNotNull(row);
}
assertEquals(3, response.getCounter());
}
}
use of org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration 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);
SolrClient 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.getQueryLimits(), estimator, solrServer, configuration);
} catch (Exception e) {
throw new RuntimeException(e);
}
return cursor;
}
use of org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration 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());
SolrClient 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;
}
Aggregations