private SpatialQueryBuilderAbstract parseOperation(Map<String, Object> query) { String operator = (String) query.get(GEO_FILTER); SpatialQueryBuilderAbstract spatialQueryBuilder = operators.get(operator); if (spatialQueryBuilder == null) { throw new OIndexEngineException("Operator " + operator + " not supported.", null); } return spatialQueryBuilder; } }
protected Shape parseShape(Map<String, Object> query) { Object geometry = query.get(SHAPE); if (geometry == null) { throw new OIndexEngineException("Invalid spatial query. Missing shape field " + query, null); } return factory.fromObject(geometry); }
protected IndexableField buildFacetField(String f, Object val) { String[] path = null; if (val instanceof String) { path = ((String) val).split("/"); // path = new String[1]; // path[0] = (String) val; } else if (val instanceof Iterable) { Iterable iterable = (Iterable) val; List<String> values = new ArrayList<String>(); for (Object s : iterable) { if (s instanceof String) { values.add((String) s); } else { throw new OIndexEngineException("Cannot facet value " + val + " because it is not a string", null); } } path = values.toArray(new String[values.size()]); } return new FacetField(f, path); }
private Set<OIdentifiable> legacySearch(Object key, OLuceneTxChanges changes) throws IOException { if (key instanceof OSpatialCompositeKey) { final OSpatialCompositeKey newKey = (OSpatialCompositeKey) key; final SpatialOperation strategy = newKey.getOperation() != null ? newKey.getOperation() : SpatialOperation.Intersects; if (SpatialOperation.Intersects.equals(strategy)) return searchIntersect(newKey, newKey.getMaxDistance(), newKey.getContext(), changes); else if (SpatialOperation.IsWithin.equals(strategy)) return searchWithin(newKey, newKey.getContext(), changes); } else if (key instanceof OCompositeKey) { return searchIntersect((OCompositeKey) key, 0, null, changes); } throw new OIndexEngineException("Unknown key" + key, null); }
@Override public Query buildQuery(Object maybeQuery) { try { if (maybeQuery instanceof String) { return queryBuilder.query(indexDefinition, maybeQuery, EMPTY_METADATA, queryAnalyzer()); } else { OLuceneKeyAndMetadata q = (OLuceneKeyAndMetadata) maybeQuery; Query query = queryBuilder.query(indexDefinition, q.key, q.metadata, queryAnalyzer()); return query; } } catch (ParseException e) { throw OException.wrapException(new OIndexEngineException("Error parsing query"), e); } }
@Override public Object get(Object key) { Query q = null; try { q = OLuceneIndexType.createFullQuery(index, key, mgrWriter.getIndexWriter().getAnalyzer(), getLuceneVersion(metadata)); OCommandContext context = null; if (key instanceof OFullTextCompositeKey) { context = ((OFullTextCompositeKey) key).getContext(); } return getResults(q, context, key); } catch (ParseException e) { throw new OIndexEngineException("Error parsing lucene query ", e); } }
private static long resolveFileIdByName(String fileName) { final OAbstractPaginatedStorage storage = (OAbstractPaginatedStorage) ODatabaseRecordThreadLocal.instance().get().getStorage() .getUnderlying(); boolean rollback = false; final OAtomicOperation atomicOperation; try { atomicOperation = storage.getAtomicOperationsManager().startAtomicOperation(fileName, true); } catch (IOException e) { throw OException.wrapException(new OIndexEngineException("Error creation of sbtree with name " + fileName, fileName), e); } try { long fileId; if (atomicOperation.isFileExists(fileName)) { fileId = atomicOperation.loadFile(fileName); } else { fileId = atomicOperation.addFile(fileName); } return fileId; } catch (IOException e) { rollback = true; throw OException.wrapException(new OIndexEngineException("Error creation of sbtree with name " + fileName, fileName), e); } finally { try { storage.getAtomicOperationsManager().endAtomicOperation(rollback); } catch (IOException ioe) { OLogManager.instance().error(OMixedIndexRIDContainer.class, "Error of rollback of atomic operation", ioe); } } }
atomicOperation = storage.getAtomicOperationsManager().startAtomicOperation(fileName, true); } catch (IOException e) { throw OException.wrapException(new OIndexEngineException("Error creation of sbtree with name " + fileName, fileName), e); } catch (IOException e) { rollback = true; throw OException.wrapException(new OIndexEngineException("Error creation of sbtree with name " + fileName, fileName), e); } catch (RuntimeException e) { rollback = true;
@Override public Set<OIdentifiable> getInTx(Object key, OLuceneTxChanges changes) { updateLastAccess(); openIfClosed(); try { if (key instanceof OLuceneKeyAndMetadata) { OLuceneKeyAndMetadata q = (OLuceneKeyAndMetadata) key; Query query = queryBuilder.query(indexDefinition, q.key, q.metadata, queryAnalyzer()); OCommandContext commandContext = q.key.getContext(); return getResults(query, commandContext, changes, q.metadata); } else { Query query = queryBuilder.query(indexDefinition, key, EMPTY_METADATA, queryAnalyzer()); OCommandContext commandContext = null; if (key instanceof OLuceneCompositeKey) { commandContext = ((OLuceneCompositeKey) key).getContext(); } return getResults(query, commandContext, changes, EMPTY_METADATA); } } catch (ParseException e) { throw OException.wrapException(new OIndexEngineException("Error parsing lucene query"), e); } }