Skip to content

Commit

Permalink
Merge pull request #84 from akretion/v4.0.x-fix-sitemap-with-broken-r…
Browse files Browse the repository at this point in the history
…ecord

Skip item that do not have url_key
  • Loading branch information
sebastienbeau authored Jun 11, 2024
2 parents 5ed2075 + 135c855 commit bdae530
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/shop_invader/services/elastic_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,19 @@ def find_all_products_and_categories
# first search which also returns _scroll_id
result['hits']['hits'].each do |hit|
record = records[hit['_id']] ||= {}
record[locale] = { name: hit['_source']['name'], url: find_route(config['name']).gsub('*', hit['_source']['url_key']) }
if hit['_source']['url_key']
record[locale] = { name: hit['_source']['name'], url: find_route(config['name']).gsub('*', hit['_source']['url_key']) }
end
end

# Uses the `scroll` API until empty results are returned
# https://www.elastic.co/guide/en/elasticsearch/reference/6.6/search-request-scroll.html
while result = @client.scroll(body: { scroll_id: result['_scroll_id'] }, scroll: '5m') and not result['hits']['hits'].empty? do
result['hits']['hits'].each do |hit|
record = records[hit['_id']] ||= {}
record[locale] = { name: hit['_source']['name'], url: find_route(config['name']).gsub('*', hit['_source']['url_key']) }
if hit['_source']['url_key']
record[locale] = { name: hit['_source']['name'], url: find_route(config['name']).gsub('*', hit['_source']['url_key']) }
end
end
end
end
Expand Down

0 comments on commit bdae530

Please sign in to comment.