Am building a ‘Book search’ API using Lucene. I need to index Book Name,Author, and Book category fields in Lucene index.
A single book can fall under multiple distinct book categories…for example:
BookName1 –fiction,humour,philosophy. BookName1 –fiction,science. BookName1 –humour,business. BookName4-humour and so on…..
User should be able to search all the books under a particular category say ‘homour’.
Given this situation, how do i index above fields and build the query in lucene?
You can have a field for a Lucene document occur multiple times. Create the document, add the values for the the name and author, then do the same for each category
When you search the index for a category, it will return all documents that have a category field with the value you’re after. The category should be a ‘Keyword’ field.
I’ve written it in english because the specific code is slightly different per lucene version.