use of org.polymap.recordstore.RecordQuery in project polymap4-core by Polymap4.
the class LuceneRecordStore method find.
@Override
public ResultSet find(RecordQuery query) throws Exception {
assert !isClosed() : "Store is closed already.";
// SimpleQuery
if (query instanceof SimpleQuery) {
Query luceneQuery = null;
Collection<QueryExpression> expressions = ((SimpleQuery) query).expressions();
if (expressions.isEmpty()) {
luceneQuery = new MatchAllDocsQuery();
} else {
luceneQuery = new BooleanQuery();
for (QueryExpression exp : expressions) {
((BooleanQuery) luceneQuery).add(valueCoders.searchQuery(exp), BooleanClause.Occur.MUST);
}
}
return new LuceneRecordQuery(this, luceneQuery).setMaxResults(query.getMaxResults()).setFirstResult(query.getFirstResult()).sort(query.getSortKey(), query.getSortOrder(), query.getSortType()).execute();
} else // other
{
return query.execute();
}
}
use of org.polymap.recordstore.RecordQuery in project polymap4-core by Polymap4.
the class LuceneQueryDialect method getCount.
@Override
public int getCount(RFeatureStore fs, Query query) throws IOException {
// XXX handle postProcess
Transformer transformer = new Transformer();
RecordQuery rsQuery = transformer.transform(fs, query);
try {
ResultSet resultSet = rs(fs).find(rsQuery);
return resultSet.count();
} catch (IOException e) {
throw e;
} catch (Exception e) {
throw new IOException(e);
}
}
use of org.polymap.recordstore.RecordQuery in project polymap4-core by Polymap4.
the class Cache304 method get.
/**
* @param request
* @param layers
* @param props The processor properties for this layer.
* @return The cached tile or null.
*/
public CachedTile get(PipelineProcessorSite site, GetMapRequest request) {
try {
// keep store and queue stable; prevent race between removing
// Command from queue and writing to store
lock.readLock().lock();
// search the store
RecordQuery query = buildQuery(site, request);
query.setMaxResults(2);
ResultSet resultSet = store.find(query);
if (resultSet.count() > 1) {
log.warn("More than one tile for query: " + request);
}
List<CachedTile> result = new ArrayList();
for (IRecordState state : resultSet) {
result.add(new CachedTile(state, dataDir));
}
// search the queue
updateQueue.adaptCacheResult(result, query);
if (result.size() > 1) {
log.warn("More than one tile in result: " + result.size());
}
if (!result.isEmpty()) {
CachedTile cachedTile = result.get(0);
long now = System.currentTimeMillis();
if (!cachedTile.dataExists()) {
log.warn("Tile data file lost for: " + cachedTile.filename.get());
return null;
}
// done in the last accessTimeRasterMillis
if ((cachedTile.lastAccessed.get() + accessTimeRasterMillis) < now) {
cachedTile.lastAccessed.put(now);
updateQueue.push(new CacheUpdateQueue.TouchCommand(cachedTile));
updater.reSchedule();
}
statistics.incLayerCounter(site.layerId.get(), false);
return cachedTile;
} else {
statistics.incLayerCounter(site.layerId.get(), true);
return null;
}
} catch (Exception e) {
log.error("", e);
return null;
} finally {
lock.readLock().unlock();
}
}
use of org.polymap.recordstore.RecordQuery 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);
}
}
use of org.polymap.recordstore.RecordQuery in project polymap4-core by Polymap4.
the class LuceneQueryDialect method getBounds.
@Override
public ReferencedEnvelope getBounds(RFeatureStore fs, Query query) throws IOException {
Timer timer = new Timer();
FeatureType schema = fs.getSchema();
assert schema.getGeometryDescriptor() != null : "Schema has no Geometry: " + schema;
String geomName = schema.getGeometryDescriptor().getLocalName();
// type/name query
// XXX handle postProcess
Transformer transformer = new Transformer();
RecordQuery rsQuery = transformer.transform(fs, query);
rsQuery.setMaxResults(1);
try {
// MinX
String fieldName = geomName + GeometryValueCoder.FIELD_MINX;
rsQuery.sort(fieldName, RecordQuery.ASC, Double.class);
ResultSet resultSet = rs(fs).find(rsQuery);
if (resultSet.count() == 0) {
return ReferencedEnvelope.EVERYTHING;
}
IRecordState record = resultSet.get(0);
double minX = record.get(fieldName);
// MaxX
fieldName = geomName + GeometryValueCoder.FIELD_MAXX;
rsQuery.sort(fieldName, RecordQuery.DESC, Double.class);
resultSet = rs(fs).find(rsQuery);
double maxX = resultSet.get(0).get(fieldName);
// MinY
fieldName = geomName + GeometryValueCoder.FIELD_MINY;
rsQuery.sort(fieldName, RecordQuery.ASC, Double.class);
resultSet = rs(fs).find(rsQuery);
double minY = resultSet.get(0).get(fieldName);
// MaxX
fieldName = geomName + GeometryValueCoder.FIELD_MAXY;
rsQuery.sort(fieldName, RecordQuery.DESC, Double.class);
resultSet = rs(fs).find(rsQuery);
double maxY = resultSet.get(0).get(fieldName);
log.info("Bounds: ... (" + timer.elapsedTime() + "ms)");
return new ReferencedEnvelope(minX, maxX, minY, maxY, schema.getCoordinateReferenceSystem());
} catch (IOException e) {
throw e;
} catch (Exception e) {
throw new IOException(e);
}
}
Aggregations