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

Feature: Search administration & Ontology and Agents search #70

Merged
merged 11 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ gem 'haml', '~> 5.2.2' # pin see https://github.com/ncbo/ontologies_api/pull/107
gem 'redcarpet'

# NCBO gems (can be from a local dev path or from rubygems/git)
gem 'goo', github: 'ontoportal-lirmm/goo', branch: 'development'
gem 'ncbo_annotator', git: 'https://github.com/ontoportal-lirmm/ncbo_annotator.git', branch: 'development'
gem 'ncbo_cron', git: 'https://github.com/ontoportal-lirmm/ncbo_cron.git', branch: 'master'
gem 'ncbo_ontology_recommender', git: 'https://github.com/ncbo/ncbo_ontology_recommender.git', branch: 'master'
gem 'sparql-client', github: 'ontoportal-lirmm/sparql-client', branch: 'master'
gem 'ontologies_linked_data', git: 'https://github.com/ontoportal-lirmm/ontologies_linked_data.git', branch: 'master'
gem 'goo', github: 'ontoportal-lirmm/goo', branch: 'development'
gem 'ontologies_linked_data', git: 'https://github.com/ontoportal-lirmm/ontologies_linked_data.git', branch: 'development'

group :development do
# bcrypt_pbkdf and ed35519 is required for capistrano deployments when using ed25519 keys; see https://github.com/miloserdow/capistrano-deploy/issues/42
Expand All @@ -77,5 +77,5 @@ group :test do
gem 'rack-test'
gem 'simplecov', require: false
gem 'simplecov-cobertura' # for codecov.io
gem 'webmock'
gem 'webmock', '~> 3.19.1'
end
32 changes: 17 additions & 15 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ GIT

GIT
remote: https://github.com/ontoportal-lirmm/goo.git
revision: 3f8b1f0b62c4334306f9ed5cb7b17a1b645e7db3
revision: 0e554fce49713ce4d5a742a06c2fb59a547caf47
branch: development
specs:
goo (0.0.2)
Expand Down Expand Up @@ -57,7 +57,7 @@ GIT

GIT
remote: https://github.com/ontoportal-lirmm/ontologies_linked_data.git
revision: 337dce98ec27627d14a440ff2a6ed09483cdac12
revision: 026c9c46baf6c0d638568528c2adcb7bcb1c2796
branch: development
specs:
ontologies_linked_data (0.0.1)
Expand Down Expand Up @@ -183,7 +183,7 @@ GEM
google-cloud-errors (~> 1.0)
google-apis-analytics_v3 (0.15.0)
google-apis-core (>= 0.14.0, < 2.a)
google-apis-core (0.14.0)
google-apis-core (0.14.1)
addressable (~> 2.5, >= 2.5.1)
googleauth (~> 1.9)
httpclient (>= 2.8.1, < 3.a)
Expand All @@ -203,7 +203,7 @@ GEM
google-protobuf (~> 3.18)
googleapis-common-protos-types (~> 1.7)
grpc (~> 1.41)
googleapis-common-protos-types (1.13.0)
googleapis-common-protos-types (1.14.0)
google-protobuf (~> 3.18)
googleauth (1.11.0)
faraday (>= 1.0, < 3.a)
Expand All @@ -229,13 +229,13 @@ GEM
httpclient (2.8.3)
i18n (0.9.5)
concurrent-ruby (~> 1.0)
json (2.7.1)
json (2.7.2)
json-ld (3.0.2)
multi_json (~> 1.12)
rdf (>= 2.2.8, < 4.0)
json-schema (2.8.1)
addressable (>= 2.4)
json_pure (2.7.1)
json_pure (2.7.2)
jwt (2.8.1)
base64
kgio (2.11.4)
Expand Down Expand Up @@ -273,11 +273,11 @@ GEM
net-ssh (>= 2.6.5, < 8.0.0)
net-sftp (4.0.0)
net-ssh (>= 5.0.0, < 8.0.0)
net-smtp (0.4.0.1)
net-smtp (0.5.0)
net-protocol
net-ssh (7.2.1)
net-ssh (7.2.3)
netrc (0.11.0)
newrelic_rpm (9.7.1)
newrelic_rpm (9.8.0)
oj (2.18.5)
omni_logger (0.1.4)
logger
Expand All @@ -289,7 +289,7 @@ GEM
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
public_suffix (5.0.4)
public_suffix (5.0.5)
rack (1.6.13)
rack-accept (0.4.5)
rack (>= 0.4)
Expand Down Expand Up @@ -346,7 +346,7 @@ GEM
netrc (~> 0.8)
retriable (3.1.2)
rexml (3.2.6)
rsolr (2.5.0)
rsolr (2.6.0)
builder (>= 2.1.2)
faraday (>= 0.9, < 3, != 2.0.0)
ruby-xxHash (0.4.0.2)
Expand Down Expand Up @@ -381,7 +381,8 @@ GEM
rack-test
sinatra (~> 1.4.0)
tilt (>= 1.3, < 3)
sshkit (1.22.0)
sshkit (1.22.1)
base64
mutex_m
net-scp (>= 1.1.2)
net-sftp (>= 2.1.2)
Expand All @@ -402,12 +403,13 @@ GEM
unicorn (>= 4, < 7)
uuid (2.3.9)
macaddr (~> 1.0)
webmock (3.23.0)
webmock (3.19.1)
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)

