Class: SiteSearch::RetrieveDocuments

Inherits:
BaseService
  • Object
show all
Defined in:
app/services/site_search/retrieve_documents.rb

Overview

Example of how you can use the swiftype API to retrieve and interact with the search documents
This class requires the addition of gem 'elastic-site-search' in gemfile

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ RetrieveDocuments

Returns a new instance of RetrieveDocuments.



7
8
9
10
# File 'app/services/site_search/retrieve_documents.rb', line 7

def initialize(options={})
  @client = Elastic::SiteSearch::Client.new
  super
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



5
6
7
# File 'app/services/site_search/retrieve_documents.rb', line 5

def client
  @client
end

Instance Method Details

#process(options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/services/site_search/retrieve_documents.rb', line 12

def process(options={})

  documents = []
  page = 1
  loop do
    #r = client.documents('warmlyyours-us','page', page, 200)
    r = client.search_document_type('warmlyyours-us','page', 'reviews', { 'page': page, 'per_page': 200 })
    puts "Pulling page #{page} with result size #{r['page'].size}"
    documents += r['page']
    break if (r['page'].empty?) # r['page'] max pagination
    page += 1
  end
  documents
end

#remove_reviewsObject



27
28
29
30
31
32
33
34
35
36
# File 'app/services/site_search/retrieve_documents.rb', line 27

def remove_reviews
  r = process
  review_pages = r.select{|r| r['url'] =~ /\/reviews\z/ }.map{|r| r['external_id']}
  if review_pages.present?
    puts "destroying #{review_pages.size}"
    #client.destroy_documents('warmlyyours-us','page',review_pages)
  else
    puts "No review_pages found"
  end
end