List of usage examples for org.apache.solr.client.solrj.util ClientUtils escapeQueryChars
public static String escapeQueryChars(String s)
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(); }