Example usage for org.apache.solr.client.solrj.impl XMLResponseParser XMLResponseParser

List of usage examples for org.apache.solr.client.solrj.impl XMLResponseParser XMLResponseParser

Introduction

In this page you can find the example usage for org.apache.solr.client.solrj.impl XMLResponseParser XMLResponseParser.

Prototype

public XMLResponseParser() 

Source Link

Usage

From source file:com.aboutdata.schedule.BuildIndexSchedule.java

public BuildIndexSchedule() {
    if (solrServer == null) {
        try {/*from ww  w  . java2  s  . c o  m*/
            //                logger.info("configService.getSystemConfig().getSolrServer() : {}", configService.getSystemConfig().getSolrServer());
            String url = "http://localhost:9090/solr";
            // configure a server object with actual solr values.
            solrServer = new HttpSolrServer(url);
            solrServer.setParser(new XMLResponseParser());
            solrServer.setSoTimeout(5000);
            solrServer.setConnectionTimeout(5000);
            // Other commonly used properties
            solrServer.setDefaultMaxConnectionsPerHost(100);
            solrServer.setMaxTotalConnections(100);
            solrServer.setMaxRetries(1); // defaults to 0. > 1 not recommended.
        } catch (Exception exc) {
            logger.error(" Exception in getting Solr Connection: " + exc.getMessage());
            exc.printStackTrace();
        }
    }
}

From source file:com.aboutdata.service.bean.SearchServiceImpl.java

public SearchServiceImpl() {
    if (solrServer == null) {
        try {/*w ww  .j  a  va  2 s .  c  o  m*/
            // configure a server object with actual solr values.
            String url = "http://localhost:9090/solr";
            // configure a server object with actual solr values.
            solrServer = new HttpSolrServer(url);
            solrServer.setParser(new XMLResponseParser());
            solrServer.setSoTimeout(5000);
            solrServer.setConnectionTimeout(5000);
            // Other commonly used properties
            solrServer.setDefaultMaxConnectionsPerHost(100);
            solrServer.setMaxTotalConnections(100);
            solrServer.setMaxRetries(1); // defaults to 0. > 1 not recommended.
        } catch (Exception exc) {
            logger.error(" Exception in getting Solr Connection: " + exc.getMessage());
            exc.printStackTrace();
        }
    }
}

From source file:com.anhao.spring.schedule.BuildIndexSchedule.java

public BuildIndexSchedule() {
    if (solrServer == null) {
        try {/*from  ww  w.  j a v  a  2s  .  c  o  m*/
            // configure a server object with actual solr values.
            solrServer = new HttpSolrServer("http://localhost:9090/solr");
            solrServer.setParser(new XMLResponseParser());
            solrServer.setSoTimeout(5000);
            solrServer.setConnectionTimeout(5000);
            // Other commonly used properties
            solrServer.setDefaultMaxConnectionsPerHost(100);
            solrServer.setMaxTotalConnections(100);
            solrServer.setMaxRetries(1); // defaults to 0. > 1 not recommended.
        } catch (Exception exc) {
            logger.error(" Exception in getting Solr Connection: " + exc.getMessage());
            exc.printStackTrace();
        }

    }
}

From source file:com.cloudera.cdk.morphline.solr.AbstractSolrMorphlineTest.java

License:Apache License

