Giter Site home page Giter Site logo

algoliasearch-rails's Introduction

Algolia for Rails

The perfect starting point to integrate Algolia within your Rails project

CircleCI Gem Version Code Climate ActiveRecord Mongoid Sequel

DocumentationCommunity ForumStack OverflowReport a bugFAQSupport

This gem let you easily integrate the Algolia Search API to your favorite ORM. It's based on the algoliasearch-client-ruby gem. Rails 5.x and 6.x are supported.

You might be interested in the sample Ruby on Rails application providing a autocomplete.js-based auto-completion and InstantSearch.js-based instant search results page: algoliasearch-rails-example.

API Documentation

You can find the full reference on Algolia's website.

  1. Setup

  2. Usage

  3. Options

  4. Indices

  5. Testing

  6. Troubleshooting

Setup

Install

gem install algoliasearch-rails

Add the gem to your Gemfile:

gem "algoliasearch-rails"

And run:

bundle install

Configuration

Create a new file config/initializers/algoliasearch.rb to setup your APPLICATION_ID and API_KEY.

AlgoliaSearch.configuration = { application_id: 'YourApplicationID', api_key: 'YourAPIKey' }

The gem is compatible with ActiveRecord, Mongoid and Sequel.

Timeouts

You can configure a various timeout thresholds by setting the following options at initialization time:

AlgoliaSearch.configuration = {
  application_id: 'YourApplicationID',
  api_key: 'YourAPIKey',
  connect_timeout: 2,
  receive_timeout: 30,
  send_timeout: 30,
  batch_timeout: 120,
  search_timeout: 5
}

Notes

This gem makes extensive use of Rails' callbacks to trigger the indexing tasks. If you're using methods bypassing after_validation, before_save or after_commit callbacks, it will not index your changes. For example: update_attribute doesn't perform validations checks, to perform validations when updating use update_attributes.

All methods injected by the AlgoliaSearch module are prefixed by algolia_ and aliased to the associated short names if they aren't already defined.

Contact.algolia_reindex! # <=> Contact.reindex!

Contact.algolia_search("jon doe") # <=> Contact.search("jon doe")

Usage

Index Schema

The following code will create a Contact index and add search capabilities to your Contact model:

class Contact < ActiveRecord::Base
  include AlgoliaSearch

  algoliasearch do
    attributes :first_name, :last_name, :email
  end
end

You can either specify the attributes to send (here we restricted to :first_name, :last_name, :email) or not (in that case, all attributes are sent).

class Product < ActiveRecord::Base
  include AlgoliaSearch

  algoliasearch do
    # all attributes will be sent
  end
end

You can also use the add_attribute method, to send all model attributes + extra ones:

class Product < ActiveRecord::Base
  include AlgoliaSearch

  algoliasearch do
    # all attributes + extra_attr will be sent
    add_attribute :extra_attr
  end

  def extra_attr
    "extra_val"
  end
end

Relevancy

We provide many ways to configure your index allowing you to tune your overall index relevancy. The most important ones are the searchable attributes and the attributes reflecting record popularity.

class Product < ActiveRecord::Base
  include AlgoliaSearch

  algoliasearch do
    # list of attribute used to build an Algolia record
    attributes :title, :subtitle, :description, :likes_count, :seller_name

    # the `searchableAttributes` (formerly known as attributesToIndex) setting defines the attributes
    # you want to search in: here `title`, `subtitle` & `description`.
    # You need to list them by order of importance. `description` is tagged as
    # `unordered` to avoid taking the position of a match into account in that attribute.
    searchableAttributes ['title', 'subtitle', 'unordered(description)']

    # the `customRanking` setting defines the ranking criteria use to compare two matching
    # records in case their text-relevance is equal. It should reflect your record popularity.
    customRanking ['desc(likes_count)']
  end

end

Indexing

To index a model, simple call reindex on the class:

Product.reindex

To index all of your models, you can do something like this:

Rails.application.eager_load! # Ensure all models are loaded (required in development).

algolia_models = ActiveRecord::Base.descendants.select{ |model| model.respond_to?(:reindex) }

algolia_models.each(&:reindex)

Frontend Search (realtime experience)

Traditional search implementations tend to have search logic and functionality on the backend. This made sense when the search experience consisted of a user entering a search query, executing that search, and then being redirected to a search result page.

Implementing search on the backend is no longer necessary. In fact, in most cases it is harmful to performance because of added network and processing latency. We highly recommend the usage of our JavaScript API Client issuing all search requests directly from the end user's browser, mobile device, or client. It will reduce the overall search latency while offloading your servers at the same time.

The JS API client is part of the gem, just require algolia/v3/algoliasearch.min somewhere in your JavaScript manifest, for example in application.js if you are using Rails 3.1+:

//= require algolia/v3/algoliasearch.min

Then in your JavaScript code you can do:

var client = algoliasearch(ApplicationID, Search-Only-API-Key);
var index = client.initIndex('YourIndexName');
index.search('something', { hitsPerPage: 10, page: 0 })
  .then(function searchDone(content) {
    console.log(content)
  })
  .catch(function searchFailure(err) {
    console.error(err);
  });

We recently (March 2015) released a new version (V3) of our JavaScript client, if you were using our previous version (V2), read the migration guide

Backend Search

Notes: We recommend the usage of our JavaScript API Client to perform queries directly from the end-user browser without going through your server.

A search returns ORM-compliant objects reloading them from your database. We recommend the usage of our JavaScript API Client to perform queries to decrease the overall latency and offload your servers.

hits =  Contact.search("jon doe")
p hits
p hits.raw_answer # to get the original JSON raw answer

A highlight_result attribute is added to each ORM object:

hits[0].highlight_result['first_name']['value']

If you want to retrieve the raw JSON answer from the API, without re-loading the objects from the database, you can use:

json_answer = Contact.raw_search("jon doe")
p json_answer
p json_answer['hits']
p json_answer['facets']

Search parameters can be specified either through the index's settings statically in your model or dynamically at search time specifying search parameters as second argument of the search method:

class Contact < ActiveRecord::Base
  include AlgoliaSearch

  algoliasearch do
    attribute :first_name, :last_name, :email

    # default search parameters stored in the index settings
    minWordSizefor1Typo 4
    minWordSizefor2Typos 8
    hitsPerPage 42
  end
end
# dynamical search parameters
p Contact.raw_search('jon doe', { hitsPerPage: 5, page: 2 })

Backend Pagination

Even if we highly recommend to perform all search (and therefore pagination) operations from your frontend using JavaScript, we support both will_paginate and kaminari as pagination backend.

To use :will_paginate, specify the :pagination_backend as follow:

AlgoliaSearch.configuration = { application_id: 'YourApplicationID', api_key: 'YourAPIKey', pagination_backend: :will_paginate }

Then, as soon as you use the search method, the returning results will be a paginated set:

# in your controller
@results = MyModel.search('foo', hitsPerPage: 10)

# in your views
# if using will_paginate
<%= will_paginate @results %>

# if using kaminari
<%= paginate @results %>

Tags

Use the tags method to add tags to your record:

class Contact < ActiveRecord::Base
  include AlgoliaSearch

  algoliasearch do
    tags ['trusted']
  end
end

or using dynamical values:

class Contact < ActiveRecord::Base
  include AlgoliaSearch

  algoliasearch do
    tags do
      [first_name.blank? || last_name.blank? ? 'partial' : 'full', has_valid_email? ? 'valid_email' : 'invalid_email']
    end
  end
end

At query time, specify { tagFilters: 'tagvalue' } or { tagFilters: ['tagvalue1', 'tagvalue2'] } as search parameters to restrict the result set to specific tags.

Faceting

Facets can be retrieved calling the extra facets method of the search answer.

class Contact < ActiveRecord::Base
  include AlgoliaSearch

  algoliasearch do
    # [...]

    # specify the list of attributes available for faceting
    attributesForFaceting [:company, :zip_code]
  end
end
hits = Contact.search('jon doe', { facets: '*' })
p hits                    # ORM-compliant array of objects
p hits.facets             # extra method added to retrieve facets
p hits.facets['company']  # facet values+count of facet 'company'
p hits.facets['zip_code'] # facet values+count of facet 'zip_code'
raw_json = Contact.raw_search('jon doe', { facets: '*' })
p raw_json['facets']

Faceted search

You can also search for facet values.

