Domanda

I'm working on a project where I have to index images and their textual metadata. I first thought about Lucene but it's not supporting images. Then I found LIre but it's only working with images and the metadata wouldn't be handled.

Is there an open-source solution to index images and their metadata in a single index?

Otherwise, the only solution I found would be to have two separate indexes and to merge the results. I jut can't figure out how to merge them considering that to each indexed image matches a set of indexed metadata. In this case, I probably need a way to link the set of metadata to the image and reciprocally.

Could you explain to me how I could actually merge the results?

È stato utile?

Soluzione

I'm not intimately familiar with LIRE, but it looks like you'll create documents using a DocumentBuilder. When you get a Document back from it, you could easily add your own fields to it, like:

 DocumentBuilder builder = /*create your builder*/
 Document doc = builder.createDocument(image, id);
 Field metadata = /*create your metadata field*/
 doc.add(metadata);
 indexWriter.addDocument(doc);

This would allow you to leverage LIRE image recognition and be able to search based on metadata separately. If you need to be able to hybridize the two, such as as image recognition search filtered by some metadata match constraint, you'll likely need to implement that yourself. Looking into code of GenericFastImageSearcher, it doesn't actually construct Lucene queries, but rather iterates images and compares to find the best matches. You should be able to create your own version of the findSimilar method, filtering results within the iteration loop by simiply continuing where it is not met:

for (int i = 0; i < docs; i++) {
    if (reader.hasDeletions() && !liveDocs.get(i)) continue;
    d = reader.document(i);
    if (!d.getField("metadata").equals(constraint)) continue; 
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top