Skip to content

Commit

Permalink
Tweak JsonPath initialization
Browse files Browse the repository at this point in the history
There is no reason we need to initialize a new set of JsonPath objects
for indexable content extraction every time a document is parsed - these
can just be transformed once in the constant.
  • Loading branch information
csutter committed Oct 6, 2023
1 parent 251174d commit c0141c8
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/document_sync_worker/document/publish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Document
class Publish < Base
# All the possible keys in the message hash that can contain unstructured content that we want
# to index, represented as JsonPath path strings.
INDEXABLE_CONTENT_VALUES_PATHS = %w[
INDEXABLE_CONTENT_VALUES_JSON_PATHS = %w[
$.details.body
$.details.contact_groups[*].title
$.details.description
Expand All @@ -17,7 +17,7 @@ class Publish < Base
$.details.parts[*]['title','body']
$.details.summary
$.details.title
].freeze
].map { JsonPath.new(_1) }.freeze
INDEXABLE_CONTENT_SEPARATOR = "\n".freeze

# Synchronize the document to the given repository (i.e. put it in the repository).
Expand All @@ -41,7 +41,7 @@ def metadata

# Extracts a single string of indexable unstructured content from the document.
def content
values = INDEXABLE_CONTENT_VALUES_PATHS.map { JsonPath.new(_1).on(document_hash) }
values = INDEXABLE_CONTENT_VALUES_JSON_PATHS.map { _1.on(document_hash) }
values.flatten.join(INDEXABLE_CONTENT_SEPARATOR)
end

Expand Down

0 comments on commit c0141c8

Please sign in to comment.