@Before
public void setUp() throws Exception {
    super.setUp();
    collector = new Collector();

    if (EXTERNAL_SOLR_SERVER_URL != null) {
        //solrServer = new ConcurrentUpdateSolrServer(EXTERNAL_SOLR_SERVER_URL, 2, 2);
        //solrServer = new SafeConcurrentUpdateSolrServer(EXTERNAL_SOLR_SERVER_URL, 2, 2);
        solrServer = new HttpSolrServer(EXTERNAL_SOLR_SERVER_URL);
        ((HttpSolrServer) solrServer).setParser(new XMLResponseParser());
    } else {/* w  w w.ja  va 2 s .  co m*/
        if (TEST_WITH_EMBEDDED_SOLR_SERVER) {
            solrServer = new TestEmbeddedSolrServer(h.getCoreContainer(), "");
        } else {
            throw new RuntimeException("Not yet implemented");
            //solrServer = new TestSolrServer(getSolrServer());
        }
    }

    int batchSize = SEQ_NUM2.incrementAndGet() % 2 == 0 ? 100 : 1; //SolrInspector.DEFAULT_SOLR_SERVER_BATCH_SIZE : 1;
    testServer = new SolrServerDocumentLoader(solrServer, batchSize);
    deleteAllDocuments();
}

From source file:com.cmart.DB.DBQuery.java

License:Open Source License

/**
 * Opens the connection to the Solr server if Solr is enabled in GlobalVars
 *///w w  w  .  ja v a  2  s  .  co m
public void initSolr() {
    if (GlobalVars.SOLR_ENABLED)
        try {
            SOLR_SERVER = new CommonsHttpSolrServer(GlobalVars.SOLR_URL);
            SOLR_SERVER.setDefaultMaxConnectionsPerHost(GlobalVars.SOLR_MAX_CONNS_PER_HOST);

            SOLR_SERVER.setSoTimeout(10000);
            SOLR_SERVER.setConnectionTimeout(1000);
            SOLR_SERVER.setMaxTotalConnections(500);
            SOLR_SERVER.setFollowRedirects(false);
            SOLR_SERVER.setParser(new XMLResponseParser());
        } catch (MalformedURLException e) {
            e.printStackTrace();
            System.out.println("initSolr (DBQuery): Could not connect to Solr server");
        }
}

From source file:com.doculibre.constellio.servlets.SolrJExampleMain.java

License:Open Source License

public static void main(String[] args) throws MalformedURLException, SolrServerException {

    // Prepare the SolrServer. Right now, the default SolrJ's ResponseParser
    // isn't supported by Constellio.
    HttpSolrServer server = new HttpSolrServer(myServer);
    server.setParser(new XMLResponseParser());

    // Do the same query three times using three different method
    System.out.println(//from  w  w w  . jav  a  2 s .  co  m
            "= = = = = = = = = = = = = = = = = First way to execute a query = = = = = = = = = = = = = = = = =");
    print(doFirstQuery(server));
    System.out.println(
            "= = = = = = = = = = = = = = = = = Second way to execute a query = = = = = = = = = = = = = = = = =");
    print(doSecondQuery(server));
    System.out.println(
            "= = = = = = = = = = = = = = = = = Third way to execute query = = = = = = = = = = = = = = = = =");
    print(doThirdQuery(server));
    System.out
            .println("= = = = = = = = = = = = = = = = = Using SpellChecker = = = = = = = = = = = = = = = = =");
    print(spellCheck(server, "opn sorce source"));
}

From source file:com.doculibre.constellio.utils.NamedListUtils.java

License:Open Source License

public static NamedList<Object> convertXMLToNamedList(InputStream in) {
    XMLResponseParser parser = new XMLResponseParser();
    return parser.processResponse(in, "UTF-8");
}

From source file:com.mycompany.solr_web_application.Simple_Query_Solr.java

