Skip to content

Commit f228cb4

Browse files
SRCH-6222 SRCH-6227 Create OpenSearch engine and OpenSearch index (#1867)
* feat: Add OpenSearch search engine * feat: Configure Open-Search client and index creation
1 parent 253d091 commit f228cb4

25 files changed

+325
-8
lines changed

.circleci/config.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ executors:
4141
xpack.security.enabled: false
4242
ES_JAVA_OPTS: "-Xms256m -Xmx256m"
4343

44+
- image: opensearchproject/opensearch:3
45+
environment:
46+
cluster.name: os-cluster
47+
discovery.type: single-node
48+
bootstrap.memory_lock: true
49+
http.port: 9300
50+
plugins.security.disabled: "true"
51+
OPENSEARCH_JAVA_OPTS: "-Xms256m -Xmx256m"
52+
OPENSEARCH_INITIAL_ADMIN_PASSWORD: S3venDr4gon!
53+
4454
- image: apache/tika:2.4.1
4555

4656
commands:

.env.development

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ ES_HOSTS="http://localhost:9200"
33
ES_CA_FINGERPRINT=FILL_THE_GENERATED_CA_FINGERPRINT
44
ES_USER=elastic
55
ES_PASSWORD=changeme
6+
OPENSEARCH_HOST=http://localhost:9300
7+
OPENSEARCH_INDEX=development-i14y-documents-searchgov
8+
OPENSEARCH_PASSWORD=S3venDr4gon!
9+
OPENSEARCH_USER=admin
610
REDIS_SYSTEM_URL=redis://localhost:6379
711
REDIS_PORT=6379
812
I14Y_DOCKER_HOST=http://i14y:3200

.env.test

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ ES_HOSTS="http://localhost:9200"
33
ES_CA_FINGERPRINT=FILL_THE_GENERATED_CA_FINGERPRINT
44
ES_USER=elastic
55
ES_PASSWORD=changeme
6+
OPENSEARCH_HOST=http://localhost:9300
7+
OPENSEARCH_INDEX=development-i14y-documents-searchgov
8+
OPENSEARCH_PASSWORD=S3venDr4gon!
9+
OPENSEARCH_USER=admin
610
REDIS_SYSTEM_URL=redis://localhost:6379
711
REDIS_PORT=6379
812
I14Y_DOCKER_HOST=http://i14y:3200

Gemfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ gem 'sass-rails', '~> 6.0'
5656
gem 'google_visualr',
5757
git: 'https://github.com/winston/google_visualr',
5858
ref: '17b97114a345baadd011e7b442b9a6c91a2b7ab5'
59-
gem 'faraday_middleware', '~> 0.14.0'
59+
gem 'faraday_middleware'
6060
gem 'net-http-persistent', '~> 2.9.3'
6161
gem 'rash_alt', '~> 0.4.12', require: 'rash'
6262
gem 'geoip', '~> 1.6.4'
@@ -77,6 +77,7 @@ gem 'elasticsearch', git: 'https://github.com/GSA/elasticsearch-ruby', branch: '
7777
gem 'elasticsearch-dsl', '~> 0.1.9'
7878
gem 'elasticsearch-xpack', '~> 7.4.0'
7979
gem "elasticsearch-persistence"
80+
gem 'opensearch-dsl'
8081
gem 'federal_register', '~> 0.6.3'
8182
gem 'redcarpet', '~> 3.6'
8283
gem 'google-api-client', '~> 0.53.0'

Gemfile.lock

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,7 @@ GEM
564564
actionpack (>= 4.2)
565565
omniauth (~> 2.0)
566566
open_uri_redirections (0.2.1)
567+
opensearch-dsl (0.2.1)
567568
os (1.1.4)
568569
ostruct (0.6.3)
569570
parallel (1.27.0)
@@ -811,10 +812,10 @@ GEM
811812
shoulda-matchers (>= 2.1.0)
812813
shoulda-matchers (5.3.0)
813814
activesupport (>= 5.2.0)
814-
signet (0.20.0)
815+
signet (0.21.0)
815816
addressable (~> 2.8)
816817
faraday (>= 0.17.5, < 3.a)
817-
jwt (>= 1.5, < 3.0)
818+
jwt (>= 1.5, < 4.0)
818819
multi_json (~> 1.10)
819820
simplecov (0.17.1)
820821
docile (~> 1.1)
@@ -951,7 +952,7 @@ DEPENDENCIES
951952
email_spec (~> 2.2)
952953
exception_notification (~> 4.5)
953954
faker (~> 1.8)
954-
faraday_middleware (~> 0.14.0)
955+
faraday_middleware
955956
federal_register (~> 0.6.3)
956957
feedjira (~> 3.2)
957958
flickraw (~> 0.9.9)
@@ -983,6 +984,7 @@ DEPENDENCIES
983984
omniauth (~> 2.1.0)
984985
omniauth-rails_csrf_protection (~> 1.0.1)
985986
omniauth_login_dot_gov!
987+
opensearch-dsl
986988
pry-byebug (~> 3.5)
987989
pry-rails (~> 0.3.6)
988990
puma (~> 5.6)

app/controllers/api/v2/searches_controller.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ def docs
4040
private
4141

4242
def selected_engine
43-
if @search_options.site.search_elastic_engine?
43+
case @search_options.site.search_engine
44+
when "open_search"
45+
OpenSearch::ApiEngine
46+
when "search_elastic"
4447
ApiSearchElastic
4548
else
4649
ApiI14ySearch

app/controllers/searches_controller.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ def advanced
7979
def pick_klass_vertical_template
8080
if get_commercial_results?
8181
[WebSearch, :web, :index]
82+
elsif @affiliate.open_search_engine?
83+
[OpenSearch::Engine, :SRCH, :i14y]
8284
elsif @affiliate.search_elastic_engine?
8385
[SearchElasticEngine, :SRCH, :i14y]
8486
elsif gets_i14y_results?

app/jobs/bulk_affiliate_search_engine_update_job.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class BulkAffiliateSearchEngineUpdateJob < ApplicationJob
44
queue_as :searchgov
55

6-
VALID_SEARCH_ENGINES = %w[bing_v7 search_gov search_elastic].freeze
6+
VALID_SEARCH_ENGINES = %w[bing_v7 search_gov search_elastic open_search].freeze
77

88
def perform(requesting_user_email, file_name, s3_object_key)
99
temp_file = download_from_s3(s3_object_key)
@@ -98,4 +98,4 @@ def log_parsing_failure(email, filename, results)
9898
Row Errors: #{results.error_details.count}.
9999
WARN
100100
end
101-
end
101+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# frozen_string_literal: true
2+
3+
class OpenSearch::ApiEngine < OpenSearch::Engine
4+
include ApiSearch
5+
6+
def as_json_result_hash(result)
7+
super.merge(thumbnail_url: result.thumbnail_url)
8+
end
9+
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
class OpenSearch::DocumentQuery < SearchElastic::DocumentQuery
4+
private
5+
6+
def parse_query(query)
7+
site_params_parser = OpenSearch::QueryParser.new(query)
8+
@site_filters = site_params_parser.site_filters
9+
@included_sites = @site_filters[:included_sites]
10+
@excluded_sites = @site_filters[:excluded_sites]
11+
@query = site_params_parser.stripped_query
12+
end
13+
end

0 commit comments

Comments
 (0)