use of org.apache.solr.client.solrj.SolrServer in project jackrabbit-oak by apache.
the class FullTextSolrSearchTest method createEmbeddedSolrServerProvider.
private EmbeddedSolrServerProvider createEmbeddedSolrServerProvider(boolean http) throws Exception {
String tempDirectoryPath = FileUtils.getTempDirectoryPath();
File solrHome = new File(tempDirectoryPath, "solr" + System.nanoTime());
EmbeddedSolrServerConfiguration embeddedSolrServerConfiguration = new EmbeddedSolrServerConfiguration(solrHome.getAbsolutePath(), "oak");
if (http) {
embeddedSolrServerConfiguration = embeddedSolrServerConfiguration.withHttpConfiguration("/solr", 8983);
}
EmbeddedSolrServerProvider embeddedSolrServerProvider = embeddedSolrServerConfiguration.getProvider();
SolrServer solrServer = embeddedSolrServerProvider.getSolrServer();
if (storageEnabled != null && !storageEnabled) {
// change schema.xml and reload the core
File schemaXML = new File(solrHome.getAbsolutePath() + "/oak/conf", "schema.xml");
InputStream inputStream = getClass().getResourceAsStream("/solr/oak/conf/schema.xml");
String schemaString = IOUtils.toString(inputStream).replace("<dynamicField name=\"*\" type=\"text_general\" indexed=\"true\" stored=\"true\" multiValued=\"true\"/>", "<dynamicField name=\"*\" type=\"text_general\" indexed=\"true\" stored=\"false\" multiValued=\"true\"/>");
FileOutputStream fileOutputStream = new FileOutputStream(schemaXML);
IOUtils.copy(new StringReader(schemaString), fileOutputStream);
fileOutputStream.flush();
((EmbeddedSolrServer) solrServer).getCoreContainer().reload("oak");
}
return embeddedSolrServerProvider;
}
use of org.apache.solr.client.solrj.SolrServer in project jackrabbit-oak by apache.
the class SolrIndexEditorTest method testIgnoredPropertiesNotIndexed.
@Test
public void testIgnoredPropertiesNotIndexed() throws Exception {
NodeBuilder builder = mock(NodeBuilder.class);
SolrServer solrServer = TestUtils.createSolrServer();
OakSolrConfiguration configuration = new DefaultSolrConfiguration() {
@Nonnull
@Override
public Collection<String> getIgnoredProperties() {
return Arrays.asList("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 Arrays.asList(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.solr.client.solrj.SolrServer 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 + "'";
SolrServer solrServer = mock(SolrServer.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.solr.client.solrj.SolrServer in project jackrabbit-oak by apache.
the class RemoteSolrServerProviderIT method testCloudRemoteServerCreation.
@Test
public void testCloudRemoteServerCreation() throws Exception {
// do this test only if a Solr Cloud server is available
for (String host : zkHosts) {
boolean cloudServerAvailable = false;
try {
cloudServerAvailable = canCreateCollections(host);
} catch (Exception e) {
// do nothing
}
if (cloudServerAvailable) {
String collection = "sample_" + System.nanoTime();
RemoteSolrServerProvider remoteSolrServerProvider = new RemoteSolrServerProvider(new RemoteSolrServerConfiguration(host, collection, 2, 2, null));
SolrServer solrServer = remoteSolrServerProvider.getSolrServer();
assertNotNull(solrServer);
solrServer.shutdown();
break;
}
}
}
use of org.apache.solr.client.solrj.SolrServer 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);
SolrServer 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