Example usage for org.apache.solr.common.params ModifiableSolrParams ModifiableSolrParams

List of usage examples for org.apache.solr.common.params ModifiableSolrParams ModifiableSolrParams

Introduction

In this page you can find the example usage for org.apache.solr.common.params ModifiableSolrParams ModifiableSolrParams.

Prototype

public ModifiableSolrParams() 

Source Link

Usage

From source file:at.newmedialab.lmf.util.solr.suggestion.service.SuggestionService.java

License:Apache License

private SolrQueryResponse query(String query, String df, String[] fields, String[] fqs) {

    SolrQueryResponse rsp = new SolrQueryResponse();

    //append *//ww  w  . j  av  a2 s. co m
    if (!query.endsWith("*")) {
        query = query.trim() + "*";
    }

    //Prepare query
    ModifiableSolrParams params = new ModifiableSolrParams();
    SolrQueryRequest req = new LocalSolrQueryRequest(solrCore, params);
    params.add(CommonParams.Q, query.toLowerCase());
    params.add(CommonParams.DF, df);
    params.add("q.op", "AND");
    params.add(FacetParams.FACET, "true");
    params.add(FacetParams.FACET_LIMIT, internalFacetLimit);
    params.add(FacetParams.FACET_MINCOUNT, "1");
    for (String field : fields) {
        params.add(FacetParams.FACET_FIELD, field);
    }
    if (fqs != null) {
        for (String fq : fqs) {
            params.add(CommonParams.FQ, fq);
        }
    }

    if (spellcheck_enabled) {
        params.add("spellcheck", "true");
        params.add("spellcheck.collate", "true");
    }

    try {
        //execute query and return
        searchHandler.handleRequestBody(req, rsp);
        return rsp;
    } catch (SolrException se) {
        throw se;
    } catch (Exception e) {
        e.printStackTrace();
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "internal server error");
    } finally {
        req.close();
    }
}

From source file:au.org.ala.biocache.dao.SearchDAOImpl.java

License:Open Source License

/**
 * Gets the details about the SOLR fields using the LukeRequestHandler:
 * See http://wiki.apache.org/solr/LukeRequestHandler  for more information
 *//*  www .j a va 2s .c om*/
public Set<IndexFieldDTO> getIndexFieldDetails(String... fields) throws Exception {
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set("qt", "/admin/luke");

    params.set("tr", "luke.xsl");
    if (fields != null) {
        params.set("fl", fields);
        params.set("numTerms", "1");
    } else {
        // TODO: We should be caching the result locally without calling Solr in this case, as it is called very often
        params.set("numTerms", "0");
    }
    QueryResponse response = query(params, queryMethod);
    return parseLukeResponse(response.toString(), fields != null);
}

From source file:com.apexxs.neonblack.solr.Queries.java

License:Apache License

public List<GeoNamesEntry> doNameQuery(String searchTerm) {
    List<GeoNamesEntry> entries = new ArrayList<>();

    String sortString;//www  . j a  va  2 s .  c  om
    if (config.populationSort()) {
        sortString = "population desc, score desc";
    } else {
        sortString = "score desc";
    }

    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set("qt", "/nameSearcher");
    params.set("q", searchTerm);
    params.set("mm", "100%");
    params.set("qs", "3");
    params.set("fl", "*, score");
    params.set("sort", sortString);
    params.set("rows", config.getMaxHits());

    try {
        QueryResponse response = geonamesCore.query(params);
        entries = response.getBeans(GeoNamesEntry.class);

    } catch (Exception ex) {
        logger.error("Error in doNameQuery for argument " + searchTerm + " " + ex.getMessage());
    }

    return entries;
}

From source file:com.apexxs.neonblack.solr.Queries.java

License:Apache License

public List<GeoNamesEntry> doNameQuery(String searchTerm, String minShouldMatch) {
    List<GeoNamesEntry> entries = new ArrayList<>();

    String sortString;/*  ww  w. j a  v a  2s .co  m*/
    if (config.populationSort()) {
        sortString = "population desc, score desc";
    } else {
        sortString = "score desc";
    }

    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set("qt", "/nameSearcher");
    params.set("q", searchTerm);
    params.set("mm", minShouldMatch);
    params.set("fl", "*, score");
    params.set("sort", sortString);
    params.set("rows", config.getMaxHits());

    try {
        QueryResponse response = geonamesCore.query(params);
        entries = response.getBeans(GeoNamesEntry.class);
    } catch (Exception ex) {
        logger.error("Error in doNameQuery for argument " + searchTerm + " " + ex.getMessage());
    }

    return entries;
}

From source file:com.apexxs.neonblack.solr.Queries.java

License:Apache License

public List<GeoNamesEntry> doSelectQuery(String searchTerm) {
    List<GeoNamesEntry> entries = new ArrayList<>();

    String sortString;//from  ww w . j  a  v a2  s.  c om
    if (config.populationSort()) {
        sortString = "population desc, score desc";
    } else {
        sortString = "score desc";
    }

    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set("qt", "/select");
    params.set("q", searchTerm);
    params.set("fl", "*, score");
    params.set("sort", sortString);
    params.set("rows", config.getMaxHits());

    try {
        QueryResponse response = geonamesCore.query(params);
        entries = response.getBeans(GeoNamesEntry.class);

    } catch (Exception ex) {
        logger.error("Error in doSelectQuery for argument " + searchTerm + " " + ex.getMessage());
    }

    return entries;
}

