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

Fix searchkick mappings for metadata #870

Merged
merged 3 commits into from
Dec 13, 2024
Merged
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
51 changes: 48 additions & 3 deletions app/models/sample.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

# entity class for Sample
class Sample < ApplicationRecord
class Sample < ApplicationRecord # rubocop:disable Metrics/ClassLength
include MetadataSortable
include HasPuid
include History
Expand All @@ -12,6 +12,51 @@ class Sample < ApplicationRecord
acts_as_paranoid

searchkick \
merge_mappings: true,
mappings: {
dynamic_templates: [
{
string_template: {
match: '*',
match_mapping_type: 'string',
mapping: {
fields: {
analyzed: {
analyzer: 'searchkick_index',
index: true,
type: 'text'
}
},
ignore_above: 30_000,
type: 'keyword'
}
}
},
{
metadata_dates: {
path_match: 'metadata.*_date',
mapping: {
type: 'date',
ignore_malformed: true
}
}
}, {
metadata_non_dates: {
path_match: 'metadata.*',
path_unmatch: 'metadata.*_date',
mapping: {
type: 'text',
fields: {
numeric: {
type: 'double',
ignore_malformed: true
}
}
}
}
}
]
},
deep_paging: true,
text_middle: %i[name puid]

Expand Down Expand Up @@ -91,11 +136,11 @@ def search_data
name: name,
puid: puid,
project_id: project_id,
metadata: metadata.as_json,
metadata: metadata.transform_keys { |k| k.gsub('.', '___') },
created_at: created_at,
updated_at: updated_at,
attachments_updated_at: attachments_updated_at
}
}.compact
end

def should_index?
Expand Down
Loading