0

I have a group index. A group has two privacy types, public and private. A private group is associated with an access code. In the search result a private group should only be included if user has the access code associated to it. Previously private groups did not show in the search result, so I had one simple query !privacy_type:private.

But now I have to include the private groups if user has the access code for that group (User can have multiple access codes and we have to include groups with those access codes). How to use conditional filter like this?

Sayantan Das
  • 1,619
  • 4
  • 24
  • 43
  • So how do you know if the group matches the access code? How do you decide that a user has explicit access to the group? – MatsLindh May 30 '18 at 07:48
  • @MatsLindh I am storing the access code related to group in the group document. And I can get the list of codes user has applied. – Sayantan Das May 30 '18 at 07:51
  • Are access codes unique? How many access codes does a user have applied at max? (i.e. can you do `fq=privacy_type:public OR access_code:(access_code_1 access_code_2 access_code_3)`)? – MatsLindh May 30 '18 at 08:01
  • @MatsLindh Multiple groups can have same access code. Although there is no limit on the number of access code user can have, we don't hope it would be too many. – Sayantan Das May 30 '18 at 08:05
  • But the user has access to all the groups with the same access_code? In that case what I typed above should work (and by default Solr is configured to allow at least 1000 boolean terms in a query) – MatsLindh May 30 '18 at 08:06
  • yes. user would have access to all the groups with the access code. Let me implement that. Thank you for your time. :) – Sayantan Das May 30 '18 at 08:08
  • @MatsLindh, thanks a lot man. You are awesome. – Sayantan Das May 30 '18 at 08:14

1 Answers1

3

As long as there aren't multiple groups with the same access_code and they should behave differently (i.e. if for an access_code all groups with that access_code should be returned):

fq=privacy_type:public OR access_code:(access_code_1 access_code_2 access_code_3)

You can also explicitly tell Solr to OR each statement inside the access_code list - access_code:(access_code_1 OR access_code_2 OR ...), but you should be able to drop it in this case.

Solr has a default maximum number of boolean clauses as 1000, so as long as the number of access groups per user is lower than that, this should work fine.

MatsLindh
  • 49,529
  • 4
  • 53
  • 84
  • 1
    Terms Query Parser may be a slight improvement on the example above and also allow more access groups: https://lucene.apache.org/solr/guide/7_3/other-parsers.html#OtherParsers-TermsQueryParser – Alexandre Rafalovitch May 31 '18 at 11:58