Class: S3arch::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/s3arch/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/s3arch/configuration.rb', line 45

def initialize
  @owner_key = 'user_id'
  @searchable_fields = %w[name description]
  @token_field = 'searchTokens'
  @metadata_fields = %w[status created_at]
  @record_filter = ->(_record) { true }
  @filter_fields = %w[status]
  @owner_extractor = lambda { |stream_record|
    image = stream_record.dig('dynamodb', 'NewImage') || stream_record.dig('dynamodb', 'OldImage') || {}
    image.dig(owner_key, 'S')
  }
  @version_ttl = 30
  @max_results = 50
  @max_cached_dbs = 20
  @ephemeral_storage_mb = 2048
  @logger = nil
end

Instance Attribute Details

#ephemeral_storage_mbObject

Searcher settings



43
44
45
# File 'lib/s3arch/configuration.rb', line 43

def ephemeral_storage_mb
  @ephemeral_storage_mb
end

#filter_fieldsObject

Fields needed by the record_filter for projection (e.g., %w)



34
35
36
# File 'lib/s3arch/configuration.rb', line 34

def filter_fields
  @filter_fields
end

#index_bucketObject

S3 bucket for storing SQLite index files



15
16
17
# File 'lib/s3arch/configuration.rb', line 15

def index_bucket
  @index_bucket
end

#loggerObject

Logger (defaults to $stdout)



40
41
42
# File 'lib/s3arch/configuration.rb', line 40

def logger
  @logger
end

#max_cached_dbsObject

Searcher settings



43
44
45
# File 'lib/s3arch/configuration.rb', line 43

def max_cached_dbs
  @max_cached_dbs
end

#max_resultsObject

Searcher settings



43
44
45
# File 'lib/s3arch/configuration.rb', line 43

def max_results
  @max_results
end

#metadata_fieldsObject

Metadata fields stored alongside FTS5 for filtering (not searched)



28
29
30
# File 'lib/s3arch/configuration.rb', line 28

def 
  @metadata_fields
end

#owner_extractorObject

Owner extractor — proc that extracts owner_id from a DynamoDB stream record



37
38
39
# File 'lib/s3arch/configuration.rb', line 37

def owner_extractor
  @owner_extractor
end

#owner_keyObject

Partition key field on the source table for owner lookup



12
13
14
# File 'lib/s3arch/configuration.rb', line 12

def owner_key
  @owner_key
end

#record_filterObject

Filter proc — receives a record hash, returns true to include in index



31
32
33
# File 'lib/s3arch/configuration.rb', line 31

def record_filter
  @record_filter
end

#searchable_fieldsObject

FTS5 searchable fields — array of field names from the source record



21
22
23
# File 'lib/s3arch/configuration.rb', line 21

def searchable_fields
  @searchable_fields
end

#source_indexObject

DynamoDB index to query records by owner (e.g., ‘UserIndex’)



9
10
11
# File 'lib/s3arch/configuration.rb', line 9

def source_index
  @source_index
end

#source_tableObject

DynamoDB table that contains the source records to index



6
7
8
# File 'lib/s3arch/configuration.rb', line 6

def source_table
  @source_table
end

#token_fieldObject

DynamoDB attribute name where pre-computed tokens are stored (Map type) e.g., { “searchTokens”: { “name”: “blue jacket”, “description”: “warm winter coat” } }



25
26
27
# File 'lib/s3arch/configuration.rb', line 25

def token_field
  @token_field
end

#version_tableObject

DynamoDB table for version tracking



18
19
20
# File 'lib/s3arch/configuration.rb', line 18

def version_table
  @version_table
end

#version_ttlObject

Searcher settings



43
44
45
# File 'lib/s3arch/configuration.rb', line 43

def version_ttl
  @version_ttl
end

Instance Method Details

#from_env!Object

Convenience: env-based configuration (reads from Lambda environment variables)



64
65
66
67
68
69
70
# File 'lib/s3arch/configuration.rb', line 64

def from_env!
  @source_table = ENV['S3ARCH_SOURCE_TABLE'] || ENV.fetch('INVENTORY_TABLE', nil)
  @source_index = ENV['S3ARCH_SOURCE_INDEX'] || 'UserIndex'
  @index_bucket = ENV['S3ARCH_INDEX_BUCKET'] || ENV.fetch('SEARCH_INDEX_BUCKET', nil)
  @version_table = ENV['S3ARCH_VERSION_TABLE'] || ENV.fetch('SEARCH_INDEX_TABLE', nil)
  self
end

#validate!Object

Raises:



72
73
74
75
76
77
78
79
# File 'lib/s3arch/configuration.rb', line 72

def validate!
  missing = []
  missing << 'source_table' unless source_table
  missing << 'index_bucket' unless index_bucket
  missing << 'version_table' unless version_table
  missing << 'source_index' unless source_index
  raise Error, "S3arch configuration missing: #{missing.join(', ')}" if missing.any?
end