Search in sources :

Example 1 with RecordQuery

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();
    }
}
Also used : BooleanQuery(org.apache.lucene.search.BooleanQuery) SimpleQuery(org.polymap.recordstore.SimpleQuery) Query(org.apache.lucene.search.Query) RecordQuery(org.polymap.recordstore.RecordQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) SimpleQuery(org.polymap.recordstore.SimpleQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) QueryExpression(org.polymap.recordstore.QueryExpression) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery)

Example 2 with RecordQuery

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);
    }
}
Also used : ResultSet(org.polymap.recordstore.ResultSet) IOException(java.io.IOException) RecordQuery(org.polymap.recordstore.RecordQuery) LuceneRecordQuery(org.polymap.recordstore.lucene.LuceneRecordQuery) IOException(java.io.IOException)

Example 3 with RecordQuery

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();
    }
}
Also used : ResultSet(org.polymap.recordstore.ResultSet) ArrayList(java.util.ArrayList) IRecordState(org.polymap.recordstore.IRecordState) RecordQuery(org.polymap.recordstore.RecordQuery) IOException(java.io.IOException)

Example 4 with RecordQuery

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

Example 5 with RecordQuery

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);
    }
}
Also used : FeatureType(org.opengis.feature.type.FeatureType) ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) Timer(org.polymap.core.runtime.Timer) ResultSet(org.polymap.recordstore.ResultSet) IRecordState(org.polymap.recordstore.IRecordState) IOException(java.io.IOException) RecordQuery(org.polymap.recordstore.RecordQuery) LuceneRecordQuery(org.polymap.recordstore.lucene.LuceneRecordQuery) IOException(java.io.IOException)

Aggregations

RecordQuery (org.polymap.recordstore.RecordQuery)5 IOException (java.io.IOException)4 ResultSet (org.polymap.recordstore.ResultSet)4 IRecordState (org.polymap.recordstore.IRecordState)3 LuceneRecordQuery (org.polymap.recordstore.lucene.LuceneRecordQuery)3 Timer (org.polymap.core.runtime.Timer)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 BooleanQuery (org.apache.lucene.search.BooleanQuery)1 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)1 Query (org.apache.lucene.search.Query)1 ReferencedEnvelope (org.geotools.geometry.jts.ReferencedEnvelope)1 Feature (org.opengis.feature.Feature)1 FeatureType (org.opengis.feature.type.FeatureType)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 IRecordFieldSelector (org.polymap.recordstore.IRecordFieldSelector)1 QueryExpression (org.polymap.recordstore.QueryExpression)1