public static void main(String[] args) {
    try {/*w  w w.ja  v  a 2 s  . com*/
        String url = null;
        HttpSolrServer server = null;
        url = "http://localhost:8983/solr/wiki";
        server = new HttpSolrServer(url);
        server.setMaxRetries(1);
        server.setConnectionTimeout(20000);
        server.setParser(new XMLResponseParser());
        server.setSoTimeout(10000);
        server.setDefaultMaxConnectionsPerHost(100);
        server.setMaxTotalConnections(100);
        server.setFollowRedirects(false);
        server.setAllowCompression(true);

        SolrQuery query = new SolrQuery();
        query.setQuery("india");
        query.setQuery("india");
        query.setFields(new String[] { "id", "name", "contents" });
        query.setHighlight(true); //set other params as needed
        query.setParam("hl.fl", "name,contents");
        query.setParam("hl.simple.pre", "<em>");
        query.setParam("hl.simple.post", "</em>");
        query.setParam("hl.fragsize", "100");

        QueryResponse queryResponse = server.query(query);
        //System.out.println(queryResponse);
        //response = server.query(solrQuery);
        Iterator<SolrDocument> iter = queryResponse.getResults().iterator();

        while (iter.hasNext()) {
            SolrDocument resultDoc = iter.next();
            String id = (String) resultDoc.getFieldValue("id");
            //System.out.println(id);
            //String id = (String) resultDoc.getFieldValue("id"); //id is the uniqueKey field

            if (queryResponse.getHighlighting().get(id) != null) {
                List<String> highlightSnippets = queryResponse.getHighlighting().get(id).get("name");
                List<String> highlightSnippets1 = queryResponse.getHighlighting().get(id).get("contents");
                // System.out.println("name "+highlightSnippets);
                //  System.out.println("content "+highlightSnippets1);
            }
        }
        //String jsonString = JSONUtil.toJSON(queryResponse);
        //ResponseWrapper data = new Gson().fromJson(jsonString, ResponseWrapper.class);
        System.out.println("Highlighting data " + queryResponse.getHighlighting());

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.mycompany.solr_web_application.Wildcard.java

public static void main(String[] args) {
    try {/* w w  w  . j  a  va  2 s . c  o m*/
        String url = null;
        HttpSolrServer server = null;
        url = "http://localhost:8983/solr/wiki";
        server = new HttpSolrServer(url);
        server.setMaxRetries(1);
        server.setConnectionTimeout(20000);
        server.setParser(new XMLResponseParser());
        server.setSoTimeout(10000);
        server.setDefaultMaxConnectionsPerHost(100);
        server.setMaxTotalConnections(100);
        server.setFollowRedirects(false);
        server.setAllowCompression(true);

        SolrQuery query = new SolrQuery();
        query.setQuery("indi*");
        query.setRequestHandler("/wildcard");
        query.setFields(new String[] { "id", "name", "contents" });
        query.setHighlight(true); //set other params as needed

        QueryResponse queryResponse = server.query(query);
        System.out.println(queryResponse);
        //response = server.query(solrQuery);

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.ngdata.hbaseindexer.indexer.FusionPipelineClient.java

License:Apache License

public QueryResponse queryFusion(SolrQuery query) throws Exception {

    int requestId = requestCounter.incrementAndGet();

    ArrayList<String> mutable = getAvailableEndpoints();
    String endpoint = mutable.get(0);

    FusionSession fusionSession = null;/*  www  .j a v a 2 s .c o m*/
    long currTime = System.nanoTime();
    synchronized (this) {
        fusionSession = sessions.get(endpoint);

        // ensure last request within the session timeout period, else reset the session
        if (fusionSession == null || (currTime - fusionSession.sessionEstablishedAt) > maxNanosOfInactivity) {
            log.info("Fusion session is likely expired (or soon will be) for endpoint " + endpoint + ", "
                    + "pre-emptively re-setting this session before processing request " + requestId);
            fusionSession = resetSession(endpoint);
            if (fusionSession == null)
                throw new IllegalStateException("Failed to re-connect to " + endpoint
                        + " after session loss when processing request " + requestId);
        }
    }

    if (fusionSession.solrClient == null) {
        fusionSession.solrClient = new HttpSolrClient(endpoint, httpClient);
    }
    QueryRequest qreq = new QueryRequest(query);
    qreq.setResponseParser(new XMLResponseParser());
    QueryResponse qr = new QueryResponse((SolrClient) fusionSession.solrClient);
    qr.setResponse(fusionSession.solrClient.request(qreq));
    return qr;
}