Product.search_for_facet_values('category', 'Headphones') # Array of {value, highlighted, count}

This method can also take any parameter a query can take. This will adjust the search to only hits which would have matched the query.

# Only sends back the categories containing red Apple products (and only counts those)
Product.search_for_facet_values('category', 'phone', {
  query: 'red',
  filters: 'brand:Apple'
}) # Array of phone categories linked to red Apple products

Group by

More info on distinct for grouping can be found here.

class Contact < ActiveRecord::Base
  include AlgoliaSearch

  algoliasearch do
    # [...]

    # specify the attribute to be used for distinguishing the records
    # in this case the records will be grouped by company
    attributeForDistinct "company"
  end
end

Geo-Search

Use the geoloc method to localize your record:

class Contact < ActiveRecord::Base
  include AlgoliaSearch

  algoliasearch do
    geoloc :lat_attr, :lng_attr
  end
end

At query time, specify { aroundLatLng: "37.33, -121.89", aroundRadius: 50000 } as search parameters to restrict the result set to 50KM around San Jose.

Options

Auto-indexing & asynchronism

Each time a record is saved, it will be asynchronously indexed. On the other hand, each time a record is destroyed, it will be - asynchronously - removed from the index. That means that a network call with the ADD/DELETE operation is sent synchronously to the Algolia API but then the engine will asynchronously process the operation (so if you do a search just after, the results may not reflect it yet).

You can disable auto-indexing and auto-removing setting the following options:

class Contact < ActiveRecord::Base
  include AlgoliaSearch

  algoliasearch auto_index: false, auto_remove: false do
    attribute :first_name, :last_name, :email
  end
end

Temporary disable auto-indexing

You can temporary disable auto-indexing using the without_auto_index scope. This is often used for performance reason.

Contact.delete_all
Contact.without_auto_index do
  1.upto(10000) { Contact.create! attributes } # inside this block, auto indexing task will not run.
end
Contact.reindex! # will use batch operations

Queues & background jobs

You can configure the auto-indexing & auto-removal process to use a queue to perform those operations in background. ActiveJob (Rails >=4.2) queues are used by default but you can define your own queuing mechanism:

class Contact < ActiveRecord::Base
  include AlgoliaSearch

  algoliasearch enqueue: true do # ActiveJob will be triggered using a `algoliasearch` queue
    attribute :first_name, :last_name, :email
  end
end

Things to Consider

If you are performing updates & deletions in the background then a record deletion can be committed to your database prior to the job actually executing. Thus if you were to load the record to remove it from the database than your ActiveRecord#find will fail with a RecordNotFound.

In this case you can bypass loading the record from ActiveRecord and just communicate with the index directly:

class MySidekiqWorker
  def perform(id, remove)
    if remove
      # the record has likely already been removed from your database so we cannot
      # use ActiveRecord#find to load it
      index = AlgoliaSearch.client.init_index("index_name")
      index.delete_object(id)
    else
      # the record should be present
      c = Contact.find(id)
      c.index!
    end
  end
end

With Sidekiq

If you're using Sidekiq:

class Contact < ActiveRecord::Base
  include AlgoliaSearch

  algoliasearch enqueue: :trigger_sidekiq_worker do
    attribute :first_name, :last_name, :email
  end

  def self.trigger_sidekiq_worker(record, remove)
    MySidekiqWorker.perform_async(record.id, remove)
  end
end

class MySidekiqWorker
  def perform(id, remove)
    if remove
      # the record has likely already been removed from your database so we cannot
      # use ActiveRecord#find to load it
      index = AlgoliaSearch.client.init_index("index_name")
      index.delete_object(id)
    else
      # the record should be present
      c = Contact.find(id)
      c.index!
    end
  end
end

With DelayedJob

If you're using delayed_job:

class Contact < ActiveRecord::Base
  include AlgoliaSearch

  algoliasearch enqueue: :trigger_delayed_job do
    attribute :first_name, :last_name, :email
  end

  def self.trigger_delayed_job(record, remove)
    if remove
      record.delay.remove_from_index!
    else
      record.delay.index!
    end
  end
end

Synchronism & testing

You can force indexing and removing to be synchronous (in that case the gem will call the wait_task method to ensure the operation has been taken into account once the method returns) by setting the following option: (this is NOT recommended, except for testing purpose)

class Contact < ActiveRecord::Base
  include AlgoliaSearch

  algoliasearch synchronous: true do
    attribute :first_name, :last_name, :email
  end
end

Custom index name

By default, the index name will be the class name, e.g. "Contact". You can customize the index name by using the index_name option:

class Contact < ActiveRecord::Base
  include AlgoliaSearch

  algoliasearch index_name: "MyCustomName" do
    attribute :first_name, :last_name, :email
  end
end

Per-environment indices

You can suffix the index name with the current Rails environment using the following option:

class Contact < ActiveRecord::Base
  include AlgoliaSearch

  algoliasearch per_environment: true do # index name will be "Contact_#{Rails.env}"
    attribute :first_name, :last_name, :email
  end
end

Custom attribute definition

You can use a block to specify a complex attribute value

class Contact < ActiveRecord::Base
  include AlgoliaSearch

  algoliasearch do
    attribute :email
    attribute :full_name do
      "#{first_name} #{last_name}"
    end
    add_attribute :full_name2
  end

  def full_name2
    "#{first_name} #{last_name}"
  end
end

