Search in sources :

Example 1 with IRecordFieldSelector

use of org.polymap.recordstore.IRecordFieldSelector in project polymap4-core by Polymap4.

the class LuceneQueryDialect method getFeatureStates.

@Override
public PostProcessResultSet getFeatureStates(RFeatureStore fs, final Query query) throws IOException {
    try {
        Timer timer = new Timer();
        // transform query
        final Transformer transformer = new Transformer();
        RecordQuery rsQuery = transformer.transform(fs, query);
        // field selector
        final String[] propNames = query.getPropertyNames();
        if (propNames != null) {
            rsQuery.setFieldSelector(new IRecordFieldSelector() {

                private Map<String, Boolean> keys = new HashMap(64);

                @Override
                public boolean test(String key) {
                    Boolean accepted = keys.get(key);
                    if (accepted == null) {
                        keys.put(key, accepted = Boolean.FALSE);
                        for (String propName : propNames) {
                            // XXX real field names and additional fields are not known here
                            if (key.startsWith(propName)) {
                                keys.put(key, accepted = Boolean.TRUE);
                                break;
                            }
                        }
                    }
                    return accepted;
                }
            });
        }
        final ResultSet results = rs(fs).find(rsQuery);
        log.debug("    non-processed results: " + results.count() + " ( " + timer.elapsedTime() + "ms)");
        return new PostProcessResultSet() {

            private boolean hasProcessing = !transformer.postProcess.isEmpty();

            private Filter filter = query.getFilter();

            @Override
            public Iterator<IRecordState> iterator() {
                return results.iterator();
            }

            @Override
            public boolean hasPostProcessing() {
                return hasProcessing;
            }

            @Override
            public boolean postProcess(Feature feature) {
                return hasProcessing ? filter.evaluate(feature) : true;
            }

            @Override
            public int size() {
                return results.count();
            }
        };
    } catch (IOException e) {
        throw e;
    } catch (Exception e) {
        throw new IOException(e);
    }
}
Also used : HashMap(java.util.HashMap) IOException(java.io.IOException) IRecordFieldSelector(org.polymap.recordstore.IRecordFieldSelector) Feature(org.opengis.feature.Feature) RFeature(org.polymap.core.data.rs.RFeature) IOException(java.io.IOException) Timer(org.polymap.core.runtime.Timer) IncludeFilter(org.opengis.filter.IncludeFilter) ExcludeFilter(org.opengis.filter.ExcludeFilter) Filter(org.opengis.filter.Filter) ResultSet(org.polymap.recordstore.ResultSet) IRecordState(org.polymap.recordstore.IRecordState) RecordQuery(org.polymap.recordstore.RecordQuery) LuceneRecordQuery(org.polymap.recordstore.lucene.LuceneRecordQuery)

Aggregations

IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Feature (org.opengis.feature.Feature)1 ExcludeFilter (org.opengis.filter.ExcludeFilter)1 Filter (org.opengis.filter.Filter)1 IncludeFilter (org.opengis.filter.IncludeFilter)1 RFeature (org.polymap.core.data.rs.RFeature)1 Timer (org.polymap.core.runtime.Timer)1 IRecordFieldSelector (org.polymap.recordstore.IRecordFieldSelector)1 IRecordState (org.polymap.recordstore.IRecordState)1 RecordQuery (org.polymap.recordstore.RecordQuery)1 ResultSet (org.polymap.recordstore.ResultSet)1 LuceneRecordQuery (org.polymap.recordstore.lucene.LuceneRecordQuery)1