Search in sources :

Example 31 with SolrServer

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;
}
Also used : EmbeddedSolrServerConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.EmbeddedSolrServerConfiguration) SolrServer(org.apache.solr.client.solrj.SolrServer)

Example 32 with 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;
}
Also used : EmbeddedSolrServerConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.EmbeddedSolrServerConfiguration) EmbeddedSolrServerProvider(org.apache.jackrabbit.oak.plugins.index.solr.server.EmbeddedSolrServerProvider) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) StringReader(java.io.StringReader) File(java.io.File) EmbeddedSolrServer(org.apache.solr.client.solrj.embedded.EmbeddedSolrServer) SolrServer(org.apache.solr.client.solrj.SolrServer)

Example 33 with SolrServer

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();
}
Also used : NamedList(org.apache.solr.common.util.NamedList) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrServer(org.apache.solr.client.solrj.SolrServer)

Example 34 with SolrServer

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) SolrDocument(org.apache.solr.common.SolrDocument) SolrServerException(org.apache.solr.client.solrj.SolrServerException) EmbeddedSolrServer(org.apache.solr.client.solrj.embedded.EmbeddedSolrServer) SolrServer(org.apache.solr.client.solrj.SolrServer) ManagedSolrServer(org.apache.stanbol.commons.solr.managed.ManagedSolrServer) SolrQuery(org.apache.solr.client.solrj.SolrQuery) ClassifierException(org.apache.stanbol.enhancer.topic.api.ClassifierException)

Example 35 with SolrServer

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));
    }
}
Also used : SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrDocumentList(org.apache.solr.common.SolrDocumentList) EmbeddedSolrServer(org.apache.solr.client.solrj.embedded.EmbeddedSolrServer) SolrServer(org.apache.solr.client.solrj.SolrServer) ManagedSolrServer(org.apache.stanbol.commons.solr.managed.ManagedSolrServer) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Date(java.util.Date) SolrDocument(org.apache.solr.common.SolrDocument) ClassificationReport(org.apache.stanbol.enhancer.topic.api.ClassificationReport) ClassifierException(org.apache.stanbol.enhancer.topic.api.ClassifierException)

Aggregations

SolrServer (org.apache.solr.client.solrj.SolrServer)42 ManagedSolrServer (org.apache.stanbol.commons.solr.managed.ManagedSolrServer)21 SolrServerException (org.apache.solr.client.solrj.SolrServerException)20 EmbeddedSolrServer (org.apache.solr.client.solrj.embedded.EmbeddedSolrServer)17 IOException (java.io.IOException)13 ClassifierException (org.apache.stanbol.enhancer.topic.api.ClassifierException)13 SolrQuery (org.apache.solr.client.solrj.SolrQuery)12 SolrDocument (org.apache.solr.common.SolrDocument)11 ConfigurationException (org.osgi.service.cm.ConfigurationException)11 TrainingSetException (org.apache.stanbol.enhancer.topic.api.training.TrainingSetException)10 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)10 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)9 OakSolrConfiguration (org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration)8 ArrayList (java.util.ArrayList)7 ChainException (org.apache.stanbol.enhancer.servicesapi.ChainException)7 EngineException (org.apache.stanbol.enhancer.servicesapi.EngineException)7 InvalidContentException (org.apache.stanbol.enhancer.servicesapi.InvalidContentException)7 EntityhubException (org.apache.stanbol.entityhub.servicesapi.EntityhubException)7 SolrInputDocument (org.apache.solr.common.SolrInputDocument)6 Test (org.junit.Test)6