~1500 files./records ├── 8-Ball.json ├── Abdul_Alhazred.json ├── Abigail_Brand.json ├── […] ├── Zombie.json ├── Zom.json └── Zzzax.json
{
"name": "Iron Man",
"secretIdentity": "Tony Stark",
"description": "Wounded, captured and forced to […]",
"powers": ["Energy repulsors", […], "Super strength"],
"teams": ["Avengers", […], "Stark Industries"],
"adventureCount": 2903
[…]
}
require 'algoliasearch'
# Init Algolia index
Algolia.init(
application_id: 'O3F8QXYK6R',
api_key: '476071478e45b023b7ff7d8ba8'
)
index = Algolia::Index.new('marvel')
# Read files from disk
records = Dir.glob("./records/*.json").map { |file| JSON.parse(File.read(file)) }
# Push records to index
records.each_slice(500) do |batch|
index.add_objects!(batch.to_a)
end
index.set_settings!(
searchableAttributes: [
'name',
'secretIdentity',
'description'
],
customRanking: [
'desc(adventureCount)'
],
attributesForFaceting: [
'powers',
'team'
]
)