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:eu.europeana.corelib.edm.utils.construct.FullBeanHandler.java

public boolean removeRecord(SolrServer solrServer, RDF rdf) {
    try {//  w w  w . jav  a 2 s  .  c om
        solrServer.deleteByQuery(
                "europeana_id:" + ClientUtils.escapeQueryChars(rdf.getProvidedCHOList().get(0).getAbout()));

        DBCollection records = mongoServer.getDatastore().getDB().getCollection("record");
        DBCollection proxies = mongoServer.getDatastore().getDB().getCollection("Proxy");
        DBCollection providedCHOs = mongoServer.getDatastore().getDB().getCollection("ProvidedCHO");
        DBCollection aggregations = mongoServer.getDatastore().getDB().getCollection("Aggregation");
        DBCollection europeanaAggregations = mongoServer.getDatastore().getDB()
                .getCollection("EuropeanaAggregation");
        DBCollection physicalThing = mongoServer.getDatastore().getDB().getCollection("PhysicalThing");
        DBObject query = new BasicDBObject("about", rdf.getProvidedCHOList().get(0).getAbout());
        DBObject proxyQuery = new BasicDBObject("about",
                "/proxy/provider" + rdf.getProvidedCHOList().get(0).getAbout());
        DBObject europeanaProxyQuery = new BasicDBObject("about",
                "/proxy/europeana" + rdf.getProvidedCHOList().get(0).getAbout());

        DBObject providedCHOQuery = new BasicDBObject("about",
                "/item" + rdf.getProvidedCHOList().get(0).getAbout());
        DBObject aggregationQuery = new BasicDBObject("about",
                "/aggregation/provider" + rdf.getProvidedCHOList().get(0).getAbout());
        DBObject europeanaAggregationQuery = new BasicDBObject("about",
                "/aggregation/europeana" + rdf.getProvidedCHOList().get(0).getAbout());
        europeanaAggregations.remove(europeanaAggregationQuery, WriteConcern.FSYNC_SAFE);
        records.remove(query, WriteConcern.FSYNC_SAFE);
        proxies.remove(europeanaProxyQuery, WriteConcern.FSYNC_SAFE);
        proxies.remove(proxyQuery, WriteConcern.FSYNC_SAFE);
        physicalThing.remove(europeanaProxyQuery, WriteConcern.FSYNC_SAFE);
        physicalThing.remove(proxyQuery, WriteConcern.FSYNC_SAFE);
        providedCHOs.remove(providedCHOQuery, WriteConcern.FSYNC_SAFE);
        aggregations.remove(aggregationQuery, WriteConcern.FSYNC_SAFE);
        return true;
    } catch (SolrServerException e) {
        log.log(Level.SEVERE, e.getMessage());

    } catch (IOException e) {
        log.log(Level.SEVERE, e.getMessage());

    }
    return false;
}

From source file:eu.europeana.corelib.edm.utils.construct.FullBeanHandler.java

public boolean removeRecordById(SolrServer solrServer, String id) {
    try {//from w w w  .j a  v a2s . co  m
        solrServer.deleteByQuery("europeana_id:" + ClientUtils.escapeQueryChars(id));

        DBCollection records = mongoServer.getDatastore().getDB().getCollection("record");
        DBCollection proxies = mongoServer.getDatastore().getDB().getCollection("Proxy");
        DBCollection providedCHOs = mongoServer.getDatastore().getDB().getCollection("ProvidedCHO");
        DBCollection aggregations = mongoServer.getDatastore().getDB().getCollection("Aggregation");
        DBCollection europeanaAggregations = mongoServer.getDatastore().getDB()
                .getCollection("EuropeanaAggregation");
        DBCollection physicalThing = mongoServer.getDatastore().getDB().getCollection("PhysicalThing");
        DBObject query = new BasicDBObject("about", id);
        DBObject proxyQuery = new BasicDBObject("about", "/proxy/provider" + id);
        DBObject europeanaProxyQuery = new BasicDBObject("about", "/proxy/europeana" + id);

        DBObject providedCHOQuery = new BasicDBObject("about", "/item" + id);
        DBObject aggregationQuery = new BasicDBObject("about", "/aggregation/provider" + id);
        DBObject europeanaAggregationQuery = new BasicDBObject("about", "/aggregation/europeana" + id);
        europeanaAggregations.remove(europeanaAggregationQuery, WriteConcern.FSYNC_SAFE);
        records.remove(query, WriteConcern.FSYNC_SAFE);
        proxies.remove(europeanaProxyQuery, WriteConcern.FSYNC_SAFE);
        proxies.remove(proxyQuery, WriteConcern.FSYNC_SAFE);
        physicalThing.remove(europeanaProxyQuery, WriteConcern.FSYNC_SAFE);
        physicalThing.remove(proxyQuery, WriteConcern.FSYNC_SAFE);
        providedCHOs.remove(providedCHOQuery, WriteConcern.FSYNC_SAFE);
        aggregations.remove(aggregationQuery, WriteConcern.FSYNC_SAFE);
        return true;
    } catch (SolrServerException e) {
        log.log(Level.SEVERE, e.getMessage());

    } catch (IOException e) {
        log.log(Level.SEVERE, e.getMessage());

    }
    return false;
}

