use of org.apache.solr.client.solrj.SolrServer in project jackrabbit-oak by apache.
the class OakSolrServer method getServer.
private synchronized SolrServer getServer(SolrRequest request) throws Exception {
boolean isIndex = request.getPath().contains("/update");
SolrServerRegistry.Strategy strategy = isIndex ? SolrServerRegistry.Strategy.INDEXING : SolrServerRegistry.Strategy.SEARCHING;
SolrServer solrServer = SolrServerRegistry.get(solrServerConfiguration, strategy);
if (solrServer == null) {
if (solrServerConfiguration instanceof EmbeddedSolrServerConfiguration) {
solrServer = solrServerProvider.getSolrServer();
// the same Solr server has to be used for both
SolrServerRegistry.register(solrServerConfiguration, solrServer, SolrServerRegistry.Strategy.INDEXING);
SolrServerRegistry.register(solrServerConfiguration, solrServer, SolrServerRegistry.Strategy.SEARCHING);
} else {
solrServer = isIndex ? solrServerProvider.getIndexingSolrServer() : solrServerProvider.getSearchingSolrServer();
SolrServerRegistry.register(solrServerConfiguration, solrServer, strategy);
}
}
return solrServer;
}
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 qi4j-sdk by Qi4j.
the class SolrEntityQueryMixin method search.
@Override
public SolrDocumentList search(String queryString) throws SolrServerException {
SolrServer server = solr.solrServer();
NamedList<Object> list = new NamedList<Object>();
list.add("q", queryString);
QueryResponse query = server.query(SolrParams.toSolrParams(list));
return query.getResults();
}
use of org.apache.solr.client.solrj.SolrServer in project stanbol by apache.
the class TopicClassificationEngine method getBroaderConcepts.
@Override
public Set<String> getBroaderConcepts(String id) throws ClassifierException {
LinkedHashSet<String> broaderConcepts = new LinkedHashSet<String>();
if (broaderField == null) {
return broaderConcepts;
}
SolrServer solrServer = getActiveSolrServer();
SolrQuery query = new SolrQuery("*:*");
query.addFilterQuery(conceptUriField + ":" + ClientUtils.escapeQueryChars(id));
query.addField(broaderField);
try {
for (SolrDocument result : solrServer.query(query).getResults()) {
// there should be only one results
Collection<Object> broaderFieldValues = result.getFieldValues(broaderField);
if (broaderFieldValues == null) {
continue;
}
for (Object value : broaderFieldValues) {
broaderConcepts.add(value.toString());
}
}
} catch (SolrServerException e) {
String msg = String.format("Error while fetching broader topics of '%s' on Solr Core '%s'.", id, solrCoreId);
throw new ClassifierException(msg, e);
}
return broaderConcepts;
}
use of org.apache.solr.client.solrj.SolrServer in project stanbol by apache.
the class TopicClassificationEngine method getPerformanceEstimates.
@Override
public ClassificationReport getPerformanceEstimates(String conceptId) throws ClassifierException {
SolrServer solrServer = getActiveSolrServer();
SolrQuery query = new SolrQuery("*:*");
query.addFilterQuery(entryTypeField + ":" + METADATA_ENTRY);
query.addFilterQuery(conceptUriField + ":" + ClientUtils.escapeQueryChars(conceptId));
try {
SolrDocumentList results = solrServer.query(query).getResults();
if (results.isEmpty()) {
throw new ClassifierException(String.format("'%s' is not a registered topic", conceptId));
}
SolrDocument metadata = results.get(0);
Float precision = computeMeanValue(metadata, precisionField);
Float recall = computeMeanValue(metadata, recallField);
int positiveSupport = computeSumValue(metadata, positiveSupportField);
int negativeSupport = computeSumValue(metadata, negativeSupportField);
Date evaluationDate = (Date) metadata.getFirstValue(modelEvaluationDateField);
boolean uptodate = evaluationDate != null;
ClassificationReport report = new ClassificationReport(precision, recall, positiveSupport, negativeSupport, uptodate, evaluationDate);
if (metadata.getFieldValues(falsePositivesField) == null) {
metadata.setField(falsePositivesField, new ArrayList<Object>());
}
for (Object falsePositiveId : metadata.getFieldValues(falsePositivesField)) {
report.falsePositiveExampleIds.add(falsePositiveId.toString());
}
if (metadata.getFieldValues(falseNegativesField) == null) {
metadata.setField(falseNegativesField, new ArrayList<Object>());
}
for (Object falseNegativeId : metadata.getFieldValues(falseNegativesField)) {
report.falseNegativeExampleIds.add(falseNegativeId.toString());
}
return report;
} catch (SolrServerException e) {
throw new ClassifierException(String.format("Error fetching the performance report for topic " + conceptId));
}
}
Aggregations