Notes: As soon as you use such code to define extra attributes, the gem is not anymore able to detect if the attribute has changed (the code uses Rails's #{attribute}_changed? method to detect that). As a consequence, your record will be pushed to the API even if its attributes didn't change. You can work-around this behavior creating a _changed? method:

class Contact < ActiveRecord::Base
  include AlgoliaSearch

  algoliasearch do
    attribute :email
    attribute :full_name do
      "#{first_name} #{last_name}"
    end
  end

  def full_name_changed?
    first_name_changed? || last_name_changed?
  end
end

Nested objects/relations

Defining the relationship

You can easily embed nested objects defining an extra attribute returning any JSON-compliant object (an array or a hash or a combination of both).

class Profile < ActiveRecord::Base
  include AlgoliaSearch

  belongs_to :user
  has_many :specializations

  algoliasearch do
    attribute :user do
      # restrict the nested "user" object to its `name` + `email`
      { name: user.name, email: user.email }
    end
    attribute :public_specializations do
      # build an array of public specialization (include only `title` and `another_attr`)
      specializations.select { |s| s.public? }.map do |s|
        { title: s.title, another_attr: s.another_attr }
      end
    end
  end

end

Propagating the change from a nested child

With ActiveRecord

With ActiveRecord, we'll be using touch and after_touch to achieve this.

# app/models/app.rb
class App < ApplicationRecord
  include AlgoliaSearch

  belongs_to :author, class_name: :User
  after_touch :index!

  algoliasearch do
    attribute :title
    attribute :author do
      author.as_json
    end
  end
end

# app/models/user.rb
class User < ApplicationRecord
  # If your association uses belongs_to
  # - use `touch: true`
  # - do not define an `after_save` hook
  has_many :apps, foreign_key: :author_id

  after_save { apps.each(&:touch) }
end

With Sequel

With Sequel, you can use the touch plugin to propagate the changes:

# app/models/app.rb
class App < Sequel::Model
  include AlgoliaSearch

  many_to_one :author, class: :User

  plugin :timestamps
  plugin :touch

  algoliasearch do
    attribute :title
    attribute :author do
      author.to_hash
    end
  end
end

# app/models/user.rb
class User < Sequel::Model
  one_to_many :apps, key: :author_id

  plugin :timestamps
  # Can't use the associations since it won't trigger the after_save
  plugin :touch

  # Define the associations that need to be touched here
  # Less performant, but allows for the after_save hook to trigger
  def touch_associations
    apps.map(&:touch)
  end

  def touch
    super
    touch_associations
  end
end

Custom objectID

By default, the objectID is based on your record's id. You can change this behavior specifying the :id option (be sure to use a uniq field).

class UniqUser < ActiveRecord::Base
  include AlgoliaSearch

  algoliasearch id: :uniq_name do
  end
end

Restrict indexing to a subset of your data

You can add constraints controlling if a record must be indexed by using options the :if or :unless options.

It allows you to do conditional indexing on a per document basis.

class Post < ActiveRecord::Base
  include AlgoliaSearch

  algoliasearch if: :published?, unless: :deleted? do
  end

  def published?
    # [...]
  end

  def deleted?
    # [...]
  end
end

Notes: As soon as you use those constraints, addObjects and deleteObjects calls will be performed in order to keep the index synced with the DB (The state-less gem doesn't know if the object don't match your constraints anymore or never matched, so we force ADD/DELETE operations to be sent). You can work-around this behavior creating a _changed? method:

class Contact < ActiveRecord::Base
  include AlgoliaSearch

  algoliasearch if: :published do
  end

  def published
    # true or false
  end

  def published_changed?
    # return true only if you know that the 'published' state changed
  end
end

You can index a subset of your records using either:

# will generate batch API calls (recommended)
MyModel.where('updated_at > ?', 10.minutes.ago).reindex!

or

MyModel.index_objects MyModel.limit(5)

Sanitizer

You can sanitize all your attributes using the sanitize option. It will strip all HTML tags from your attributes.

class User < ActiveRecord::Base
  include AlgoliaSearch

  algoliasearch per_environment: true, sanitize: true do
    attributes :name, :email, :company
  end
end

If you're using Rails 4.2+, you also need to depend on rails-html-sanitizer:

gem 'rails-html-sanitizer'

UTF-8 Encoding

You can force the UTF-8 encoding of all your attributes using the force_utf8_encoding option:

class User < ActiveRecord::Base
  include AlgoliaSearch

  algoliasearch force_utf8_encoding: true do
    attributes :name, :email, :company
  end
end

Notes: This option is not compatible with Ruby 1.8

Exceptions

You can disable exceptions that could be raised while trying to reach Algolia's API by using the raise_on_failure option:

class Contact < ActiveRecord::Base
  include AlgoliaSearch

  # only raise exceptions in development env
  algoliasearch raise_on_failure: Rails.env.development? do
    attribute :first_name, :last_name, :email
  end
end

Configuration example

Here is a real-word configuration example (from HN Search):

class Item < ActiveRecord::Base
  include AlgoliaSearch

  algoliasearch per_environment: true do
    # the list of attributes sent to Algolia's API
    attribute :created_at, :title, :url, :author, :points, :story_text, :comment_text, :author, :num_comments, :story_id, :story_title

    # integer version of the created_at datetime field, to use numerical filtering
    attribute :created_at_i do
      created_at.to_i
    end

    # `title` is more important than `{story,comment}_text`, `{story,comment}_text` more than `url`, `url` more than `author`
    # btw, do not take into account position in most fields to avoid first word match boost
    searchableAttributes ['unordered(title)', 'unordered(story_text)', 'unordered(comment_text)', 'unordered(url)', 'author']

    # tags used for filtering
    tags do
      [item_type, "author_#{author}", "story_#{story_id}"]
    end

    # use associated number of HN points to sort results (last sort criteria)
    customRanking ['desc(points)', 'desc(num_comments)']

    # google+, $1.5M raises, C#: we love you
    separatorsToIndex '+#$'
  end

  def story_text
    item_type_cd != Item.comment ? text : nil
  end

  def story_title
    comment? && story ? story.title : nil
  end

  def story_url
    comment? && story ? story.url : nil
  end

  def comment_text
    comment? ? text : nil
  end

  def comment?
    item_type_cd == Item.comment
  end

  # [...]
end

Indices

Manual indexing

You can trigger indexing using the index! instance method.

c = Contact.create!(params[:contact])
c.index!

Manual removal

And trigger index removing using the remove_from_index! instance method.

c.remove_from_index!
c.destroy

Reindexing

The gem provides 2 ways to reindex all your objects:

Atomical reindexing

To reindex all your records (taking into account the deleted objects), the reindex class method indices all your objects to a temporary index called <INDEX_NAME>.tmp and moves the temporary index to the final one once everything is indexed (atomically). This is the safest way to reindex all your content.

Contact.reindex

Notes: if you're using an index-specific API key, ensure you're allowing both <INDEX_NAME> and <INDEX_NAME>.tmp.

Warning: You should not use such an atomic reindexing operation while scoping/filtering the model because this operation replaces the entire index, keeping the filtered objects only. ie: Don't do MyModel.where(...).reindex but do MyModel.where(...).reindex! (with the trailing !)!!!

Regular reindexing

To reindex all your objects in place (without temporary index and therefore without deleting removed objects), use the reindex! class method:

Contact.reindex!

Clearing an index

To clear an index, use the clear_index! class method:

Contact.clear_index!

Using the underlying index

You can access the underlying index object by calling the index class method:

index = Contact.index
# index.get_settings, index.partial_update_object, ...

Primary/replica

You can define replica indices using the add_replica method. Use inherit: true on the replica block if you want it to inherit from the primary settings.

class Book < ActiveRecord::Base
  attr_protected

  include AlgoliaSearch

  algoliasearch per_environment: true do
    searchableAttributes [:name, :author, :editor]

    # define a replica index to search by `author` only
    add_replica 'Book_by_author', per_environment: true do
      searchableAttributes [:author]
    end

    # define a replica index with custom ordering but same settings than the main block
    add_replica 'Book_custom_order', inherit: true, per_environment: true do
      customRanking ['asc(rank)']
    end
  end

end

To search using a replica, use the following code:

Book.raw_search 'foo bar', replica: 'Book_by_editor'
# or
Book.search 'foo bar', replica: 'Book_by_editor'

Share a single index

It can make sense to share an index between several models. In order to implement that, you'll need to ensure you don't have any conflict with the objectID of the underlying models.

class Student < ActiveRecord::Base
  attr_protected

  include AlgoliaSearch

  algoliasearch index_name: 'people', id: :algolia_id do
    # [...]
  end

  private
  def algolia_id
    "student_#{id}" # ensure the teacher & student IDs are not conflicting
  end
end

class Teacher < ActiveRecord::Base
  attr_protected

  include AlgoliaSearch

  algoliasearch index_name: 'people', id: :algolia_id do
    # [...]
  end

  private
  def algolia_id
    "teacher_#{id}" # ensure the teacher & student IDs are not conflicting
  end
end

Notes: If you target a single index from several models, you must never use MyModel.reindex and only use MyModel.reindex!. The reindex method uses a temporary index to perform an atomic reindexing: if you use it, the resulting index will only contain records for the current model because it will not reindex the others.

Target multiple indices

You can index a record in several indices using the add_index method:

class Book < ActiveRecord::Base
  attr_protected

  include AlgoliaSearch

  PUBLIC_INDEX_NAME  = "Book_#{Rails.env}"
  SECURED_INDEX_NAME = "SecuredBook_#{Rails.env}"

  # store all books in index 'SECURED_INDEX_NAME'
  algoliasearch index_name: SECURED_INDEX_NAME do
    searchableAttributes [:name, :author]
    # convert security to tags
    tags do
      [released ? 'public' : 'private', premium ? 'premium' : 'standard']
    end

    # store all 'public' (released and not premium) books in index 'PUBLIC_INDEX_NAME'
    add_index PUBLIC_INDEX_NAME, if: :public? do
      searchableAttributes [:name, :author]
    end
  end

  private
  def public?
    released && !premium
  end

end

To search using an extra index, use the following code:

Book.raw_search 'foo bar', index: 'Book_by_editor'
# or
Book.search 'foo bar', index: 'Book_by_editor'

Testing

Notes

To run the specs, please set the ALGOLIA_APPLICATION_ID and ALGOLIA_API_KEY environment variables. Since the tests are creating and removing indices, DO NOT use your production account.

You may want to disable all indexing (add, update & delete operations) API calls, you can set the disable_indexing option:

class User < ActiveRecord::Base
  include AlgoliaSearch

  algoliasearch per_environment: true, disable_indexing: Rails.env.test? do
  end
end

class User < ActiveRecord::Base
  include AlgoliaSearch

  algoliasearch per_environment: true, disable_indexing: Proc.new { Rails.env.test? || more_complex_condition } do
  end
end

❓ Troubleshooting

Encountering an issue? Before reaching out to support, we recommend heading to our FAQ where you will find answers for the most common issues and gotchas with the client.

Use the Dockerfile

If you want to contribute to this project without installing all its dependencies, you can use our Docker image. Please check our dedicated guide to learn more.

algoliasearch-rails's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

algoliasearch-rails's Issues

Markdown Sanitizer

It would be nice to have a Sanitizer for markdown and not only HTML.

As a wordaround I will translate my Markdowns to HTML and use sanitize.

Exclude specific records from indexing

We need to exclude certain records from indexing (for example, unpublished articles). Would be nice if there was a way to flag a record for exclusion. I was imagining an implementation similar to this:

def algolia_should_index?
  published_at < Time.now # only index published articles
end

If this seems reasonable, let me know and I'll send a pull request over.

Uninitialized constant in Rake reindex task

Getting a NameError when trying to run the reindex rake task. This is because the host project in our case is a little funky and model filenames / directory names don't always match the actual class name (a problem for autoload too, but this is a legacy project).

Therefore, when we camelize and constantize on line 25 of the task here, it fails:

https://github.com/algolia/algoliasearch-rails/blob/master/lib/algoliasearch/tasks/algoliasearch.rake#L25

Is there a reason this just doesn't use AlgoliaSearch::Utilities.get_model_classes?

Reindex doesn't trigger when attribute is an array

I'm using Acts-As-Taggable-On which maintains tags in an association. In order to index these, I was trying to do this:

attribute :_tags do
  tags.map(&:name)
end

Where 'tags' is the result of the query that acts_as_taggable_on performs . Reindexes were not being triggered when I changed the tags in the 'tags' list. To further debug this, I set a attribute on my model called 'cached_tags' and set this to an explicit array like so

attribute :cached_tags

Where 'cached_tags' is a postgres array. Modifying this array did not seem to trigger reindexes. The work around I am using is to do this:

attribute :_tags do
  name_will_change!
  tags.map(&:name)
end

Displaying number of hits in header template

When displaying a header for each category in a multi-category (multi index) search, how can we display the total number of hits?

The header template context doesn't seem to have this info?

`rake algoliasearch:reindex` doesn't do anything.

Hi Guys,

I'm trying to index all of my AlgoliaSearch models for the first time. Was going to write a quick rake task to do this for me but I found you guys already had done that. The only thing is, I run it and it doesn't do anything. :/

I investigated a little further and it seems like the AlgoliaSearch::Utilities.get_model_classes returns an empty Array.

Is there anything I should know about here?

Thanks.

Josh

Can we change the `search` method name?

search is quite generic and clash with many other gems

Can we have an option to change the method name, something in the line of

  algoliasearch per_environment: true, if: :should_reindex?, method_name: :algolia_uniq_search do
    ...

Cannot reindex subset of objects

It's only possible to reindex 1 object or all objects. Ideally you'd be able to do something like:

User.where('updated_at > ?', 10.minutes.ago).algolia_reindex!

since using find_in_batches doesn't respect orders and scopes, as Rails returns:

Scoped order and limit are ignored, it's forced to be batch order and batch size

Does it make sense to allow for this?

Is the Sequel ORM supported?

We are using a Rails app with the Sequel ORM. From what I see in the source code, you don't support Sequel yet, which is a bummer for us.

Pagination backend kaminari not working

I'm using kaminari (0.15.1) and algoliasearch-rails (1.9.1) and get the following error when trying to paginate:

NoMethodError:
       undefined method `offset' for []:AlgoliaSearch::Pagination::Kaminari

Associated Records

Given the following model:

class Profile < ActiveRecord::Base
  include AlgoliaSearch

  belongs_to :user, touch: true, dependent: :destroy
  has_many :licenses
  has_many :specializations
  has_many :specialties, through: :specializations

  algoliasearch do
    add_attribute :profile_user
    add_attribute :profile_licenses
    add_attribute :profile_specialties
  end

  def profile_user
    self.user
  end

  def profile_licenses
    self.licenses
  end

  def profile_specialties
    self.specialties
  end
end

The index is happening, and in the Algolia Dashboard it shows the associated items (for example "profile_licenses") However, two things:

  1. How do I limit the fields indexed for associated models?
  2. What would could the associated models to return undefined in the front-end JS search. Meaning -- the associated data is showing in the Algolia dashboard, but on search, anything that was an associated record is returning undefined.

WebMock globally disabled in gem

Using

require 'algolia/webmock'

internally does

# disable by default
WebMock.disable!

which is rude behavior in a project that is already using WebMock for other things. It should just set up the stubs but leave it to the client rails app to decide when to enable or disable, either globally or with specific parameters.

Namespace conflicts

index, search, and many other methods added to ActiveModel objects by this gem are incredibly common method names, conflicting with Ransack, Mongoid, and various other search libraries. Any chance you'd consider namespacing / wrapping usage here?

Curb::Easy segfaults after fork

Segfaults when running rake algoliasearch:reindex. Is it because I'm using spring?

ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-darwin13.0]

-- Crash Report log information --------------------------------------------
   See Crash Report log file under the one of following:
     * ~/Library/Logs/CrashReporter
     * /Library/Logs/CrashReporter
     * ~/Library/Logs/DiagnosticReports
     * /Library/Logs/DiagnosticReports
   for more details.

-- Control frame information -----------------------------------------------
c:0067 p:---- s:0257 e:000256 CFUNC  :perform
c:0066 p:0042 s:0254 e:000253 METHOD /Users/alexander/.gem/ruby/2.1.0/gems/curb-0.8.5/lib/curl/easy.rb:58 [FINISH]
c:0065 p:---- s:0249 e:000248 CFUNC  :http
c:0064 p:0019 s:0245 e:000244 METHOD /Users/alexander/.gem/ruby/2.1.0/gems/curb-0.8.5/lib/curl/easy.rb:284
c:0063 p:0077 s:0242 e:000241 BLOCK  /Users/alexander/.gem/ruby/2.1.0/gems/algoliasearch-1.1.17/lib/algolia/client.rb:36 [FINISH]
c:0062 p:---- s:0237 e:000236 CFUNC  :each
c:0061 p:0018 s:0234 e:000233 METHOD /Users/alexander/.gem/ruby/2.1.0/gems/algoliasearch-1.1.17/lib/algolia/client.rb:30
c:0060 p:0011 s:0227 e:000226 METHOD /Users/alexander/.gem/ruby/2.1.0/gems/algoliasearch-1.1.17/lib/algolia/client.rb:60
c:0059 p:0027 s:0223 e:000222 METHOD /Users/alexander/.gem/ruby/2.1.0/gems/algoliasearch-1.1.17/lib/algolia/index.rb:377
c:0058 p:0041 s:0220 e:000219 METHOD /Users/alexander/.gem/ruby/2.1.0/gems/algoliasearch-rails-1.6.3/lib/algoliasearch-rails.rb:200
c:0057 p:0028 s:0216 e:000215 METHOD /Users/alexander/.gem/ruby/2.1.0/gems/algoliasearch-rails-1.6.3/lib/algoliasearch-rails.rb:151
c:0056 p:0008 s:0210 e:000209 BLOCK  /Users/alexander/.gem/ruby/2.1.0/gems/algoliasearch-rails-1.6.3/lib/algoliasearch/utilities.rb:16 [FINISH]
c:0055 p:---- s:0207 e:000206 CFUNC  :each
c:0054 p:0009 s:0204 e:000203 METHOD /Users/alexander/.gem/ruby/2.1.0/gems/algoliasearch-rails-1.6.3/lib/algoliasearch/utilities.rb:15
c:0053 p:0029 s:0201 e:000200 BLOCK  /Users/alexander/.gem/ruby/2.1.0/gems/algoliasearch-rails-1.6.3/lib/algoliasearch/tasks/algoliasearch.rake:7 [FINISH]
c:0052 p:---- s:0199 e:000198 CFUNC  :call
c:0051 p:0028 s:0194 e:000193 BLOCK  /Users/alexander/.gem/ruby/2.1.0/gems/rake-10.1.1/lib/rake/task.rb:236 [FINISH]
c:0050 p:---- s:0191 e:000190 CFUNC  :each
c:0049 p:0113 s:0188 e:000187 METHOD /Users/alexander/.gem/ruby/2.1.0/gems/rake-10.1.1/lib/rake/task.rb:231
c:0048 p:0075 s:0184 e:000183 BLOCK  /Users/alexander/.gem/ruby/2.1.0/gems/rake-10.1.1/lib/rake/task.rb:175
c:0047 p:0014 s:0182 e:000181 METHOD /Users/alexander/.rubies/ruby-2.1.0/lib/ruby/2.1.0/monitor.rb:211
c:0046 p:0025 s:0179 e:000178 METHOD /Users/alexander/.gem/ruby/2.1.0/gems/rake-10.1.1/lib/rake/task.rb:168
c:0045 p:0036 s:0172 e:000171 METHOD /Users/alexander/.gem/ruby/2.1.0/gems/rake-10.1.1/lib/rake/task.rb:161
c:0044 p:0033 s:0167 e:000166 METHOD /Users/alexander/.gem/ruby/2.1.0/gems/rake-10.1.1/lib/rake/application.rb:149
c:0043 p:0009 s:0160 e:000159 BLOCK  /Users/alexander/.gem/ruby/2.1.0/gems/rake-10.1.1/lib/rake/application.rb:106 [FINISH]
c:0042 p:---- s:0157 e:000156 CFUNC  :each
c:0041 p:0039 s:0154 e:000153 BLOCK  /Users/alexander/.gem/ruby/2.1.0/gems/rake-10.1.1/lib/rake/application.rb:106
c:0040 p:0025 s:0152 e:000151 METHOD /Users/alexander/.gem/ruby/2.1.0/gems/rake-10.1.1/lib/rake/application.rb:115
c:0039 p:0007 s:0148 e:000147 METHOD /Users/alexander/.gem/ruby/2.1.0/gems/rake-10.1.1/lib/rake/application.rb:100
c:0038 p:0019 s:0145 e:000144 BLOCK  /Users/alexander/.gem/ruby/2.1.0/gems/rake-10.1.1/lib/rake/application.rb:78
c:0037 p:0006 s:0143 e:000142 METHOD /Users/alexander/.gem/ruby/2.1.0/gems/rake-10.1.1/lib/rake/application.rb:165
c:0036 p:0007 s:0139 e:000138 METHOD /Users/alexander/.gem/ruby/2.1.0/gems/rake-10.1.1/lib/rake/application.rb:75
c:0035 p:0040 s:0136 e:000135 TOP    /Users/alexander/.gem/ruby/2.1.0/gems/rake-10.1.1/bin/rake:33 [FINISH]
c:0034 p:---- s:0134 e:000133 CFUNC  :load
c:0033 p:0012 s:0129 e:000128 BLOCK  /Users/alexander/.gem/ruby/2.1.0/gems/activesupport-4.1.0.beta1/lib/active_support/dependencies.rb:241
c:0032 p:0054 s:0127 e:000126 METHOD /Users/alexander/.gem/ruby/2.1.0/gems/activesupport-4.1.0.beta1/lib/active_support/dependencies.rb:232
c:0031 p:0019 s:0122 e:000121 METHOD /Users/alexander/.gem/ruby/2.1.0/gems/activesupport-4.1.0.beta1/lib/active_support/dependencies.rb:241
c:0030 p:0179 s:0116 e:000115 BLOCK  /Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/application.rb:133 [FINISH]
c:0029 p:---- s:0111 e:000110 CFUNC  :fork
c:0028 p:0181 s:0108 e:000107 METHOD /Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/application.rb:106
c:0027 p:0079 s:0098 e:000097 BLOCK  /Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/application.rb:75 [FINISH]
c:0026 p:---- s:0096 e:000095 CFUNC  :loop
c:0025 p:0023 s:0093 e:000092 METHOD /Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/application.rb:65
c:0024 p:0136 s:0090 E:001ed0 BLOCK  /Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/application_manager.rb:103 [FINISH]
c:0023 p:---- s:0087 e:000086 CFUNC  :fork
c:0022 p:0038 s:0084 E:001c98 METHOD /Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/application_manager.rb:90
c:0021 p:0007 s:0079 e:000078 METHOD /Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/application_manager.rb:30
c:0020 p:0031 s:0076 e:000075 BLOCK  /Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/application_manager.rb:56
c:0019 p:0014 s:0074 e:000073 METHOD /Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/application_manager.rb:24
c:0018 p:0007 s:0071 e:000070 METHOD /Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/application_manager.rb:43
c:0017 p:0007 s:0068 e:000067 METHOD /Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/application_manager.rb:64
c:0016 p:0129 s:0062 e:000060 METHOD /Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/server.rb:73
c:0015 p:0011 s:0052 e:000051 BLOCK  /Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/server.rb:58 [FINISH]
c:0014 p:---- s:0050 e:000049 CFUNC  :loop
c:0013 p:0041 s:0047 e:000046 METHOD /Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/server.rb:58
c:0012 p:0055 s:0043 e:000042 METHOD /Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/server.rb:52
c:0011 p:0009 s:0040 e:000039 METHOD /Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/server.rb:27
c:0010 p:0023 s:0037 e:000036 BLOCK  /Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/client/run.rb:36 [FINISH]
c:0009 p:---- s:0035 e:000034 CFUNC  :fork
c:0008 p:0026 s:0032 e:000031 METHOD /Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/client/run.rb:34
c:0007 p:0014 s:0026 e:000025 METHOD /Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/client/run.rb:18
c:0006 p:0011 s:0021 e:000020 METHOD /Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/client/command.rb:7
c:0005 p:0015 s:0017 e:000016 METHOD /Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/client.rb:23
c:0004 p:0215 s:0012 e:000011 TOP    /Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/bin/spring:31 [FINISH]
c:0003 p:---- s:0008 e:000007 CFUNC  :load
c:0002 p:0086 s:0004 E:002708 EVAL   ./bin/rake:7 [FINISH]
c:0001 p:0000 s:0002 E:0003b8 TOP    [FINISH]

./bin/rake:7:in `<main>'
./bin/rake:7:in `load'
/Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/bin/spring:31:in `<top (required)>'
/Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/client.rb:23:in `run'
/Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/client/command.rb:7:in `call'
/Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/client/run.rb:18:in `call'
/Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/client/run.rb:34:in `boot_server'
/Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/client/run.rb:34:in `fork'
/Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/client/run.rb:36:in `block in boot_server'
/Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/server.rb:27:in `boot'
/Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/server.rb:52:in `boot'
/Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/server.rb:58:in `start_server'
/Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/server.rb:58:in `loop'
/Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/server.rb:58:in `block in start_server'
/Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/server.rb:73:in `serve'
/Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/application_manager.rb:64:in `run'
/Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/application_manager.rb:43:in `with_child'
/Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/application_manager.rb:24:in `synchronize'
/Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/application_manager.rb:56:in `block in with_child'
/Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/application_manager.rb:30:in `start'
/Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/application_manager.rb:90:in `start_child'
/Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/application_manager.rb:90:in `fork'
/Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/application_manager.rb:103:in `block in start_child'
/Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/application.rb:65:in `run'
/Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/application.rb:65:in `loop'
/Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/application.rb:75:in `block in run'
/Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/application.rb:106:in `serve'
/Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/application.rb:106:in `fork'
/Users/alexander/.gem/ruby/2.1.0/gems/spring-1.0.0/lib/spring/application.rb:133:in `block in serve'
/Users/alexander/.gem/ruby/2.1.0/gems/activesupport-4.1.0.beta1/lib/active_support/dependencies.rb:241:in `load'
/Users/alexander/.gem/ruby/2.1.0/gems/activesupport-4.1.0.beta1/lib/active_support/dependencies.rb:232:in `load_dependency'
/Users/alexander/.gem/ruby/2.1.0/gems/activesupport-4.1.0.beta1/lib/active_support/dependencies.rb:241:in `block in load'
/Users/alexander/.gem/ruby/2.1.0/gems/activesupport-4.1.0.beta1/lib/active_support/dependencies.rb:241:in `load'
/Users/alexander/.gem/ruby/2.1.0/gems/rake-10.1.1/bin/rake:33:in `<top (required)>'
/Users/alexander/.gem/ruby/2.1.0/gems/rake-10.1.1/lib/rake/application.rb:75:in `run'
/Users/alexander/.gem/ruby/2.1.0/gems/rake-10.1.1/lib/rake/application.rb:165:in `standard_exception_handling'
/Users/alexander/.gem/ruby/2.1.0/gems/rake-10.1.1/lib/rake/application.rb:78:in `block in run'
/Users/alexander/.gem/ruby/2.1.0/gems/rake-10.1.1/lib/rake/application.rb:100:in `top_level'
/Users/alexander/.gem/ruby/2.1.0/gems/rake-10.1.1/lib/rake/application.rb:115:in `run_with_threads'
/Users/alexander/.gem/ruby/2.1.0/gems/rake-10.1.1/lib/rake/application.rb:106:in `block in top_level'
/Users/alexander/.gem/ruby/2.1.0/gems/rake-10.1.1/lib/rake/application.rb:106:in `each'
/Users/alexander/.gem/ruby/2.1.0/gems/rake-10.1.1/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/Users/alexander/.gem/ruby/2.1.0/gems/rake-10.1.1/lib/rake/application.rb:149:in `invoke_task'
/Users/alexander/.gem/ruby/2.1.0/gems/rake-10.1.1/lib/rake/task.rb:161:in `invoke'
/Users/alexander/.gem/ruby/2.1.0/gems/rake-10.1.1/lib/rake/task.rb:168:in `invoke_with_call_chain'
/Users/alexander/.rubies/ruby-2.1.0/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/Users/alexander/.gem/ruby/2.1.0/gems/rake-10.1.1/lib/rake/task.rb:175:in `block in invoke_with_call_chain'
/Users/alexander/.gem/ruby/2.1.0/gems/rake-10.1.1/lib/rake/task.rb:231:in `execute'
/Users/alexander/.gem/ruby/2.1.0/gems/rake-10.1.1/lib/rake/task.rb:231:in `each'
/Users/alexander/.gem/ruby/2.1.0/gems/rake-10.1.1/lib/rake/task.rb:236:in `block in execute'
/Users/alexander/.gem/ruby/2.1.0/gems/rake-10.1.1/lib/rake/task.rb:236:in `call'
/Users/alexander/.gem/ruby/2.1.0/gems/algoliasearch-rails-1.6.3/lib/algoliasearch/tasks/algoliasearch.rake:7:in `block (2 levels) in <top (required)>'
/Users/alexander/.gem/ruby/2.1.0/gems/algoliasearch-rails-1.6.3/lib/algoliasearch/utilities.rb:15:in `reindex_all_models'
/Users/alexander/.gem/ruby/2.1.0/gems/algoliasearch-rails-1.6.3/lib/algoliasearch/utilities.rb:15:in `each'
/Users/alexander/.gem/ruby/2.1.0/gems/algoliasearch-rails-1.6.3/lib/algoliasearch/utilities.rb:16:in `block in reindex_all_models'
/Users/alexander/.gem/ruby/2.1.0/gems/algoliasearch-rails-1.6.3/lib/algoliasearch-rails.rb:151:in `reindex!'
/Users/alexander/.gem/ruby/2.1.0/gems/algoliasearch-rails-1.6.3/lib/algoliasearch-rails.rb:200:in `ensure_init'
/Users/alexander/.gem/ruby/2.1.0/gems/algoliasearch-1.1.17/lib/algolia/index.rb:377:in `get_settings'
/Users/alexander/.gem/ruby/2.1.0/gems/algoliasearch-1.1.17/lib/algolia/client.rb:60:in `get'
/Users/alexander/.gem/ruby/2.1.0/gems/algoliasearch-1.1.17/lib/algolia/client.rb:30:in `request'
/Users/alexander/.gem/ruby/2.1.0/gems/algoliasearch-1.1.17/lib/algolia/client.rb:30:in `each'
/Users/alexander/.gem/ruby/2.1.0/gems/algoliasearch-1.1.17/lib/algolia/client.rb:36:in `block in request'
/Users/alexander/.gem/ruby/2.1.0/gems/curb-0.8.5/lib/curl/easy.rb:284:in `http_get'
/Users/alexander/.gem/ruby/2.1.0/gems/curb-0.8.5/lib/curl/easy.rb:284:in `http'
/Users/alexander/.gem/ruby/2.1.0/gems/curb-0.8.5/lib/curl/easy.rb:58:in `perform'
/Users/alexander/.gem/ruby/2.1.0/gems/curb-0.8.5/lib/curl/easy.rb:58:in `perform'

-- C level backtrace information -------------------------------------------
0   ruby                                0x0000000104cc5a8b rb_vm_bugreport + 251
1   ruby                                0x0000000104b4c2e5 report_bug + 357
2   ruby                                0x0000000104b4c60f rb_bug + 207
3   ruby                                0x0000000104c3902f sigsegv + 207
4   libsystem_platform.dylib            0x00007fff870e25aa _sigtramp + 26
5   libdispatch.dylib                   0x00007fff8b733fc8 _dispatch_async_f_slow + 87
6   ???                                 0x00007ff5bf024220 0x0 + 140693448311328

-- Other runtime information -----------------------------------------------

* Loaded script: /Users/alexander/.gem/ruby/2.1.0/gems/rake-10.1.1/bin/rake

* Loaded features:

    ... removed

[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome.
For details: http://www.ruby-lang.org/bugreport.html

Mongoid Cursor Timeout

When iterating over large collections, the Mongoid cursor will timeout after 10 minutes.

Example error below:

irb(main):002:0> Member.reindex!
Moped::Errors::CursorNotFound: The operation: "GET MORE"
failed with error "cursor 3213467116051329994 not found"
    from /var/www/imagebrief/dev/shared/bundle/ruby/1.9.1/gems/moped-1.5.1/lib/moped/node.rb:216:in `get_more'
    from /var/www/imagebrief/dev/shared/bundle/ruby/1.9.1/gems/moped-1.5.1/lib/moped/cursor.rb:44:in `get_more'
    from /var/www/imagebrief/dev/shared/bundle/ruby/1.9.1/gems/moped-1.5.1/lib/moped/cursor.rb:29:in `each'
    from /var/www/imagebrief/dev/shared/bundle/ruby/1.9.1/gems/moped-1.5.1/lib/moped/query.rb:76:in `each'
    from /var/www/imagebrief/dev/shared/bundle/ruby/1.9.1/gems/moped-1.5.1/lib/moped/query.rb:76:in `each'
    from /var/www/imagebrief/dev/shared/bundle/ruby/1.9.1/gems/mongoid-3.1.5/lib/mongoid/contextual/mongo.rb:122:in `block in each'
    from /var/www/imagebrief/dev/shared/bundle/ruby/1.9.1/gems/mongoid-3.1.5/lib/mongoid/contextual/mongo.rb:619:in `selecting'
    from /var/www/imagebrief/dev/shared/bundle/ruby/1.9.1/gems/mongoid-3.1.5/lib/mongoid/contextual/mongo.rb:121:in `each'
    from /var/www/imagebrief/dev/shared/bundle/ruby/1.9.1/gems/mongoid-3.1.5/lib/mongoid/contextual.rb:19:in `each'
    from /var/www/imagebrief/dev/shared/bundle/ruby/1.9.1/gems/algoliasearch-rails-1.11.7/lib/algoliasearch-rails.rb:569:in `algolia_find_in_batches'
    from /var/www/imagebrief/dev/shared/bundle/ruby/1.9.1/gems/algoliasearch-rails-1.11.7/lib/algoliasearch-rails.rb:237:in `block in algolia_reindex!'
    from /var/www/imagebrief/dev/shared/bundle/ruby/1.9.1/gems/algoliasearch-rails-1.11.7/lib/algoliasearch-rails.rb:231:in `each'
    from /var/www/imagebrief/dev/shared/bundle/ruby/1.9.1/gems/algoliasearch-rails-1.11.7/lib/algoliasearch-rails.rb:231:in `algolia_reindex!'

Environment variable for disable_indexing

Let's allow the disable_indexing option to be set by an environment variable, so that we can add one line inside the config/environments/test file instead of updating all Models including Algolia.

Slave index are not binded to master

When I set a slave index this is not automatically binded to master.

    add_slave 'User_name_asc', per_environment: true do
      customRanking %w(asc(name))
    end

An index User_name_asc_[env] is created but id not a slave of the master index created by the class

Several model for the same index

It's not an issue but a question. I post it here because maybe some people are interested in the response.

Is it possible to have one index used for multiple models? I'm sure indexing should work but what about double id (same in model A and model B) and searching?

Do I need to first copy A and B in a model C by myself and then index C in Algolia?

Sager load associations through includes?

Is there a way to eager load associations to loaded models? I could theoretically index the data but then it seems I'd have to map my result set against the raw answer json to pull out the data I want which isn't that pretty.. Could easily do this if instead of returning an array Algolia Rails returned a scope..

rspec sends out Put requests

When running on rspec on my project, VCR is catching all the requests for each item been created. It should be possible to run rspec without needing an internet connection.

On say my Artist model, I have

algoliasearch if: :valid_to_index? do
attribute :name, :link
end

def valid_to_index?
false
end

Yet, when I create an artist in rspec, the before callbacks trigger and a request is send to Algolia

License missing from gemspec

RubyGems.org doesn't report a license for your gem. This is because it is not specified in the gemspec of your last release.

via e.g.

spec.license = 'MIT'
# or
spec.licenses = ['MIT', 'GPL-2']

Including a license in your gemspec is an easy way for rubygems.org and other tools to check how your gem is licensed. As you can imagine, scanning your repository for a LICENSE file or parsing the README, and then attempting to identify the license or licenses is much more difficult and more error prone. So, even for projects that already specify a license, including a license in your gemspec is a good practice. See, for example, how rubygems.org uses the gemspec to display the rails gem license.

There is even a License Finder gem to help companies/individuals ensure all gems they use meet their licensing needs. This tool depends on license information being available in the gemspec. This is an important enough issue that even Bundler now generates gems with a default 'MIT' license.

I hope you'll consider specifying a license in your gemspec. If not, please just close the issue with a nice message. In either case, I'll follow up. Thanks for your time!

Appendix:

If you need help choosing a license (sorry, I haven't checked your readme or looked for a license file), GitHub has created a license picker tool. Code without a license specified defaults to 'All rights reserved'-- denying others all rights to use of the code.
Here's a list of the license names I've found and their frequencies

p.s. In case you're wondering how I found you and why I made this issue, it's because I'm collecting stats on gems (I was originally looking for download data) and decided to collect license metadata,too, and make issues for gemspecs not specifying a license as a public service :). See the previous link or my blog post about this project for more information.

Asynchronously index!

I'm currently doing after_touch :index! to reindex a record after a dependant record has been updated. However this introduces a small(but noticeable) delay in the server response.

Am I doing it wrong? Or would it be desirable to add an asynchronous index method?

Multiple indexes on the same model

For a model, can there be multiple indexes on the same model?

Doing that, doesn't seem to work. Only 1 index is updated on doing a reindex

Problem with updating the old record when using worker

I am using worker to update index when attributes are being updated. I had some nested objects, I found out when I use a worker, the old record is sent to worker before the changes are committed. Is there anyway to solve this problem?

Reindex can do its work without removing backend index configuration

It happens sometime when you dev, that you add a field with a migration on a model. You often then configure this new field for algolia indexation into model which is fine. But then you have to reindex to have a production index up to date and it removes previously working index because the reindexation removes the configuration done in algolia backend, thus breaking services that rely on algolia search.
Happens to me with a back in rails and a front in ember.js

Potential enhancement for custom attribute definition

I was working on some custom attributes and ended up had to write a few methods like the following:

def custom_attribute_changed?
  self.attribute_a_changed? || self.attribute_b_changed?
end

def custom_attribute_2_changed?
  self.attribute_c_changed? || self.attribute_d_changed?
end

I did some little experiments and found out that whenever anything changed (including nested object / associations), updated_at will always change when you call record.save!. I guess we can just use one method to trigger index! everytime instead of having to write _changed? method for all custom attributes?

    def updated_at_i_changed?
        self.updated_at_changed?
    end

callbacks should use after_commit, and not after_save

code in question: fbdff0d#diff-dfaec67e907148ea8211e17340f0f30cR267

after_save shouldn't be used because it fails in transaction. consider this example

class User < AR::Base
  algoliasearch index_name: 'users' do
    attributes :name
  end
end

user = User.create(name: 'Bob')

# after couple of days.
User.transaction do
  user.update_attributes!(name: 'Marley')
  call_a_method_which_raises_error!
end

since we are using after_save, it will update algolia with user name as 'Marley'. so, its advised to use after_commit. after_commit will only be called if transaction is successful, which is the behavior we want here.

elasticsearch-rails does the same, check this readme for more info: https://github.com/elastic/elasticsearch-rails/blob/738c63ef/elasticsearch-model/README.md#custom-callbacks

Item isn't reindexed if only tags are changed

My model looks like

algoliasearch index_name: "ChefSteps", per_environment: true, if: :has_title do
    # Searchable fields (may be used for display too)
    attribute :title, :description

   ...

    tags do
      tags.map(&:name)
    end
end

If I change the description, a reindex happens as expected. If I change only tags and save, it doesn't.

Rails 4.2.0.beta2 problem

Followed all steps correctly, installed and configured for a searchable model.
But, on rails console, cannot reindex data.

Throws exception below;

Loading development environment (Rails 4.2.0.beta2)
irb(main):001:0> Activity.reindex!
NameError: undefined local variable or method `visit_Arel_Nodes_Casted' for #    <Arel::Visitors::DepthFirst:0x007f9af6e3e110>
  from /Users/dev/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/arel-

Silly question...

What is the best way to not affect my production database when developing locally? Do I need to create a whole new application? Or do I create a new indice with the same name (Post)?

Lastly, is there a special dev mode where it won't count against my usage?

find_in_batches is ActiveRecord-specific

We're using this successfully with Mongoid right now. The only hitch was that we had to supply our own version of find_in_batches for compatibility purposes. Would be ideal if this wasn't required for other users, though.

Is this library thread safe ?

I'm using sidekiq to process lot of jobs, using 25 threads. Each job result into an object creation with is then synced with algolia using this library.

However, I'm experiencing many ruby segmentation faults and it looks like it comes from curb. Have you any recommendations to use Algolia in a thread safe environment?

Right now the only solution I see would be to use the basic Ruby lib and rebuild the index each minute using tasks.

Here is the full stack trace, ending in a segmentation fault. Algolia says host is unreachable but of course the server has connexion. I think curb crashes because of the threaded environnement.

2013-10-15T14:00:02Z 26574 TID-jso6s WARN: {"retry"=>true, "queue"=>"default", "class"=>"EventsWorker", "args"=>[{"url"=>"xxx", "developer_id"=>1, "action"=>0, "tracker"=>"xxxx", "device_id"=>128607, "ip_address"=>"78.124.135.74"}], "jid"=>"f35155322857c388a9833d9e", "enqueued_at"=>1381842082.106857, "error_message"=>"Cannot reach any hosts", "error_class"=>"Algolia::AlgoliaProtocolError", "failed_at"=>"2013-10-15T13:49:49Z", "retry_count"=>1, "retried_at"=>2013-10-15 14:00:02 UTC}
2013-10-15T14:00:02Z 26574 TID-jso6s WARN: 0: Cannot reach any hosts
2013-10-15T14:00:02Z 26574 TID-jso6s WARN: /usr/local/lib/ruby/gems/1.9.1/gems/algoliasearch-1.1.2/lib/algolia/client.rb:70:in request' /usr/local/lib/ruby/gems/1.9.1/gems/algoliasearch-1.1.2/lib/algolia/client.rb:74:inget'
/usr/local/lib/ruby/gems/1.9.1/gems/algoliasearch-1.1.2/lib/algolia/index.rb:141:in block in wait_task' /usr/local/lib/ruby/gems/1.9.1/gems/algoliasearch-1.1.2/lib/algolia/index.rb:140:inloop'
/usr/local/lib/ruby/gems/1.9.1/gems/algoliasearch-1.1.2/lib/algolia/index.rb:140:in wait_task' /usr/local/lib/ruby/gems/1.9.1/gems/algoliasearch-1.1.2/lib/algolia/index.rb:43:inadd_object!'
/usr/local/lib/ruby/gems/1.9.1/gems/algoliasearch-rails-1.1.8/lib/algoliasearch-rails.rb:117:in index!' /usr/local/lib/ruby/gems/1.9.1/gems/algoliasearch-rails-1.1.8/lib/algoliasearch-rails.rb:174:inindex!'
/usr/local/lib/ruby/gems/1.9.1/gems/algoliasearch-rails-1.1.8/lib/algoliasearch-rails.rb:202:in perform_index_tasks' /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:479:in_run__4331490953959730047__save__721909785243820611__callbacks'
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:405:in __run_callback' /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:385:in_run_save_callbacks'
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:81:in run_callbacks' /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/callbacks.rb:264:increate_or_update'
/usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/persistence.rb:84:in save' /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/validations.rb:50:insave'
/usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/attribute_methods/dirty.rb:22:in save' /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/transactions.rb:259:inblock (2 levels) in save'
/usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/transactions.rb:313:in block in with_transaction_returning_status' /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/database_statements.rb:192:intransaction'
/usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/transactions.rb:208:in transaction' /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/transactions.rb:311:inwith_transaction_returning_status'
/usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/transactions.rb:259:in block in save' /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/transactions.rb:270:inrollback_active_record_state!'
/usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/transactions.rb:258:in save' /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/relation/finder_methods.rb:296:infind_or_instantiator_by_attributes'
/usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/dynamic_matchers.rb:52:in method_missing' /home/shopelia/shopelia/app/models/product.rb:46:infetch'
/home/shopelia/shopelia/app/models/event.rb:45:in find_or_create_product' /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:407:in_run__2915695537341975728__validation__721909785243820611__callbacks'
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:405:in __run_callback' /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:385:in_run_validation_callbacks'
/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:81:in run_callbacks' /usr/local/lib/ruby/gems/1.9.1/gems/activemodel-3.2.13/lib/active_model/validations/callbacks.rb:53:inrun_validations!'
/usr/local/lib/ruby/gems/1.9.1/gems/activemodel-3.2.13/lib/active_model/validations.rb:195:in valid?' /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/validations.rb:69:invalid?'
/usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/validations.rb:77:in perform_validations' /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/validations.rb:56:insave!'
/usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/attribute_methods/dirty.rb:33:in save!' /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/transactions.rb:264:inblock in save!'
/usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/transactions.rb:313:in block in with_transaction_returning_status' /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/database_statements.rb:192:intransaction'
/usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/transactions.rb:208:in transaction' /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/transactions.rb:311:inwith_transaction_returning_status'
/usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/transactions.rb:264:in save!' /usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/validations.rb:41:increate!'
/home/shopelia/shopelia/app/workers/events_worker.rb:16:in create_event' /home/shopelia/shopelia/app/workers/events_worker.rb:5:inperform'
/usr/local/lib/ruby/gems/1.9.1/gems/sidekiq-2.14.1/lib/sidekiq/processor.rb:48:in block (3 levels) in process' /usr/local/lib/ruby/gems/1.9.1/gems/sidekiq-2.14.1/lib/sidekiq/middleware/chain.rb:115:incall'
/usr/local/lib/ruby/gems/1.9.1/gems/sidekiq-2.14.1/lib/sidekiq/middleware/chain.rb:115:in block in invoke' /usr/local/lib/ruby/gems/1.9.1/gems/sidekiq-2.14.1/lib/sidekiq/middleware/server/active_record.rb:6:incall'
/usr/local/lib/ruby/gems/1.9.1/gems/sidekiq-2.14.1/lib/sidekiq/middleware/chain.rb:117:in block in invoke' /usr/local/lib/ruby/gems/1.9.1/gems/sidekiq-2.14.1/lib/sidekiq/middleware/server/retry_jobs.rb:62:incall'
/usr/local/lib/ruby/gems/1.9.1/gems/sidekiq-2.14.1/lib/sidekiq/middleware/chain.rb:117:in block in invoke' /usr/local/lib/ruby/gems/1.9.1/gems/sidekiq-2.14.1/lib/sidekiq/middleware/server/logging.rb:11:inblock in call'
/usr/local/lib/ruby/gems/1.9.1/gems/sidekiq-2.14.1/lib/sidekiq/logging.rb:22:in with_context' /usr/local/lib/ruby/gems/1.9.1/gems/sidekiq-2.14.1/lib/sidekiq/middleware/server/logging.rb:7:incall'
/usr/local/lib/ruby/gems/1.9.1/gems/sidekiq-2.14.1/lib/sidekiq/middleware/chain.rb:117:in block in invoke' /usr/local/lib/ruby/gems/1.9.1/gems/sidekiq-2.14.1/lib/sidekiq/middleware/chain.rb:120:incall'
/usr/local/lib/ruby/gems/1.9.1/gems/sidekiq-2.14.1/lib/sidekiq/middleware/chain.rb:120:in invoke' /usr/local/lib/ruby/gems/1.9.1/gems/sidekiq-2.14.1/lib/sidekiq/processor.rb:47:inblock (2 levels) in process'
/usr/local/lib/ruby/gems/1.9.1/gems/sidekiq-2.14.1/lib/sidekiq/processor.rb:102:in stats' /usr/local/lib/ruby/gems/1.9.1/gems/sidekiq-2.14.1/lib/sidekiq/processor.rb:46:inblock in process'
/usr/local/lib/ruby/gems/1.9.1/gems/celluloid-0.14.1/lib/celluloid/calls.rb:25:in call' /usr/local/lib/ruby/gems/1.9.1/gems/celluloid-0.14.1/lib/celluloid/calls.rb:25:inpublic_send'
/usr/local/lib/ruby/gems/1.9.1/gems/celluloid-0.14.1/lib/celluloid/calls.rb:25:in dispatch' /usr/local/lib/ruby/gems/1.9.1/gems/celluloid-0.14.1/lib/celluloid/calls.rb:67:indispatch'
/usr/local/lib/ruby/gems/1.9.1/gems/celluloid-0.14.1/lib/celluloid/future.rb:15:in block in new' /usr/local/lib/ruby/gems/1.9.1/gems/celluloid-0.14.1/lib/celluloid/internal_pool.rb:59:incall'
/usr/local/lib/ruby/gems/1.9.1/gems/celluloid-0.14.1/lib/celluloid/internal_pool.rb:59:in `block in create'
/usr/local/lib/ruby/gems/1.9.1/gems/curb-0.8.5/lib/curl/easy.rb:58: [BUG] Segmentation fault
ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-linux]

Search keyword conflict with Ransack(ActiveAdmin)

Model.search(wir) for me causes
NoMethodError: undefined method delete_if' for "wir":String from /home/v/.rvm/gems/ruby-2.0.0-p247/gems/ransack-1.2.2/lib/ransack/adapters/active_record/base.rb:15:inransack'
from (irb):1

ruby -v
ruby 2.0.0p247

Ransack is used in a common library called ActiveAdmin.

Is there any aliases instead of search possible? In Sunspot, it used
Sunspot.search(Post) as an alias for Post.search

Best,
Vinny

Is there a way to keep Algolia out of the model?

It seems very strange to me that i need to hook algolia into the models and then use webmock just to mock running api requests in my tests so they don't throw errors (or slow down unit-testing)....

Having workers in models can't be best-practice. Sounds like a huge side-effect to me.

Is there a way to move it into normal cronjobs/rake tasks? Where i (eg) fetch the latest changes and send them to algolia ?

If not is there a best practice to move it into a module and only include it in production (which sounds scary as well)…

Also what's the best way to automaticcaly test the integration ?
Make model / change it / hit search ?

best wishes
Andreas

attributes vs attribute

In README I see examples where both attributes and attribute are used.

Is there any difference? Are they equivalent?

e.g. I found both

attributes :name, :email, :company

and

attribute :first_name, :last_name, :email

Algolia down does not affect website

Hi,
While Algolia search was down(http://blog.algolia.com/black-thursday-dns-issue/) , my site was not able to start as in initializers, it was trying to connect via

AlgoliaSearch.configuration = { application_id: ALGOLIA_APP_ID,
api_key: ALGOLIA_API_KEY,
pagination_backend: :kaminari }

I changed it to

AlgoliaSearch.configuration = { application_id: ALGOLIA_APP_ID,
api_key: ALGOLIA_API_KEY,
hosts: ["#{ALGOLIA_APP_ID}-1.algolia.net",
"#{ALGOLIA_APP_ID}-2.algolia.net",
"#{ALGOLIA_APP_ID}-3.algolia.net"],
pagination_backend: :kaminari }

and this works. But sometime in the future, this may fail for unknown reasons. Would having a begin/rescue help, or is there a way to mock out algoliasearch(in the models) if there is not a valid connection. My current models use:

algoliasearch per_environment: true, :disable_indexing => Proc.new { Rails.env.test? || Rails.env.development? } do
...
end

Algoliasearch Rake tasks

Is there a point keeping the algoliasearch:reindex and algoliasearch:clear_indexes tasks in the code base (https://github.com/algolia/algoliasearch-rails/blob/master/lib/algoliasearch/tasks/algoliasearch.rake) ?

Is this code just kept for the record : I see no easy way to make it work.
The only solution I found was to rewrite the tasks code adding the loading of the models I needed.

namespace :nexkap do
  desc "Reindex Companies"
  task :algolia_reindex_companies => :environment do
    Company
    AlgoliaSearch::Utilities.reindex_all_models
  end
end

Am I missing something ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.