Skip to content

Commit

Permalink
add search administration endpoints to init schema and index batch
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Feb 16, 2024
1 parent 1ab56c0 commit 5f319b7
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
18 changes: 9 additions & 9 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: a74645bbe5f801b64839f4f38461a456b3b90fc5
revision: ec99ed8d742fc8d458911cb0e74fa23d31cdd158
branch: feature/add-model-based-search
specs:
goo (0.0.2)
Expand Down Expand Up @@ -54,7 +54,7 @@ GIT

GIT
remote: https://github.com/ontoportal-lirmm/ontologies_linked_data.git
revision: aa39d724c26c7fad30866c5a343c040d029f094a
revision: 00d321a32d10acf6d659ef2aa9a305141b181cac
branch: feature/index-ontology-agent-metadata
specs:
ontologies_linked_data (0.0.1)
Expand Down Expand Up @@ -127,7 +127,7 @@ GEM
sshkit (~> 1.3)
coderay (1.1.3)
concurrent-ruby (1.2.3)
crack (0.4.6)
crack (1.0.0)
bigdecimal
rexml
cube-ruby (0.0.3)
Expand Down Expand Up @@ -193,15 +193,15 @@ GEM
google-cloud-env (2.1.1)
faraday (>= 1.0, < 3.a)
google-cloud-errors (1.3.1)
google-protobuf (3.25.2-x86_64-darwin)
google-protobuf (3.25.2-x86_64-linux)
google-protobuf (3.25.3-x86_64-darwin)
google-protobuf (3.25.3-x86_64-linux)
googleapis-common-protos (1.4.0)
google-protobuf (~> 3.14)
googleapis-common-protos-types (~> 1.2)
grpc (~> 1.27)
googleapis-common-protos-types (1.11.0)
googleapis-common-protos-types (1.12.0)
google-protobuf (~> 3.18)
googleauth (1.10.0)
googleauth (1.11.0)
faraday (>= 1.0, < 3.a)
google-cloud-env (~> 2.1)
jwt (>= 1.4, < 3.0)
Expand Down Expand Up @@ -288,7 +288,7 @@ GEM
rack (>= 0.4)
rack-cors (1.0.6)
rack (>= 1.6.0)
rack-mini-profiler (3.3.0)
rack-mini-profiler (3.3.1)
rack (>= 1.2.0)
rack-protection (1.5.5)
rack
Expand Down Expand Up @@ -330,7 +330,7 @@ GEM
rubyzip (2.3.2)
rufus-scheduler (2.0.24)
tzinfo (>= 0.3.22)
signet (0.18.0)
signet (0.19.0)
addressable (~> 2.8)
faraday (>= 0.17.5, < 3.a)
jwt (>= 1.5, < 3.0)
Expand Down
38 changes: 38 additions & 0 deletions controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,44 @@ class AdminController < ApplicationController
halt 204
end

namespace "/search" do
get '/collections' do
collections = { collections: Goo.search_connections.keys.map(&:to_s)}
reply(200, collections)
end

get '/collections/:collection/schema' do
collection = params[:collection].to_sym
collection_schema = Goo.search_connections[collection].fetch_schema

reply(200, collection_schema)
end

post '/collections/:collection/schema/init' do
collection = params[:collection].to_sym
collection_schema = Goo.search_connections[collection].init_schema
reply(200, collection_schema)
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)

collection = model.where.include(all_attrs).all

response = model.indexBatch(collection).dig("responseHeader", "status")

if response.eql?(0)
reply(200, "Batch indexing for #{model.model_name} complete")
else
reply(500, "Batch indexing for #{model.model_name} failed: #{response}")
end
end
end
private

def process_long_operation(timeout, args)
Expand Down

0 comments on commit 5f319b7

Please sign in to comment.