0
votes

Not sure if the tittle is correct for the purpose, but what i want is to be able to search only few documents (and not all) from a lucene index.

Think about it as the following context:

The user wants to search inside a book, which is indexed on lucene, chapter by chapter (every chapter corresponds to a document). The user needs to be able to select the chapters he wants to search in, avoiding irrelevant occurences for his study.

Is that possible to restrict the search to only some documents? or do i have to search ALL index and then filter the results?

Thank you!

2

2 Answers

1
votes

Lucene allows you to apply Query Filters, so that you can restrict the results only for those which match the filter criteria.
So basically you can search for chapter:chapter1 and the search will be limited only for chapter one documents

1
votes

Look at the QueryWrapperFilter. It will let you easily do this kind of thing.

Note however that this is more for ease of coding. This won't really help performance, because in the background, it's effectively searching the entire index, but it makes it easier to code "search within a search." Searching the entire index is not a problem because that's the whole purpose of an index--to make indexed searching extremely fast. This assumes that you have a book ID that is indexed, incidentally. If that is the case, then including the book ID in your search allows for very fast searches of the entire index for that particular book.