private Filter buildFilter(final GazetteerQuery params) {
        List<Query> queryParts = new ArrayList<Query>();

        // create the historical locations restriction if we are not including historical locations
        if (!params.isIncludeHistorical()) {
            int val = IndexField.getBooleanIndexValue(false);
            queryParts.add(NumericRangeQuery.newIntRange(HISTORICAL.key(), val, val, true, true));
        }

        // create the parent ID restrictions if we were provided at least one parent ID
        Set<Integer> parentIds = params.getParentIds();
        if (!parentIds.isEmpty()) {
            BooleanQuery parentQuery = new BooleanQuery();
            // locations must descend from at least one of the specified parents (OR)
            for (Integer id : parentIds) {
                parentQuery.add(NumericRangeQuery.newIntRange(ANCESTOR_IDS.key(), id, id, true, true), Occur.SHOULD);
            }
            queryParts.add(parentQuery);
        }

        // create the feature code restrictions if we were provided some, but not all, feature codes
        Set<FeatureCode> codes = params.getFeatureCodes();
        if (!(codes.isEmpty() || ALL_CODES.equals(codes))) {
            BooleanQuery codeQuery = new BooleanQuery();
            // locations must be one of the specified feature codes (OR)
            for (FeatureCode code : codes) {
                codeQuery.add(new TermQuery(new Term(FEATURE_CODE.key(), code.name())), Occur.SHOULD);
            }
            queryParts.add(codeQuery);
        }

        Filter filter = null;
        if (!queryParts.isEmpty()) {
            BooleanQuery bq = new BooleanQuery();
            for (Query part : queryParts) {
                bq.add(part, Occur.MUST);
            }
            filter = new QueryWrapperFilter(bq);
        }
        return filter;
    }
private Filter buildFilter ( final GazetteerQuery params ) { List < Query > queryParts = new ArrayList < Query > ( ) ; if ( ! params . isIncludeHistorical ( ) ) { int val = IndexField . getBooleanIndexValue ( false ) ; queryParts . add ( NumericRangeQuery . newIntRange ( HISTORICAL . key ( ) , val , val , true , true ) ) ; } Set < Integer > parentIds = params . getParentIds ( ) ; if ( ! parentIds . isEmpty ( ) ) { BooleanQuery parentQuery = new BooleanQuery ( ) ; for ( Integer id : parentIds ) { parentQuery . add ( NumericRangeQuery . newIntRange ( ANCESTOR_IDS . key ( ) , id , id , true , true ) , Occur . SHOULD ) ; } queryParts . add ( parentQuery ) ; } Set < FeatureCode > codes = params . getFeatureCodes ( ) ; if ( ! ( codes . isEmpty ( ) || ALL_CODES . equals ( codes ) ) ) { BooleanQuery codeQuery = new BooleanQuery ( ) ; for ( FeatureCode code : codes ) { codeQuery . add ( new TermQuery ( new Term ( FEATURE_CODE . key ( ) , code . name ( ) ) ) , Occur . SHOULD ) ; } queryParts . add ( codeQuery ) ; } Filter filter = null ; if ( ! queryParts . isEmpty ( ) ) { BooleanQuery bq = new BooleanQuery ( ) ; for ( Query part : queryParts ) { bq . add ( part , Occur . MUST ) ; } filter = new QueryWrapperFilter ( bq ) ; } return filter ; }
Builds a Lucene search filter based on the provided parameters.
@param params the query configuration parameters
@return a Lucene search filter that will restrict the returned documents to the criteria provided or <code>null</code>
if no filtering is necessary