1
votes

I have a list of categories, e.g. 1000, 1001, 1002, 1003, etc... and users have access to only some of these categories. I want to filter my lucene.net search results based on only categories that the user has access to, or to omit results for items they don't have access to.

I have tried using the Lucene FieldCacheTermsFilter but this returns no results at all:

New Lucene.net.search.FieldCacheTermsFilter("category", {"1000", "1002"} )

Is there a better way to filter results based on a particular field having a value that exists in a list?

1

1 Answers

1
votes

I solved this by using a BooleanQuery wrapper around my main query in all cases.

I took my originaly search query (MainQuery) and created a new BooleanQuery using occur.must for that and my security query as below:

dim SecurityQuery as New lucene.net.search.BooleanQuery( )
For Each id as string in AllowedIDs
    q.Add(New TermQuery(New Lucene.Net.Index.Term("category", s)), Occur.SHOULD)
Next

Dim FinalQuery As New lucene.net.search.BooleanQuery( )
FinalQuery.Add( MainQuery, occur.must )
FinalQuery.Add( SecurityQuery, occur.must )

This doesn't use a Filter, so I am unsure as to whether this is the best performing option. But it works.