use of org.apache.jackrabbit.oak.plugins.index.solr.configuration.DefaultSolrConfiguration in project jackrabbit-oak by apache.
the class SolrQueryIndexTest method testNoNegativeCost.
@Test
public void testNoNegativeCost() throws Exception {
NodeState root = InitialContent.INITIAL_CONTENT;
NodeBuilder builder = root.builder();
builder.child("oak:index").child("solr").setProperty("usedProperties", Collections.singleton("name"), Type.STRINGS).setProperty("propertyRestrictions", true).setProperty("type", "solr");
nodeState = builder.getNodeState();
SelectorImpl selector = newSelector(root, "a");
String query = "select * from [nt:base] as a where native('solr','select?q=searchKeywords:\"foo\"^20 text:\"foo\"^1 " + "description:\"foo\"^8 something:\"foo\"^3 headline:\"foo\"^5 title:\"foo\"^10 &q.op=OR'";
String sqlQuery = "select * from [nt:base] a where native('solr','" + query + "'";
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());
filter.restrictProperty("native*solr", Operator.EQUAL, PropertyValues.newString(query));
CountingResponse response = new CountingResponse(0);
when(solrServer.query(any(SolrParams.class))).thenReturn(response);
List<QueryIndex.IndexPlan> plans = solrQueryIndex.getPlans(filter, null, nodeState);
for (QueryIndex.IndexPlan p : plans) {
double costPerEntry = p.getCostPerEntry();
assertTrue(costPerEntry >= 0);
double costPerExecution = p.getCostPerExecution();
assertTrue(costPerExecution >= 0);
long estimatedEntryCount = p.getEstimatedEntryCount();
assertTrue(estimatedEntryCount >= 0);
double c = p.getCostPerExecution() + estimatedEntryCount * p.getCostPerEntry();
assertTrue(c >= 0);
}
}
use of org.apache.jackrabbit.oak.plugins.index.solr.configuration.DefaultSolrConfiguration in project jackrabbit-oak by apache.
the class SolrOakRepositoryStub method preCreateRepository.
@Override
protected void preCreateRepository(Jcr jcr) {
File f = new File("target" + File.separatorChar + "queryjcrtest-" + System.currentTimeMillis());
final SolrClient solrServer;
try {
solrServer = new EmbeddedSolrServerProvider(new EmbeddedSolrServerConfiguration(f.getPath(), "oak")).getSolrServer();
} catch (Exception e) {
throw new RuntimeException(e);
}
SolrServerProvider solrServerProvider = new SolrServerProvider() {
@Override
public void close() throws IOException {
}
@CheckForNull
@Override
public SolrClient getSolrServer() throws Exception {
return solrServer;
}
@Override
public SolrClient getIndexingSolrServer() throws Exception {
return solrServer;
}
@Override
public SolrClient getSearchingSolrServer() throws Exception {
return solrServer;
}
};
try {
assertNotNull(solrServer);
// safely remove any previous document on the index
solrServer.deleteByQuery("*:*");
solrServer.commit();
} catch (Exception e) {
throw new RuntimeException(e);
}
OakSolrConfiguration configuration = new DefaultSolrConfiguration() {
@Nonnull
@Override
public CommitPolicy getCommitPolicy() {
return CommitPolicy.HARD;
}
};
OakSolrConfigurationProvider oakSolrConfigurationProvider = new DefaultSolrConfigurationProvider(configuration);
jcr.with(new SolrIndexInitializer(false)).with(AggregateIndexProvider.wrap(new SolrQueryIndexProvider(solrServerProvider, oakSolrConfigurationProvider))).with(new NodeStateSolrServersObserver()).with(new SolrIndexEditorProvider(solrServerProvider, oakSolrConfigurationProvider));
}
Aggregations