I am building an app that has a Calendar in which users can annotate events.
The Calendar is private to each user, that is, user A cannot see the events on user B's calendar.
I would like to index the calendar events using Zend Lucene, but I'm unsure how to do this.
I could have Lucene index all events together, regardless of user -- but then when a search is done it will show events of one user to the other, and that's not what I want.
I don't think it would be a good idea to create an index exclusive to each user, but am out of ideas how to:
- create a common index of calendar events from all users
- when a search is done, force results to show only events that belong to user performing the search
Any ideas/suggestions/pointers on how to do this?
Here's how I solved this issue:
First, make sure you include
user_id
field when building the indexNote that it is wise to use
Keyword()
foruser_id
since we want Lucene to search as well as display this data in results.Next, add a boolean subquery on the backend (programatically) that will force all results to include the query string (user's search input) AND this user's
user_id
.And there you have it.
Now if user
123
searches for 'appointment', Lucene will make the search actually be something likeappointment AND user_id=123
.Let me know if there's any way to improve this - glad to discuss.