Note that there are some explanatory texts on larger screens.

plurals
  1. POLucene.NET 2.9 Custom Filter to add authorisation
    text
    copied!<p>Friends,</p> <p>I'm new to Lucene...<br> I successfully created an index, added fields, I could search etc it works.</p> <p>Now, I've in my database a view that tell which users can see which document. This view is created using several complicated rules so I want to reuse the view. So I need to add a filter in Lucene search to remove documents that match the query but the users doesn't have access to.<br> What I tried to do now is:<br> - Store the db document id in a field. It's a Guid, I store it as a string.<br> - create a custom filter that fetch all document id the current user can access, then filter using the field in lucene </p> <p>I've the feeling that it'll not be efficient... User can have access to hundred of thousands documents, so I may retrieve 200 000 document Id I need to filter on. I suppose I've to cache some stuff...<br> Here is the code I've writen, but it doesn't work: no document are returned when the filter is used (it should return 3 docs)</p> <pre><code>public class LuceneAuthorisationFilter : Filter { public override DocIdSet GetDocIdSet(Lucene.Net.Index.IndexReader reader) { List&lt;Guid&gt; ids = this.load(); // Load list of ID from database OpenBitSet result = new OpenBitSet(reader.MaxDoc); int[] docs = new int[1]; int[] freq = new int[1]; for (int i = 0; i &lt; ids.Count; i++) { Lucene.Net.Index.TermDocs termDocs = reader.TermDocs(new Lucene.Net.Index.Term("EmId", ids.ElementAt(i).ToString())); int count = termDocs.Read(docs, freq); if (count == 1) { result.FastSet(docs[0]); } } return result; } } </code></pre> <p>Do you have any idea on what's wrong ? And how to increase perf ?</p> <p>Thank you</p> <p>EDIT:<br> The code above works, the problem was only that the EmId field was not indexed. Now I've changed and it works.<br> <strong>Now I would like to have any tip to improve performances</strong></p> <hr> <p><strong><em>2ND EDIT TO ADD FEEDBACK</em></strong></p> <p>Note: The test environment contains 25 000 documents, and the list of document access contains 50 000 id (because all documents are not yet </p> <p>indexed)</p> <ul> <li>Using the custom filter above: ~2600ms the 1st time, 2100ms the next times as filter is cached</li> <li>Using a Boolean query filter: ~4700ms then ~4000ms</li> </ul> <p>These are poor performances ... So I've searched again an found 'FieldCacheTermsFilter' filter. </p> <ul> <li>Using a FieldCacheTermsFilter: ~600ms then ~60ms</li> </ul> <p>This is acceptable performance</p> <p>PS: I also found another similar <a href="https://stackoverflow.com/questions/795532/how-do-i-pass-a-list-of-allowed-ids-to-filter-a-lucene-search">question</a> </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload