use of org.apache.jackrabbit.oak.plugins.index.solr.configuration.DefaultSolrConfiguration 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.DefaultSolrConfiguration 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.DefaultSolrConfiguration 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.DefaultSolrConfiguration 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.DefaultSolrConfiguration 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());
}
Aggregations