Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Add filters patterns to select variables to resolve empty pagination #34

Merged
merged 1 commit into from
Apr 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions lib/goo/sparql/query_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,12 @@ def build_select_query(ids, variables, graphs, patterns,
@order_by, variables, optional_patterns = init_order_by(@count, @klass, @order_by, optional_patterns, variables)
variables, patterns = add_some_type_to_id(patterns, query_options, variables)

query_filter_str, patterns, optional_patterns =
query_filter_str, patterns, optional_patterns, filter_variables =
filter_query_strings(@collection, graphs, internal_variables, @klass, optional_patterns, patterns, @query_filters)

variables = [] if @count
variables.delete :some_type

select_distinct(variables, aggregate_projections)
select_distinct(variables, aggregate_projections, filter_variables)
.from(graphs)
.where(patterns)
.union_bind_in_where(properties_to_include)
Expand Down Expand Up @@ -135,10 +134,10 @@ def from(graphs)
self
end

def select_distinct(variables, aggregate_projections)

def select_distinct(variables, aggregate_projections, filter_variables)
select_vars = variables.dup
reject_aggregations_from_vars(select_vars, aggregate_projections) if aggregate_projections
select_vars = (select_vars + filter_variables).uniq if @page # Fix for 4store pagination with a filter
@query = @query.select(*select_vars).distinct(true)
self
end
Expand Down Expand Up @@ -347,8 +346,8 @@ def filter_query_strings(collection, graphs, internal_variables, klass,
optional_patterns, patterns,
query_filters)
query_filter_str = []

filter_graphs = []
filter_variables = []
inspected_patterns = {}
query_filters&.each do |query_filter|
filter_operations = []
Expand All @@ -365,9 +364,9 @@ def filter_query_strings(collection, graphs, internal_variables, klass,
patterns.concat(filter_patterns)
end
end
filter_variables << inspected_patterns.values.last
end

[query_filter_str, patterns, optional_patterns, internal_variables]
[query_filter_str, patterns, optional_patterns, filter_variables]
end

def reject_aggregations_from_vars(variables, aggregate_projections)
Expand Down