Package org.apache.solr.client.solrj

Examples of org.apache.solr.client.solrj.SolrServer


    }

    @Override
    public void deleteById(String id, String ldProgramName) throws StoreException {
        if (id == null || id.isEmpty()) return;
        SolrServer solrServer = SolrCoreManager.getInstance(bundleContext, managedSolrServer).getServer(
            ldProgramName);
        removeEnhancements(id);
        try {
            solrServer.deleteById(id);
            solrServer.commit();
        } catch (SolrServerException e) {
            log.error("Solr Server Exception", e);
            throw new StoreException(e.getMessage(), e);
        } catch (IOException e) {
            log.error("IOException", e);
View Full Code Here


        deleteById(id, SolrCoreManager.CONTENTHUB_DEFAULT_INDEX_NAME);
    }

    @Override
    public void deleteById(List<String> idList, String ldProgramName) throws StoreException {
        SolrServer solrServer = SolrCoreManager.getInstance(bundleContext, managedSolrServer).getServer(
            ldProgramName);
        for (int i = 0; i < idList.size(); i++) {
            String id = idList.get(i);
            idList.remove(i);
            idList.add(i, id);
        }
        try {
            solrServer.deleteById(idList);
            solrServer.commit();
        } catch (SolrServerException e) {
            log.error("Solr Server Exception", e);
            throw new StoreException(e.getMessage(), e);
        } catch (IOException e) {
            log.error("IOException", e);
View Full Code Here

        config.setName("DBpedia.org default data");
        config.setDescription("Data used for FstLinkingEngie tests");
        // create the Yard used for the tests
        IndexReference solrIndexRef = IndexReference.parse(config.getSolrServerLocation());
       
        SolrServer server = StandaloneEmbeddedSolrServerProvider.getInstance().getSolrServer(
            solrIndexRef, config.getIndexConfigurationName());
        Assert.assertNotNull("Unable to initialise SolrServer for testing",server);
        core = ((EmbeddedSolrServer)server).getCoreContainer().getCore(
            solrIndexRef.getIndex());
        Assert.assertNotNull("Unable to get SolrCore '" + config.getIndexConfigurationName()
View Full Code Here

    protected MockEntityhub(){
        SolrYardConfig config = new SolrYardConfig("dbpedia", "dbpedia");
        config.setIndexConfigurationName(TEST_SOLR_CORE_CONFIGURATION);
        config.setAllowInitialisation(true);
        IndexReference solrIndexRef = IndexReference.parse(config.getSolrServerLocation());
        SolrServer server = StandaloneEmbeddedSolrServerProvider.getInstance().getSolrServer(
            solrIndexRef, config.getIndexConfigurationName());
        Assert.assertNotNull("Unable to initialise SolrServer for testing",server);
        try {
            yard = new SolrYard(server,config,null);
            Representation paris = yard.getRepresentation("http://dbpedia.org/resource/Paris");
View Full Code Here

        config.setName("DBpedia.org default data");
        config.setDescription("Data used for the LDPath setup");
        // create the Yard used for the tests
        IndexReference solrIndexRef = IndexReference.parse(config.getSolrServerLocation());
       
        SolrServer server = StandaloneEmbeddedSolrServerProvider.getInstance().getSolrServer(
            solrIndexRef, config.getIndexConfigurationName());
        Assert.assertNotNull("Unable to initialise SolrServer for testing",server);
        yard = new SolrYard(server,config,null);
        backend = new YardBackend(yard);
    }
View Full Code Here

    /**
     * @return the manually bound classifierSolrServer instance or the one tracked by the OSGi service
     *         tracker.
     */
    public SolrServer getActiveSolrServer() {
        SolrServer result;
        if(solrServer != null){
            result = solrServer;
        } else {
            result = indexTracker.getService();
            if(result == null){
View Full Code Here

        if (text == null) {
            // special case: example removal
            if (exampleId == null) {
                throw new IllegalArgumentException("exampleId and text should not be null simultaneously");
            }
            SolrServer solrServer = getActiveSolrServer();
            try {
                solrServer.deleteByQuery(exampleIdField + ":" + exampleId);
                solrServer.commit();
                return exampleId;
            } catch (Exception e) {
                String msg = String.format("Error deleting example with id '%s' on Solr Core '%s'",
                    exampleId, solrCoreId);
                throw new TrainingSetException(msg, e);
            }
        }

        if (exampleId == null || exampleId.isEmpty()) {
            exampleId = UUID.randomUUID().toString();
        }
        SolrInputDocument doc = new SolrInputDocument();
        doc.addField(exampleIdField, exampleId);
        doc.addField(exampleTextField, text);
        if (topics != null) {
            doc.addField(topicUrisField, topics);
        }
        doc.addField(modificationDateField, UTCTimeStamper.nowUtcDate());
        SolrServer server = getActiveSolrServer();
        try {
            server.add(doc);
            server.commit();
        } catch (Exception e) {
            String msg = String.format("Could not register example '%s' with topics: ['%s']", exampleId,
                StringUtils.join(topics, "', '"));
            throw new TrainingSetException(msg, e);
        }
View Full Code Here

        }
        SolrQuery query = new SolrQuery(sb.toString());
        query.setRows(1);
        query.setFields(exampleIdField);
        try {
            SolrServer solrServer = getActiveSolrServer();
            return solrServer.query(query).getResults().size() > 0;
        } catch (SolrServerException e) {
            String msg = String.format(
                "Error while fetching topics for examples modified after '%s' on Solr Core '%s'.",
                utcIsoDate, solrCoreId);
            throw new TrainingSetException(msg, e);
View Full Code Here

        return getExamples(topics, offset, false);
    }

    protected Batch<Example> getExamples(List<String> topics, Object offset, boolean positive) throws TrainingSetException {
        List<Example> items = new ArrayList<Example>();
        SolrServer solrServer = getActiveSolrServer();
        SolrQuery query = new SolrQuery();
        List<String> parts = new ArrayList<String>();
        String q = "";
        if (topics.isEmpty()) {
            q += "*:*";
        } else if (positive) {
            for (String topic : topics) {
                parts.add(topicUrisField + ":" + ClientUtils.escapeQueryChars(topic));
            }
            if (offset != null) {
                q += "(";
            }
            q += StringUtils.join(parts, " OR ");
            if (offset != null) {
                q += ")";
            }
        } else {
            for (String topic : topics) {
                parts.add("-" + topicUrisField + ":" + ClientUtils.escapeQueryChars(topic));
            }
            q += StringUtils.join(parts, " AND ");
        }
        if (offset != null) {
            q += " AND " + exampleIdField + ":[" + offset.toString() + " TO *]";
        }
        query.setQuery(q);
        query.addSortField(exampleIdField, SolrQuery.ORDER.asc);
        query.set("rows", batchSize + 1);
        String nextExampleId = null;
        try {
            int count = 0;
            QueryResponse response = solrServer.query(query);
            for (SolrDocument result : response.getResults()) {
                if (count == batchSize) {
                    nextExampleId = result.getFirstValue(exampleIdField).toString();
                } else {
                    count++;
View Full Code Here

        return suggestTopics(StringUtils.join(contents, "\n\n"));
    }

    public List<TopicSuggestion> suggestTopics(String text) throws ClassifierException {
        List<TopicSuggestion> suggestedTopics = new ArrayList<TopicSuggestion>(MAX_SUGGESTIONS * 3);
        SolrServer solrServer = getActiveSolrServer();
        SolrQuery query = new SolrQuery();
        query.setRequestHandler("/" + MoreLikeThisParams.MLT);
        query.setFilterQueries(entryTypeField + ":" + MODEL_ENTRY);
        query.set(MoreLikeThisParams.MATCH_INCLUDE, false);
        query.set(MoreLikeThisParams.MIN_DOC_FREQ, 1);
        query.set(MoreLikeThisParams.MIN_TERM_FREQ, 1);
        query.set(MoreLikeThisParams.MAX_QUERY_TERMS, 30);
        query.set(MoreLikeThisParams.MAX_NUM_TOKENS_PARSED, 10000);
        // TODO: find a way to parse the interesting terms and report them
        // for debugging / explanation in dedicated RDF data structure.
        // query.set(MoreLikeThisParams.INTERESTING_TERMS, "details");
        query.set(MoreLikeThisParams.SIMILARITY_FIELDS, similarityField);
        query.set(CommonParams.STREAM_BODY, text);
        // over query the number of suggestions to find a statistical cut based on the curve of the scores of
        // the top suggestion
        query.setRows(MAX_SUGGESTIONS * 3);
        query.setFields(conceptUriField);
        query.setIncludeScore(true);
        try {
            StreamQueryRequest request = new StreamQueryRequest(query);
            QueryResponse response = request.process(solrServer);
            SolrDocumentList results = response.getResults();
            for (SolrDocument result : results.toArray(new SolrDocument[0])) {
                String conceptUri = (String) result.getFirstValue(conceptUriField);
                if (conceptUri == null) {
                    throw new ClassifierException(String.format(
                        "Solr Core '%s' is missing required field '%s'.", solrCoreId, conceptUriField));
                }
                Float score = (Float) result.getFirstValue("score");

                // fetch metadata
                SolrQuery metadataQuery = new SolrQuery("*:*");
                // use filter queries to leverage the Solr cache explicitly
                metadataQuery.addFilterQuery(entryTypeField + ":" + METADATA_ENTRY);
                metadataQuery
                        .addFilterQuery(conceptUriField + ":" + ClientUtils.escapeQueryChars(conceptUri));
                metadataQuery.setFields(conceptUriField, broaderField, primaryTopicUriField);
                SolrDocument metadata = solrServer.query(metadataQuery).getResults().get(0);
                String primaryTopicUri = (String) metadata.getFirstValue(primaryTopicUriField);
                suggestedTopics.add(new TopicSuggestion(conceptUri, primaryTopicUri, metadata
                        .getFieldValues(broaderField), score));
            }
        } catch (SolrServerException e) {
View Full Code Here

TOP

Related Classes of org.apache.solr.client.solrj.SolrServer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.