Search in sources :

Example 6 with GeonamesUtility

use of org.opensextant.util.GeonamesUtility in project Xponents by OpenSextant.

the class GazetteerUpdateProcessorFactory method init.

/**
     * NamedList? in Solr. What a horror. Okay, they work, but...
     *
     * items found in solrconfig under the gaz update processor script:
     *
     * include_category -- Tells the update processor which flavors of data to
     * keep category_field -- the field name where a row of data is categorized.
     * countries -- a list of countries to use. stopterms -- a list of terms
     * used to mark rows of data as "search_only"
     *
     */
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void init(NamedList params) {
    /*
         * Load the exclusion names -- these are terms that are gazeteer
         * entries, e.g., gazetteer.name = <exclusion term>, that will be marked
         * as search_only = true.
         *
         */
    try {
        termFilter = new TagFilter();
        termFilter.enableCaseSensitive(false);
        helper = new GeonamesUtility();
    } catch (Exception err) {
        logger.error("Init failure", err);
    }
    String logTag = "GAZ UPR////////////// ";
    logger.debug("Parameters for Gaz Updater {}, size={}, Country Filter?{}", params, params.size(), params.getAll("countries"));
    if (params.size() == 0) {
        logger.debug(logTag + "Zero parameters found.");
        return;
    }
    NamedList p = (NamedList) params.getVal(0);
    logger.debug(logTag + "Found p={}", p);
    logger.debug(logTag + "P={}, V={}", p.getName(0), p.getVal(0));
    // array of
    List<String> ic = (List<String>) p.get("include_category");
    // String
    if (ic != null) {
        logger.debug(logTag + "Found CAT={}", ic);
        includeCategorySet = new HashSet<String>();
        List<String> val = TextUtils.string2list(ic.get(0), ",");
        includeCategorySet.addAll(val);
        if (includeCategorySet.contains("all")) {
            includeAll = true;
        }
    } else {
        logger.error(logTag + "No category found.");
    }
    /* Optional: filter entries with a country list
         *
         */
    List<String> cc = (List<String>) p.get("countries");
    if (cc != null) {
        logger.debug("Found CO={}", ic);
        includeCountrySet = new HashSet<>();
        List<String> val = TextUtils.string2list(cc.get(0), ",");
        includeCountrySet.addAll(val);
    } else {
        logger.debug("No country filter found");
    }
    if (params.get("category_field") != null) {
        catField = (String) p.get("category_field");
    }
    logger.debug(logTag + " DONE.   CAT={}, CO={}", includeCategorySet, includeCountrySet);
}
Also used : GeonamesUtility(org.opensextant.util.GeonamesUtility) NamedList(org.apache.solr.common.util.NamedList) NamedList(org.apache.solr.common.util.NamedList) List(java.util.List) IOException(java.io.IOException)

Aggregations

GeonamesUtility (org.opensextant.util.GeonamesUtility)6 Test (org.junit.Test)3 Country (org.opensextant.data.Country)3 IOException (java.io.IOException)2 Place (org.opensextant.data.Place)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 TreeMap (java.util.TreeMap)1 SolrServerException (org.apache.solr.client.solrj.SolrServerException)1 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)1 SolrDocument (org.apache.solr.common.SolrDocument)1 SolrDocumentList (org.apache.solr.common.SolrDocumentList)1 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)1 NamedList (org.apache.solr.common.util.NamedList)1 SolrGazetteer (org.opensextant.extractors.geo.SolrGazetteer)1 Logger (org.slf4j.Logger)1