Skip to content

Commit

Permalink
optimize the json search action
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Jan 1, 2024
1 parent 5acbea7 commit 008b875
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
26 changes: 12 additions & 14 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ GEM
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
chart-js-rails (0.1.7)
railties (> 3.1)
coderay (1.1.3)
concurrent-ruby (1.2.2)
crass (1.0.6)
Expand All @@ -146,7 +144,7 @@ GEM
daemons (1.4.1)
dalli (3.2.6)
date (3.3.4)
debug (1.9.0)
debug (1.9.1)
irb (~> 1.10)
reline (>= 0.3.8)
deepl-rb (2.5.3)
Expand Down Expand Up @@ -176,7 +174,7 @@ GEM
flamegraph (0.9.5)
globalid (1.2.1)
activesupport (>= 6.1)
graphql (2.2.0)
graphql (2.2.3)
racc (~> 1.4)
graphql-client (0.18.0)
activesupport (>= 3.0)
Expand Down Expand Up @@ -218,7 +216,7 @@ GEM
activesupport (>= 3.0)
nokogiri (>= 1.6)
io-console (0.7.1)
irb (1.10.1)
irb (1.11.0)
rdoc
reline (>= 0.3.8)
iso-639 (0.3.6)
Expand All @@ -231,7 +229,7 @@ GEM
jsbundling-rails (1.2.1)
railties (>= 6.0.0)
json (2.7.1)
json-jwt (1.16.3)
json-jwt (1.16.4)
activesupport (>= 4.2)
aes_key_wrap
bindata
Expand Down Expand Up @@ -285,13 +283,14 @@ GEM
multi_json (1.15.0)
multi_xml (0.6.0)
multipart-post (2.3.0)
mutex_m (0.2.0)
mysql2 (0.5.5)
net-ftp (0.2.0)
net-protocol
time
net-http (0.3.2)
uri
net-imap (0.4.8)
net-imap (0.4.9)
date
net-protocol
net-pop (0.1.2)
Expand All @@ -302,7 +301,7 @@ GEM
net-ssh (>= 2.6.5, < 8.0.0)
net-smtp (0.4.0)
net-protocol
net-ssh (7.2.0)
net-ssh (7.2.1)
netrc (0.11.0)
newrelic_rpm (9.6.0)
base64
Expand All @@ -319,7 +318,7 @@ GEM
rack (>= 1.2, < 4)
oj (3.16.3)
bigdecimal (>= 3.0)
omniauth (2.1.1)
omniauth (2.1.2)
hashie (>= 3.4.6)
rack (>= 2.2.3)
rack-protection
Expand Down Expand Up @@ -364,7 +363,8 @@ GEM
rack (>= 0.4)
rack-mini-profiler (3.3.0)
rack (>= 1.2.0)
rack-protection (3.1.0)
rack-protection (3.2.0)
base64 (>= 0.1.0)
rack (~> 2.2, >= 2.2.4)
rack-test (2.1.0)
rack (>= 1.3)
Expand Down Expand Up @@ -468,7 +468,6 @@ GEM
sprockets (> 3.0)
sprockets-rails
tilt
select2-rails (4.0.13)
selenium-webdriver (4.9.0)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
Expand All @@ -492,7 +491,8 @@ GEM
actionpack (>= 5.2)
activesupport (>= 5.2)
sprockets (>= 3.0.0)
sshkit (1.21.6)
sshkit (1.21.7)
mutex_m
net-scp (>= 1.1.2)
net-ssh (>= 2.8.0)
stackprof (0.2.25)
Expand Down Expand Up @@ -560,7 +560,6 @@ DEPENDENCIES
capistrano-rails (~> 1.4)
capistrano-yarn
capybara
chart-js-rails
cube-ruby
dalli
debug
Expand Down Expand Up @@ -610,7 +609,6 @@ DEPENDENCIES
rspec-rails
rubocop
sassc-rails
select2-rails
selenium-webdriver
simplecov
simplecov-cobertura
Expand Down
14 changes: 10 additions & 4 deletions app/controllers/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@ def json_search
end
check_params_query(params)
check_params_ontologies(params) # Filter on ontology_id
if params["id"]&.eql?('All')
params.delete("id")
params.delete("ontologies")
end
search_page = LinkedData::Client::Models::Class.search(params[:q], params)
@results = search_page.collection

response = ""
obsolete_response = ""
separator = (params[:separator].nil?) ? "~!~" : params[:separator]
for result in @results

for result in Array(@results)
# TODO_REV: Format the response with type information, target information
# record_type = format_record_type(result[:recordType], result[:obsolete])
record_type = ""
Expand All @@ -40,12 +45,13 @@ def json_search
target_value = result.id
end

acronym = result.links["ontology"].split('/').last
json = []
json << "#{target_value}"
json << " [obsolete]" if result.obsolete? # used by JS in ontologies/visualize to markup obsolete classes
json << "|#{result.id}"
json << "|#{record_type}"
json << "|#{result.explore.ontology.acronym}"
json << "|#{acronym}"
json << "|#{result.id}" # Duplicated because we used to have shortId and fullId
json << "|#{target_value}"
# This is nasty, but hard to workaround unless we rewrite everything (form_autocomplete, jump_to, crossdomain_autocomplete)
Expand All @@ -55,8 +61,8 @@ def json_search
if params[:id] && params[:id].split(",").length == 1
json << "|#{CGI.escape((result.definition || []).join(". "))}#{separator}"
else
json << "|#{result.explore.ontology.name}"
json << "|#{result.explore.ontology.acronym}"
json << "|#{acronym}"
json << "|#{acronym}"
json << "|#{CGI.escape((result.definition || []).join(". "))}#{separator}"
end

Expand Down

0 comments on commit 008b875

Please sign in to comment.