PLATFORMS
x86_64-darwin-23
x86_64-linux

DEPENDENCIES
Expand Down Expand Up @@ -463,7 +465,7 @@ DEPENDENCIES
sparql-client!
unicorn
unicorn-worker-killer
webmock
webmock (~> 3.19.1)

BUNDLED WITH
2.3.23
2.4.22
73 changes: 73 additions & 0 deletions controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,79 @@ class AdminController < ApplicationController
halt 204
end

namespace "/search" do
get '/collections' do
conn = SOLR::SolrConnector.new(Goo.search_conf, '')
collections = { collections: conn.fetch_all_collections}
reply(200, collections)
end

get '/collections/:collection/schema' do
collection = params[:collection].to_sym
conn = SOLR::SolrConnector.new(Goo.search_conf, collection)
collection_schema = conn.fetch_schema

reply(200, collection_schema)
end

post '/collections/:collection/schema/init' do
collection = params[:collection].to_sym
conn = SOLR::SolrConnector.new(Goo.search_conf, collection)
collection_schema = conn.init_schema
reply(200, collection_schema)
end


post '/collections/:collection/search' do
collection = params[:collection].to_sym

search_keys = %w[defType fq qf sort start rows fl stopwords lowercaseOperators]

search_params = params.select { |key, _| search_keys.include?(key) }
search_query = params[:query] || params[:q]
search_query = search_query.blank? ? '*' : search_query
conn = SOLR::SolrConnector.new(Goo.search_conf, collection)
reply(200, conn.search(search_query, search_params).to_h)
end

post '/index_batch/:model_name' do
error 500, "model_name parameter not set" if params["model_name"].blank?

model = Goo.model_by_name(params["model_name"].to_sym)
error 500, "#{params["model_name"]} is not indexable" if model.nil? || !model.index_enabled?

all_attrs = get_attributes_to_include([:all], model)

collections = model.where.include(all_attrs).all
indexed = []
not_indexed = []
collections.each do |m|
begin
response = m.index.dig("responseHeader", "status")
if response.eql?(0)
indexed << m.id
else
not_indexed << m.id
end
rescue StandardError
not_indexed << m.id
end
end

if !indexed.empty?
msg = "Batch indexing for #{model.model_name} completed for"

if not_indexed.empty?
msg += " all models"
else
msg += " #{indexed.join(', ')} and not for the following #{not_indexed.join(', ')}, see logs for more details"
end
reply(200, msg)
else
reply(500, "Batch indexing for #{model.model_name} failed")
end
end
end
private

def process_long_operation(timeout, args)
Expand Down
Loading
Loading