LuceneStoreImpl implements Store { @Override public List<Alert> query(String queryString) throws Exception { List<Alert> alerts = new ArrayList<>(); IndexReader indexReader = DirectoryReader.open(indexWriter); IndexSearcher indexSearcher = new IndexSearcher(indexReader); StandardQueryParser queryParser = new StandardQueryParser(); queryParser.setAllowLeadingWildcard(true); queryParser.setPointsConfigMap(points); Query query = queryParser.parse(queryString, ""); TopDocs topDocs = indexSearcher.search(query, Integer.MAX_VALUE, Sort.INDEXORDER, false); for (int i = 0; i < topDocs.scoreDocs.length; i++) { alerts.add(documentToAlert(indexSearcher.doc(topDocs.scoreDocs[i].doc))); } return alerts; }  @Activate void activate(); @Deactivate void deactivate(); @Override String store(Event event); @Override void cleanup(); @Override void eviction(); @Override void flag(String queryString, String ruleName); @Override List<Alert> list(); @Override List<Alert> query(String queryString); @Override void delete(String queryString); static final String INDEX_DIRECTORY; static final String POINTS_DIRECTORY; }
@Test public void testQuery() throws Exception { HashMap<String, Object> data = new HashMap<>(); data.put("threadCount", 200); data.put("alertTimestamp", System.currentTimeMillis()); data.put("mydouble", 2.5); data.put("content", "this is a raw text"); Event event = new Event("collected", data); alertingService.store(event); data = new HashMap<>(); data.put("other", "value"); data.put("alertTimestamp", System.currentTimeMillis()); event = new Event("collected", data); alertingService.store(event); List<Alert> found = alertingService.query("content:this* AND threadCount:[0 TO 200]"); Assert.assertEquals(1, found.size()); Assert.assertEquals(200, found.get(0).get("threadCount")); Assert.assertEquals("this is a raw text", found.get(0).get("content")); Assert.assertEquals(2.5, found.get(0).get("mydouble")); long past = System.currentTimeMillis() - 60 * 1000; data = new HashMap<>(); data.put("scope", "out"); data.put("alertTimestamp", System.currentTimeMillis() - 2 * 60 * 60 * 1000); event = new Event("collected", data); alertingService.store(event); found = alertingService.query("alertTimestamp:[" + past + " TO *]"); Assert.assertEquals(2, found.size()); data = new HashMap<>(); data.put("period", "test"); data.put("alertTimestamp", System.currentTimeMillis() - 5 * 60 * 1000); event = new Event("collected", data); alertingService.store(event); found = alertingService.query("period:test"); Assert.assertEquals(1, found.size()); }