Hongli Lai
2007-Nov-04 18:22 UTC
[Ferret-talk] Searching different fields based on document permissions
I''m currently writing a system that stores user-created documents. Each user belongs to a specific group, and the system supports multiple groups. The thing is, my users want to be able to hide pieces of a document from other groups. So for example, lets say Joe of team A has written this document: "Hello all, our secret plan is finally complete! <private>We will begin our mission of world domination at 12:00 PM tomorrow.</private>" If Jane of team B views this document, she''ll only see the text: "Hello all, our secret plan is finally complete!" Only other people in team A will be able to see the original message. So each document essentially has two versions of contents: one without private information, and one with private information. My users were very specific about this feature and want it no matter what. But this poses a problem for searching. Is it possible to tell Ferret the following? - Search all documents with the given search terms, but: * Search in the field content_without_private_information if the document does not belong to team A. * Search in the field content_with_private_information if the document belongs to team A. I''ve taken a quick look at the tutorial, and I''ve purchased the Ferret book by O''Reilly. But so far I can''t seem to find anything that makes this possible. Is it possible at all? Or are there other possible alternatives?
Scott Davies
2007-Nov-05 00:39 UTC
[Ferret-talk] Searching different fields based on document permissions
It''s trivial if you construct your query tree manually, which you''ll probably have to do for your security purposes (as opposed to using one of the existing query parsers)...the first argument to TermQuery''s constructor is which field to search. On 11/4/07, Hongli Lai <hongli at plan99.net> wrote:> I''m currently writing a system that stores user-created documents. Each > user belongs to a specific group, and the system supports multiple > groups. The thing is, my users want to be able to hide pieces of a > document from other groups. So for example, lets say Joe of team A has > written this document: > "Hello all, our secret plan is finally complete! <private>We will > begin our mission of world domination at 12:00 PM tomorrow.</private>" > > If Jane of team B views this document, she''ll only see the text: > "Hello all, our secret plan is finally complete!" > Only other people in team A will be able to see the original message. > > So each document essentially has two versions of contents: one without > private information, and one with private information. > > My users were very specific about this feature and want it no matter > what. But this poses a problem for searching. Is it possible to tell > Ferret the following? > - Search all documents with the given search terms, but: > * Search in the field content_without_private_information if the > document does not belong to team A. > * Search in the field content_with_private_information if the > document belongs to team A. > > I''ve taken a quick look at the tutorial, and I''ve purchased the Ferret > book by O''Reilly. But so far I can''t seem to find anything that makes > this possible. Is it possible at all? Or are there other possible > alternatives? > _______________________________________________ > Ferret-talk mailing list > Ferret-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/ferret-talk >
Hongli Lai
2007-Nov-05 10:09 UTC
[Ferret-talk] Searching different fields based on document permissions
Scott Davies wrote:> It''s trivial if you construct your query tree manually, which you''ll > probably have to do for your security purposes (as opposed to using > one of the existing query parsers)...the first argument to TermQuery''s > constructor is which field to search.I found out that I''ll need a query that looks like this: "(group_id:#{group_id} AND private_content:#{search_term}) OR (public_content:#{search_term})" The query parser seems to generate a BooleanQuery at the top-level. I spent several hours reading the book and the API, but I could not find a way to generate ''OR'' boolean queries. The API only allows :must, :must_not and :should. How can I construct an OR query like the one above?
Jens Kraemer
2007-Nov-05 10:23 UTC
[Ferret-talk] Searching different fields based on document permissions
On Mon, Nov 05, 2007 at 11:09:28AM +0100, Hongli Lai wrote:> Scott Davies wrote: > > It''s trivial if you construct your query tree manually, which you''ll > > probably have to do for your security purposes (as opposed to using > > one of the existing query parsers)...the first argument to TermQuery''s > > constructor is which field to search. > > I found out that I''ll need a query that looks like this: > > "(group_id:#{group_id} AND private_content:#{search_term}) OR > (public_content:#{search_term})" > > The query parser seems to generate a BooleanQuery at the top-level. I > spent several hours reading the book and the API, but I could not find a > way to generate ''OR'' boolean queries. The API only allows :must, > :must_not and :should. How can I construct an OR query like the one above?Ferret by default creates OR queries so a query string like ''term1 term2'' means the same as ''term1 OR term2'' . Using the API, :should is the correct modifier to create ORed boolean clauses. Jens -- Jens Kr?mer http://www.jkraemer.net/ - Blog http://www.omdb.org/ - The new free film database