From source file:eu.europeana.corelib.edm.utils.construct.SolrDocumentHandler.java

private void extractCRFFields(SolrInputDocument doc, String about) throws SolrServerException {
    ModifiableSolrParams params = new ModifiableSolrParams();

    params.add("q", "europeana_id:" + ClientUtils.escapeQueryChars(about));

    SolrDocumentList resultList = solrServer.query(params).getResults();
    if (resultList != null && resultList.size() > 0) {
        SolrDocument retrievedDocument = resultList.get(0);
        for (String field : inputFields) {
            if (retrievedDocument.getFieldValue(field) != null) {
                doc.addField(field, retrievedDocument.getFieldValue(field));
            }/*from  w  w  w  .  jav a  2s.co m*/
        }
    }
}

From source file:eu.europeana.corelib.search.utils.SearchUtils.java

License:Creative Commons License

public static String escapeQuery(String query) {
    return ClientUtils.escapeQueryChars(query).replace("\\ ", " ").replace("\\-", "-");
}

From source file:fi.vm.sade.organisaatio.service.search.OrganisaatioSearchService.java

License:EUPL

private String escape(String searchStr) {
    searchStr = ClientUtils.escapeQueryChars(searchStr);
    return searchStr;
}

From source file:fr.mcc.ginco.services.IndexerServiceImpl.java

License:CeCILL license

@Override
public void removeThesaurusIndex(String thesaurusId) throws TechnicalException {
    try {// w  w  w .j ava2  s  .co m
        solrServer.deleteByQuery(SolrField.THESAURUSID + ":" + ClientUtils.escapeQueryChars(thesaurusId));
        solrServer.commit();
    } catch (SolrServerException e) {
        throw new TechnicalException("Error executing query for clearing SOLR index!", e);
    } catch (IOException e) {
        throw new TechnicalException("IO error during executing query for clearing SOLR index!", e);
    } catch (SolrException e) {
        throw new TechnicalException("Error executing query for clearing SOLR index!", e);
    }
}

From source file:fr.mcc.ginco.tests.solr.ThesaurusIndexerServiceTest.java

License:CeCILL license

@Test
public void testRemoveThesaurusIndex() throws TechnicalException, IOException, SolrServerException {

    String thesaurusId = "http://th1";
    thesaurusIndexerService.removeThesaurusIndex(thesaurusId);

    verify(solrServer).deleteByQuery(SolrField.THESAURUSID + ":" + ClientUtils.escapeQueryChars(thesaurusId));
    verify(solrServer).commit();//w  ww .  j  a  v  a2 s .c o  m
}

From source file:jp.aegif.nemaki.cmis.aspect.query.solr.SolrPredicateWalker.java

License:Open Source License

/**
 * TODO Implement check for each kind of literal
 * Parse field name & condition value. Field name is prepared for Solr
 * query.//  w  ww.ja v  a2s . c  om
 *
 * @param leftNode
 * @param rightNode
 * @return
 */
private HashMap<String, String> walkCompareInternal(Tree leftNode, Tree rightNode) {
    HashMap<String, String> map = new HashMap<String, String>();

    String left = solrUtil.convertToString(leftNode);
    String right = walkExpr(rightNode).toString();

    map.put(FLD, ClientUtils.escapeQueryChars(solrUtil.getPropertyNameInSolr(repositoryId, left)));
    map.put(CND, right);
    return map;
}

From source file:jp.aegif.nemaki.cmis.aspect.query.solr.SolrPredicateWalker.java

License:Open Source License

private Object walkString(Tree node) {
    String s = node.getText();/*from  w  ww  . ja  v a2  s.com*/
    s = s.substring(1, s.length() - 1);
    //return "\"" + ClientUtils.escapeQueryChars(s) + "\"";
    return ClientUtils.escapeQueryChars(s);
}

From source file:jp.aegif.nemaki.query.solr.SolrPredicateWalker.java

License:Open Source License

/**
 * TODO Implement check for each kind of literal
 * Parse field name & condition value. Field name is prepared for Solr
 * query.//from w w  w .j  a va  2s .  c  o m
 *
 * @param leftNode
 * @param rightNode
 * @return
 */
private HashMap<String, String> walkCompareInternal(Tree leftNode, Tree rightNode) {
    HashMap<String, String> map = new HashMap<String, String>();

    String left = solrUtil.convertToString(leftNode);
    String right = walkExpr(rightNode).toString();

    map.put(FLD, ClientUtils.escapeQueryChars(solrUtil.getPropertyNameInSolr(left)));
    map.put(CND, right);
    return map;
}