public class MemoryIndexTest { private static final String DATE_FIELD = "date"; MemoryIndex index = new MemoryIndex(); NumericTokenStream numericTokenStream = new NumericTokenStream(); @Before public void init() { index.addField(DATE_FIELD, numericTokenStream.setIntValue(20141116)); } @Test public void testRange() { Query query = NumericRangeQuery.newIntRange(DATE_FIELD, 20141115, 20141118, true, true); assertTrue(index.search(query) > 0); } }
private boolean matchField(Object iLeft, Object iRight, OLuceneFullTextIndex index, MemoryIndex memoryIndex) throws IOException, ParseException { for (IndexableField field : index.buildDocument(iLeft).getFields()) { memoryIndex.addField(field, index.indexAnalyzer()); } return memoryIndex.search(index.buildQuery(iRight)) > 0.0f; }
public boolean isDeleted(Document document, Object key, OIdentifiable value) { boolean match = false; List<String> strings = deleted.get(value.getIdentity().toString()); if (strings != null) { MemoryIndex memoryIndex = new MemoryIndex(); for (String string : strings) { Query q = engine.deleteQuery(string, value); memoryIndex.reset(); for (IndexableField field : document.getFields()) { memoryIndex.addField(field.name(), field.stringValue(), new KeywordAnalyzer()); } match = match || (memoryIndex.search(q) > 0.0f); } return match; } return match; }
@Override public Object execute(Object iThis, OIdentifiable iCurrentRecord, Object iCurrentResult, Object[] params, OCommandContext ctx) { OElement element = iThis instanceof OElement ? (OElement) iThis : ((OResult) iThis).toElement(); String indexName = (String) params[0]; OLuceneFullTextIndex index = searchForIndex(ctx, indexName); if (index == null) return false; String query = (String) params[1]; MemoryIndex memoryIndex = getOrCreateMemoryIndex(ctx); List<Object> key = index.getDefinition().getFields().stream().map(s -> element.getProperty(s)).collect(Collectors.toList()); try { for (IndexableField field : index.buildDocument(key).getFields()) { memoryIndex.addField(field, index.indexAnalyzer()); } ODocument metadata = getMetadata(params); OLuceneKeyAndMetadata keyAndMetadata = new OLuceneKeyAndMetadata( new OLuceneCompositeKey(Arrays.asList(query)).setContext(ctx), metadata); return memoryIndex.search(index.buildQuery(keyAndMetadata)) > 0.0f; } catch (ParseException e) { OLogManager.instance().error(this, "error occurred while building query", e); } return null; }
new OLuceneCompositeKey(Arrays.asList(query)).setContext(ctx), metadata); return memoryIndex.search(index.buildQuery(keyAndMetadata)) > 0.0f; } catch (ParseException e) { OLogManager.instance().error(this, "error occurred while building query", e);
new OLuceneCompositeKey(Arrays.asList(query)).setContext(ctx), metadata); return memoryIndex.search(index.buildQuery(keyAndMetadata)) > 0.0f; } catch (ParseException e) { OLogManager.instance().error(this, "error occurred while building query", e);
@Override public Object evaluateRecord(OIdentifiable iRecord, ODocument iCurrentResult, OSQLFilterCondition iCondition, Object iLeft, Object iRight, OCommandContext iContext) { OLuceneFullTextIndex index = involvedIndex(iRecord, iCurrentResult, iCondition, iLeft, iRight); if (index == null) { throw new OCommandExecutionException("Cannot evaluate lucene condition without index configuration."); } MemoryIndex memoryIndex = (MemoryIndex) iContext.getVariable("_memoryIndex"); if (memoryIndex == null) { memoryIndex = new MemoryIndex(); iContext.setVariable("_memoryIndex", memoryIndex); } memoryIndex.reset(); Document doc = index.buildDocument(iLeft); for (IndexableField field : doc.getFields()) { memoryIndex.addField(field.name(), field.stringValue(), index.analyzer(field.name())); } Query query = null; try { query = index.buildQuery(iRight); } catch (Exception e) { throw new OCommandExecutionException("Error executing lucene query.", e); } return memoryIndex.search(query) > 0.0f; }