Skip to content

Commit a572967

Browse files
committed
add experimental support for ignored allowed groups
1 parent d046b0e commit a572967

File tree

6 files changed

+41
-5
lines changed

6 files changed

+41
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# Changelog
2+
## Unreleased
3+
**Features**
4+
- added ignored groups: groups that should not be taken into account when searching
5+
26
## v0.10.0
37
**Fixes**
48
- [#92](https://github.com/mu-semtech/mu-search/issues/92) fix restoring update-handler if file exceeds 3MB

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,10 @@ Assume your application contains a company-specific user group in the authorizat
787787

788788
A typical group to be specified as a single `eager_indexing_group` is `{ "variables": [], "name": "clean" }`. The index will not contain any data, but will be used in the combination to fully match the user's allowed groups.
789789

790+
#### [EXPERIMENTAL] Ignoring allowed groups
791+
In some cases you may search to ignore certain allowed groups when looking for matching indexes. Typically because they will not relate to data that has to be indexed and you want to avoid having many empty indexes. In this case you will have to provide an entry in the `ignored_allowed_groups` list for each group, currently this means including each possible variable value.
792+
For example the clean group can be added to `ignored_allowed_groups` by adding `{ "variables": [], "name": "clean" }` to the list.
793+
790794
### Delta integration
791795
Mu-search integrates with the delta's generated by [mu-authorization](https://github.com/mu-semtech/mu-authorization) and dispatched by the [delta-notifier](https://github.com/mu-semtech/delta-notifier).
792796

config/config.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
"automatic_index_updates" : true,
55
"eager_indexing_groups" : [[{"name" : "documents", "variables" : ["human"]}],
66
[{"name" : "documents", "variables" : ["chicken"]}]],
7+
"ignored_allowed_groups": [
8+
{ "variables": [], "name": "clean" }
9+
],
710
"attachments_path_base" : "/local/files/directory",
811
"persist_indexes" : false,
912
"default_settings" : {

lib/mu_search/config_parser.rb

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def self.parse(path)
4747
if json_config["eager_indexing_groups"]
4848
config[:eager_indexing_groups] = json_config["eager_indexing_groups"]
4949
end
50-
50+
config[:ignored_allowed_groups] = json_config["ignored_allowed_groups"] || []
5151
config[:type_definitions] = Hash[MuSearch::IndexDefinition.from_json_config(json_config["types"])]
5252
config
5353
end
@@ -117,12 +117,33 @@ def self.validate_config(json_config)
117117
else
118118
errors << "no type definitions specified, expected field 'types' not found"
119119
end
120+
if json_config.has_key?("ignored_allowed_groups")
121+
errors = errors.concat(self.validate_ignored_allowed_groups(json_config["ignored_allowed_groups"]))
122+
end
120123
if errors.length > 0
121124
Mu::log.error("CONFIG_PARSER") { errors.join("\n") }
122125
raise "invalid config"
123126
end
124127
end
125128

129+
def self.validate_ignored_allowed_groups(groups)
130+
errors = []
131+
if ! groups.kind_of?(Array)
132+
errors << "ignored_allowed_groups should be an array"
133+
else
134+
groups.each do |group|
135+
if ! group.kind_of?(Hash)
136+
errors << "ignored_allowed_group is not an object: #{group.inspect}"
137+
else
138+
if ! group.has_key?("name") && group.has_key?("variables")
139+
errors << "ignored_allowed_group should have both name and variables set: #{group.inspect}"
140+
end
141+
end
142+
end
143+
end
144+
errors
145+
end
146+
126147
##
127148
# basic validations of typedefinitions
128149
#

lib/mu_search/index_manager.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module MuSearch
88
# - triplestore
99
###
1010
class IndexManager
11-
attr_reader :indexes
11+
attr_reader :indexes, :ignored_allowed_groups
1212

1313
def initialize(logger:, elasticsearch:, tika:, sparql_connection_pool:, search_configuration:)
1414
@logger = logger
@@ -18,7 +18,7 @@ def initialize(logger:, elasticsearch:, tika:, sparql_connection_pool:, search_c
1818
@master_mutex = Mutex.new
1919
@configuration = search_configuration
2020
@indexes = {} # indexes per type
21-
21+
@ignored_allowed_groups = search_configuration[:ignored_allowed_groups]
2222
initialize_indexes
2323
end
2424

@@ -200,7 +200,10 @@ def find_single_index_for_groups(type_name, allowed_groups, used_groups = [])
200200
# TODO take used_groups into account when they are supported by mu-authorization
201201
def ensure_index_combination_for_groups(type_name, allowed_groups, used_groups = [])
202202
@logger.debug("INDEX MGMT") { "Trying to combine indexes in cache for type '#{type_name}' to match allowed_groups #{allowed_groups} and used_groups #{used_groups}" }
203-
203+
if !ignored_allowed_groups.empty?
204+
@logger.debug("INDEX MGMT") { "Ignoring the following allowed groups: #{ignored_allowed_groups.inspect}" }
205+
allowed_groups.reject!{ |ag| ignored_allowed_groups.include? ag }
206+
end
204207
indexes = @indexes[type_name].values.find_all(&:eager_index?)
205208
@logger.debug("INDEX MGMT") { "Currently known indexes for type '#{type_name}': #{indexes.map(&:allowed_groups).to_json}" }
206209
# Find all indexes with allowed_groups that are a subset of the given allowed_groups

web.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ def setup_index_manager(elasticsearch, tika, sparql_connection_pool, config)
5252
search_configuration = config.select do |key|
5353
[:type_definitions, :default_index_settings,
5454
:persist_indexes, :eager_indexing_groups, :number_of_threads,
55-
:batch_size, :max_batches, :attachment_path_base].include? key
55+
:batch_size, :max_batches, :attachment_path_base,
56+
:ignored_allowed_groups].include? key
5657
end
5758

5859
MuSearch::IndexManager.new(

0 commit comments

Comments
 (0)