Skip to content

Commit

Permalink
so much good stuff for static indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
epugh committed Sep 11, 2023
1 parent 8dcfe7b commit 5c7dbdd
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 9 deletions.
8 changes: 8 additions & 0 deletions app/assets/templates/views/devQueryParams.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ <h4 class="pull-left">Query Sandbox:</h4>


<div class='clearfix'></div>

<p ng-show="settings.searchEngine == 'snapshot'">
With a static (snapshot) search endpoint there are no query settings to play with ;-(.
</p>

<p ng-show="showQueryParamsWarning" id="query-params-warn" class="alert alert-warning" ng-bind-html="queryParamsWarning">{{ queryParamsWarning }}</p>

Expand Down Expand Up @@ -51,6 +55,10 @@ <h4 class="pull-left">Query Sandbox:</h4>
Define variables in your query template with <code>##</code>, such as this boost: <code>title^##titleBoost##</code>.
Play with the values in this tab. Submit to rerun with the new values!
</p>

<p ng-show="settings.searchEngine == 'snapshot'">
With a static (snapshot) search endpoint there are no tuning knobs to play with ;-(.
</p>

<h4>Tuning Knobs</h4>

Expand Down
23 changes: 21 additions & 2 deletions app/controllers/api/v1/snapshots/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ class SearchController < SnapshotsController
before_action :check_snapshot

# rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/CyclomaticComplexity
# rubocop:disable Metrics/PerceivedComplexity
def index
@q = params[:q]
query = if '*:*' == @q
Expand All @@ -30,14 +33,30 @@ def index
@snapshot_docs = []
end

rows = params[:rows]
rows = params[:rows].to_i if params[:rows]
start = params[:start].to_i if params[:start]

@number_found = @snapshot_docs.count
@snapshot_docs = @snapshot_docs.take rows if rows

if start && rows
end_index = rows + start
@snapshot_docs = @snapshot_docs[start...end_index]
elsif rows
@snapshot_docs = @snapshot_docs.take rows if rows
end

@solr_params = {
q: @q,
}
@solr_params[:rows] = params[:rows] if params[:rows]
@solr_params[:start] = params[:start] if params[:start]

respond_with @snapshot
end
# rubocop:enable Metrics/MethodLength
# rubocop:enable Metrics/AbcSize
# rubocop:enable Metrics/CyclomaticComplexity
# rubocop:enable Metrics/PerceivedComplexity

private

Expand Down
3 changes: 1 addition & 2 deletions app/controllers/api/v1/tries_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ def update
search_endpoint_params_to_use = search_endpoint_params
search_endpoint_params_to_use = convert_blank_values_to_nil search_endpoint_params_to_use
unless search_endpoint_params_to_use.empty?
puts 'Here are the params'
puts search_endpoint_params_to_use.except :name

# really hsould be a search_endpoint_id
search_endpoint = @current_user.search_endpoints_involved_with
.find_by search_endpoint_params_to_use.except :name
Expand Down
9 changes: 8 additions & 1 deletion app/models/try.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ def args
# return unless search_endpoint
unless search_endpoint.nil?
case search_endpoint.search_engine
when 'solr' || 'snapshot'
when 'solr'
solr_args
when 'snapshot'
snapshot_args
when 'es'
es_args
when 'os'
Expand Down Expand Up @@ -94,6 +96,11 @@ def os_args
EsArgParser.parse(query_params, curator_vars_map)
end

def snapshot_args
# Use the SolrArgParser as that is the only snapshot format we know
SolrArgParser.parse(query_params, curator_vars_map)
end

def id_from_field_spec
# logic is inspired by https://github.com/o19s/splainer-search/blob/main/services/fieldSpecSvc.js

Expand Down
4 changes: 1 addition & 3 deletions app/views/api/v1/snapshots/search/index.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ json.responseHeader do
json.status 2
json.QTime 0

json.params do
json.q @q
end
json.params @solr_params
end

json.response do
Expand Down
2 changes: 1 addition & 1 deletion app/views/ratings/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<h1 class="h2">Ratings for Case <%= @case.case_name %></h1>
<div class="btn-toolbar mb-2 mb-md-0">
<div class="btn-group me-2">
<%= link_to "Back to Case #{@case.case_name}", case_path(@case), class: "btn btn-sm btn-outline-secondary" %>
<%= link_to "Back to Case #{@case.case_name}", case_core_path(@case), class: "btn btn-sm btn-outline-secondary" %>
</div>
</div>
</div>
Expand Down
26 changes: 26 additions & 0 deletions test/controllers/api/v1/snapshots/search_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,32 @@ class SearchControllerTest < ActionController::TestCase
assert_equal 2, data['response']['numFound']
assert_equal rows, data['response']['docs'].length
end

test 'deals with pagination' do
snapshot_query = snapshot.snapshot_queries.first
query_text = snapshot_query.query.query_text
solr_params = {
q: query_text,
rows: 1,
start: 1,
}
params = {
case_id: acase.id, snapshot_id: snapshot.id
}
params = params.merge(solr_params)

get :index, params: params

assert_response :ok

data = response.parsed_body

assert_equal query_text, data['responseHeader']['params']['q']
assert_equal 2, data['response']['numFound']
assert_equal solr_params[:rows], data['response']['docs'].length

assert_equal data['responseHeader']['params'], solr_params.stringify_keys.transform_values(&:to_s)
end
end
end
end
Expand Down

0 comments on commit 5c7dbdd

Please sign in to comment.