Reverse search in Hibernate Search

Posted by Javi on Stack Overflow See other posts from Stack Overflow or by Javi
Published on 2010-04-16T08:43:22Z Indexed on 2010/04/16 9:13 UTC
Read the original article Hit count: 288

Hello,

I'm using Hibernate Search (which uses Lucene) for searching some Data I have indexed in a directory. It works fine but I need to do a reverse search. By reverse search I mean that I have a list of queries stored in my database I need to check which one of these queries match with a Data object each time Data Object is created. I need it to alert the user when a Data Object matches with a Query he has created. So I need to index this single Data Object which has just been created and see which queries of my list has this object as a result.

I've seen Lucene MemoryIndex Class to create an index in memory so I can do something like this example for every query in a list (though iterating in a Java list of queries would not be very efficient):

//Iterating over my list<Query>
MemoryIndex index = new MemoryIndex();
//Add all fields
index.addField("myField", "myFieldData", analyzer);
...
QueryParser parser = new QueryParser("myField", analyzer);
float score = index.search(query);
if (score > 0.0f) {
    System.out.println("it's a match");
} else {
    System.out.println("no match found");
}

The problem here is that this Data Class has several Hibernate Search Annotations @Field,@IndexedEmbedded,... which indicated how fields should be indexed, so when I invoke index() method on the FullTextEntityManager instance it uses this information to index the object in the directory. Is there a similar way to index it in memory using this information?

Is there a more efficient way of doing this reverse search?

Thanks

© Stack Overflow or respective owner

Related posts about lucene

Related posts about lucene-index