From source file:com.apexxs.neonblack.solr.Queries.java

License:Apache License

public List<BorderData> doBorderQuery(String lonLat) {
    List<BorderData> entries = new ArrayList<>();

    String queryString = "shape:\"Intersects(" + lonLat + ")\"";

    ModifiableSolrParams params = new ModifiableSolrParams();
    params.add("q", "*:*");
    params.add("fq", queryString);

    try {//from w w  w.  j  a  v a2 s. c  o m
        QueryResponse response = geodataCore.query(params);
        entries = response.getBeans(BorderData.class);
    } catch (Exception ex) {
        logger.error("Error in doBorderQuery for argument " + lonLat + " " + ex.getMessage());
    }

    return entries;
}

From source file:com.apexxs.neonblack.solr.Queries.java

License:Apache License

public List<GeoNamesEntry> geoNamesWithinDistanceOf(String lonLat, String distanceInKm) {
    List<GeoNamesEntry> entries = new ArrayList<>();

    ModifiableSolrParams params = new ModifiableSolrParams();
    params.add("q", "*:*");
    params.add("fq", "{!geofilt sfield=lonLat}");
    params.add("pt", lonLat);
    params.add("d", distanceInKm);
    params.add("rows", config.getNumProximalHits().toString());

    try {//from   w  w w . j av a  2s.c o  m
        QueryResponse response = geonamesCore.query(params);
        entries = response.getBeans(GeoNamesEntry.class);
    } catch (Exception ex) {
        logger.error("Error in geoNamesWithinDistance for argument " + lonLat + ", " + distanceInKm + " "
                + ex.getMessage());
    }

    return entries;
}

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

License:Apache License

private NamedList<Object> createAlias(String alias, String collections)
        throws SolrServerException, IOException {
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set("collections", collections);
    params.set("name", alias);
    params.set("action", CollectionAction.CREATEALIAS.toString());
    QueryRequest request = new QueryRequest(params);
    request.setPath("/admin/collections");
    return cloudClient.request(request);
}

From source file:com.comm.sr.common.solr.SolrQueryService.java

public SolrQueryService(CacheService<String, String> cacheService, Properties settings) {
    super(cacheService, settings);
    try {//from www .  ja v  a 2  s . com
        String zkHost = settings.getProperty("solrcloud.zkHost");
        int max_connections = Integer.parseInt(settings.getProperty("solrcloud.max_connections"));
        int max_connections_per_host = Integer
                .parseInt(settings.getProperty("solrcloud.max_connections_per_host"));
        int zkConnectTimeout = Integer.parseInt(settings.getProperty("solrcloud.zkConnectTimeout"));
        int zkClientTimeout = Integer.parseInt(settings.getProperty("solrcloud.zkClientTimeout"));

        ModifiableSolrParams params = new ModifiableSolrParams();
        params.set(HttpClientUtil.PROP_MAX_CONNECTIONS, max_connections);
        params.set(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, max_connections_per_host);
        HttpClient client = HttpClientUtil.createClient(params);

        LBHttpSolrServer lbServer = new LBHttpSolrServer(client);

        cloudSolrServer = new CloudSolrServer(zkHost, lbServer);
        cloudSolrServer.setZkConnectTimeout(zkConnectTimeout);
        cloudSolrServer.setZkClientTimeout(zkClientTimeout);
    } catch (Exception e) {

    }

}

From source file:com.comm.sr.service.solr.SolrUpdateService.java

private void populateCloudServers() throws MalformedURLException {
    String collectNames = solrProperties.getString("solrcloud.collectionNames");
    String[] collectionNames_ = collectNames.split(",");
    for (String collectionNames_1 : collectionNames_) {
        CloudSolrServer cloudSolrServer = null;
        String zkHost = solrProperties.getString("solrcloud.zkHost");
        int max_connections = Integer.parseInt(solrProperties.getString("solrcloud.max_connections"));
        int max_connections_per_host = Integer
                .parseInt(solrProperties.getString("solrcloud.max_connections_per_host"));
        int zkConnectTimeout = Integer.parseInt(solrProperties.getString("solrcloud.zkConnectTimeout"));
        int zkClientTimeout = Integer.parseInt(solrProperties.getString("solrcloud.zkClientTimeout"));

        ModifiableSolrParams params = new ModifiableSolrParams();
        params.set(HttpClientUtil.PROP_MAX_CONNECTIONS, max_connections);
        params.set(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, max_connections_per_host);
        HttpClient client = HttpClientUtil.createClient(params);
        LBHttpSolrServer lbServer = new LBHttpSolrServer(client);
        cloudSolrServer = new CloudSolrServer(zkHost, lbServer);
        cloudSolrServer.setZkConnectTimeout(zkConnectTimeout);
        cloudSolrServer.setZkClientTimeout(zkClientTimeout);
        cloudSolrServer.setDefaultCollection(collectionNames_1);
        serverMap.put(collectionNames_1, cloudSolrServer);
    }/*from w w  w. j  a  v  a 2 s. c  o m*/

}