I have two classes:
Code:
@Indexed
public class Book implements Serializable
{
@DocumentId
private Integer id;
@ContainedIn //is this the correct annotaion??
private Set <Keyword> keywords = new HashSet();
//whole bag of other fields
............
}
@Indexed
public class Keyword implements Serializable
{
@DocumentId
private Integer id;
@ IndexedEmbedded //is this the correct annotaion??
@Field(name="keyword", index=Index.TOKENIZED, store=Store.YES)
private String name;
//do I need to index this????
private Set <Book>books = new HashSet();
..........
}
And my query code looks like this:
Code:
FullTextSession fullTextSession = Search.createFullTextSession(session);
//why "id" here???
org.apache.lucene.queryParser.QueryParser parser = new QueryParser("id", new StopAnalyzer() );
String queryString = "keyword:france"; //for example
org.apache.lucene.search.Query luceneQuery = parser.parse(queryString );
//do I need to add Keyword.class here????
org.hibernate.Query fullTextQuery = fullTextSession.createFullTextQuery( luceneQuery, Book.class/*, Keyword.class*/ );
result = fullTextQuery.list();
And I want to do a fulltext search returning only Book objects. This is working nicely if I just search the Book fields - but I also want it to match Keyword names.
Firstly I'm unclear about the roles of @ContainedIn and @IndexedEmbedded. Have I got it right?
At present, it builds two indexes - one for Books and one for Keywords. But I only want to get Book objects back. Is this correct? Or do I need to "embed" keyword index inside the book index?
Also, I wonder if I perhaps need to index the
private Set <Book> books = new HashSet();
in my Keywords class?
And what arguments should I pass to the method
fullTextSession.createFullTextQuery()??
I've noticed that if I pass the Keyword.class, I can get my Keyword objects back - but then I have to go through a load of laborious code to get back the corresponding Book object.
Does anyone know a good online tutorial that explains all this? I've read the docs and googled around but not found anything beyond the Hibernate Reference Guide and have spent a couple of days on this without getting much further - so any help anyone can give me would be much appreciated. Thanks