use of org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration in project jackrabbit-oak by apache.
the class SolrQueryIndexTest method testSize.
@Test
public void testSize() 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')";
SolrServerProvider solrServerProvider = mock(SolrServerProvider.class);
OakSolrConfigurationProvider configurationProvider = mock(OakSolrConfigurationProvider.class);
OakSolrConfiguration configuration = new DefaultSolrConfiguration() {
@Override
public boolean useForPropertyRestrictions() {
return true;
}
};
when(configurationProvider.getConfiguration()).thenReturn(configuration);
SolrQueryIndex solrQueryIndex = new SolrQueryIndex(null, configurationProvider, solrServerProvider);
FilterImpl filter = new FilterImpl(selector, sqlQuery, new QueryEngineSettings());
List<QueryIndex.IndexPlan> plans = solrQueryIndex.getPlans(filter, null, root);
for (QueryIndex.IndexPlan p : plans) {
Cursor cursor = solrQueryIndex.query(p, root);
assertNotNull(cursor);
long sizeExact = cursor.getSize(Result.SizePrecision.EXACT, 100000);
long sizeApprox = cursor.getSize(Result.SizePrecision.APPROXIMATION, 100000);
long sizeFastApprox = cursor.getSize(Result.SizePrecision.FAST_APPROXIMATION, 100000);
assertTrue(Math.abs(sizeExact - sizeApprox) < 10);
assertTrue(Math.abs(sizeExact - sizeFastApprox) > 10000);
}
}
use of org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration in project jackrabbit-oak by apache.
the class FilterQueryParserTest method testAllChildrenQueryParsing.
@Test
public void testAllChildrenQueryParsing() throws Exception {
String query = "select [jcr:path], [jcr:score], * from [nt:hierarchy] as a where isdescendantnode(a, '/')";
Filter filter = mock(Filter.class);
OakSolrConfiguration configuration = new DefaultSolrConfiguration() {
@Override
public boolean useForPathRestrictions() {
return true;
}
};
when(filter.getQueryStatement()).thenReturn(query);
Filter.PathRestriction pathRestriction = Filter.PathRestriction.ALL_CHILDREN;
when(filter.getPathRestriction()).thenReturn(pathRestriction);
when(filter.getPath()).thenReturn("/");
QueryIndex.IndexPlan plan = mock(QueryIndex.IndexPlan.class);
SolrQuery solrQuery = FilterQueryParser.getQuery(filter, plan, configuration);
assertNotNull(solrQuery);
String[] filterQueries = solrQuery.getFilterQueries();
assertTrue(Arrays.asList(filterQueries).contains(configuration.getFieldForPathRestriction(pathRestriction) + ":\\/"));
assertEquals("*:*", solrQuery.get("q"));
}
use of org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration in project jackrabbit-oak by apache.
the class FilterQueryParserTest method testCollapseJcrContentNodes.
@Test
public void testCollapseJcrContentNodes() throws Exception {
String query = "select [jcr:path], [jcr:score], * from [nt:hierarchy] as a where isdescendantnode(a, '/')";
Filter filter = mock(Filter.class);
OakSolrConfiguration configuration = new DefaultSolrConfiguration() {
@Override
public boolean collapseJcrContentNodes() {
return true;
}
};
when(filter.getQueryStatement()).thenReturn(query);
QueryIndex.IndexPlan plan = mock(QueryIndex.IndexPlan.class);
SolrQuery solrQuery = FilterQueryParser.getQuery(filter, plan, configuration);
assertNotNull(solrQuery);
String[] filterQueries = solrQuery.getFilterQueries();
assertTrue(Arrays.asList(filterQueries).contains("{!collapse field=" + configuration.getCollapsedPathField() + " min=" + configuration.getPathDepthField() + " hint=top_fc nullPolicy=expand}"));
assertEquals("*:*", solrQuery.get("q"));
}
use of org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration in project jackrabbit-oak by apache.
the class SolrIndexEditorTest method testIgnoredPropertiesNotIndexed.
@Test
public void testIgnoredPropertiesNotIndexed() throws Exception {
NodeBuilder builder = mock(NodeBuilder.class);
SolrClient solrServer = TestUtils.createSolrServer();
OakSolrConfiguration configuration = new DefaultSolrConfiguration() {
@Nonnull
@Override
public Collection<String> getIgnoredProperties() {
return Collections.singletonList("foo2");
}
@Nonnull
@Override
public CommitPolicy getCommitPolicy() {
return CommitPolicy.HARD;
}
};
IndexUpdateCallback callback = mock(IndexUpdateCallback.class);
SolrIndexEditor solrIndexEditor = new SolrIndexEditor(solrServer, configuration, callback);
NodeState before = mock(NodeState.class);
NodeState after = mock(NodeState.class);
Iterable properties = new Iterable<PropertyState>() {
@Override
public Iterator<PropertyState> iterator() {
return Collections.singletonList(PropertyStates.createProperty("foo2", "bar")).iterator();
}
};
when(after.getProperties()).thenReturn(properties);
solrIndexEditor.leave(before, after);
QueryResponse queryResponse = solrServer.query(new SolrQuery("foo2:*"));
assertEquals(0, queryResponse.getResults().getNumFound());
}
use of org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration in project jackrabbit-oak by apache.
the class SolrQueryIndex method getPlans.
@Override
public List<IndexPlan> getPlans(Filter filter, List<OrderEntry> sortOrder, NodeState rootState) {
Collection<String> indexPaths = new SolrIndexLookup(rootState).collectIndexNodePaths(filter);
List<IndexPlan> plans = Lists.newArrayListWithCapacity(indexPaths.size());
for (String path : indexPaths) {
OakSolrConfiguration configuration = getConfiguration(path, rootState);
SolrClient solrServer = getServer(path, rootState);
// only provide the plan if both valid configuration and server exist
if (configuration != null && solrServer != null) {
LMSEstimator estimator = getEstimator(path);
IndexPlan plan = getIndexPlan(filter, configuration, estimator, sortOrder, path);
if (plan != null) {
plans.add(plan);
}
}
}
return plans;
}
Aggregations