Example usage for org.apache.solr.client.solrj.util ClientUtils escapeQueryChars

List of usage examples for org.apache.solr.client.solrj.util ClientUtils escapeQueryChars

Introduction

In this page you can find the example usage for org.apache.solr.client.solrj.util ClientUtils escapeQueryChars.

Prototype


public static String escapeQueryChars(String s) 

Source Link

Document

See: <a href="https://www.google.com/?gws_rd=ssl#q=lucene+query+parser+syntax">Lucene query parser syntax</a> for more information on Escaping Special Characters

Usage

From source file:uk.bl.wa.annotation.Annotator.java

License:Open Source License

private static void searchAndApplyAnnotations(Annotations ann, SurtPrefixSet oaSurts, String solrServer)
        throws SolrServerException, URISyntaxException, IOException {
    // Connect to solr:
    SolrClient solr = new HttpSolrClient(solrServer);

    // Set up annotator:
    Annotator anr = new Annotator(ann, oaSurts);

    // Loop over URL known to ACT:
    for (String scope : ann.getCollections().keySet()) {
        if ("resource".equals(scope)) {

            // Search for all matching URLs in SOLR:
            for (String uriKey : ann.getCollections().get(scope).keySet()) {
                LOG.info("Looking for URL: " + uriKey);
                SolrQuery parameters = new SolrQuery();
                parameters.set("q", "url:" + ClientUtils.escapeQueryChars(uriKey));
                searchAndApplyAnnotations(anr, solr, parameters);
            }/*from w  w  w .ja v  a2  s .co  m*/

        } else if ("root".equals(scope)) {

            // Search for all matching URLs in SOLR:
            for (String uriKey : ann.getCollections().get(scope).keySet()) {
                LOG.info("Looking for URLs starting with: " + uriKey);
                SolrQuery parameters = new SolrQuery();
                parameters.set("q", "url:" + ClientUtils.escapeQueryChars(uriKey) + "*");
                searchAndApplyAnnotations(anr, solr, parameters);
            }

        } else {
            LOG.warn("Ignoring annotations scoped as: " + scope);
        }
    }

    // And commit:
    solr.commit();

}