/** * Delete a term document * * @param pictureId * @param conf * @throws IOException */ public static void delete(UUID pictureId, IndexWriterConfig conf) throws IOException { /* create term to delete document */ Term term = new Term(DocumentBuilder.FIELD_NAME_IDENTIFIER, pictureId.toString()); for (FeatureEnumerate f : FeatureEnumerate.values()) { deleteFromFeature(pictureId, term, f.getText(), conf); } }
/** * Search a picture * * @param imageBytes * @param maxHits * @param feature * @param pictures * @return * @throws IOException */ public static List<LirePictureSortable> search( byte[] imageBytes, int maxHits, FeatureEnumerate feature, List<LirePictureSortable> pictures) throws IOException { File path = getPath(feature.getText()); log.debug("reading from indexed path " + path.getAbsolutePath()); List<LirePictureSortable> result = new ArrayList<>(); try { IndexReader ir = DirectoryReader.open(FSDirectory.open(path)); ImageSearcher searcher = new GenericFastImageSearcher(maxHits, feature.getValueClass()); // searching with a image file ... InputStream in = new ByteArrayInputStream(imageBytes); ImageSearchHits hits = searcher.search(in, ir); float score = 0.0F; for (int i = 0; i < hits.length(); i++) { score = hits.score(i); LirePictureSortable lp = new LirePictureSortable( UUID.fromString(hits.doc(i).getValues(DocumentBuilder.FIELD_NAME_IDENTIFIER)[0]), score, feature); /* check is its a picture was repeated by picture UUID */ if (pictures.contains(lp)) { lp = pictures.get(pictures.indexOf(lp)); lp.addDescriptor(feature, score); lp.addScore(score); } else { result.add(lp); } } } catch (Exception e) { e.printStackTrace(); } return result; }