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);
}
}
Aggregations