searchkick

Searching has_many association with Searchkick

此生再无相见时 提交于 2019-12-13 05:36:52
问题 I'm attempting to build out a search feature for my app and am running into some issues with being able to search a has_many association. I want it set up so that a user only sees items that they have access to. In my user model, I have: class User < ApplicationRecord searchkick has_many :items, -> (user) { unscope(:where).where("(consumer_type = ? and consumer_id = ?))", 'User', user.id) }, fully_load: false, dependent: :destroy # not sure if this is helpful, was messing around with this def

How to allow users to search only their posts using Elastic Search with Searchkick on Rails?

强颜欢笑 提交于 2019-12-11 11:16:15
问题 I want users to be able to search only their posts and not show the posts created by other users. How exactly would I do that? I'm using Elastic Search with Searchkick gem. I tried this but it is still showing posts from other users: posts controller @posts = current_user.posts.search params[:search] 回答1: According to searchkick, the following should work: Post.search params[:search], where: {user_id: current_user.id} 回答2: Maybe you need to add a where clause to only search the post of the

Elasticsearch log file huge size performance degradation

岁酱吖の 提交于 2019-12-11 10:28:30
问题 I am using RoR to develop an application and a gem called searchkick, this gem internally uses elasticsearch. Everything works fine but on the production, we faced a weird issue, that after some time the site goes down. The reason we discovered was the memory on the server was being overused. We deleted some elasticsearch log files of the previous week and found out that the memory use was reduced to 47% from 92%. we use rolled logging, and logs are backed up each day. Now, the problem that

How to use elasticsearch/searchkick to run a search bar on my navbar and show results in a specific page?

吃可爱长大的小学妹 提交于 2019-12-11 04:59:41
问题 I just finished going over a few tutorials dealing with search. I wanted to put my search bar on my navbar so that whenever someone searches the results I will be taken to my search.html.erb within my books folder (similar to how SO works). I ran into an issue though, every time I did a search I was taken to my books page [http://localhost:3000/books?utf8=%E2%9C%93&q=travel] with no results being shown just my standard index showing all my books and was never taken to my search results page.

URI::InvalidURIError: the scheme http does not accept registry part: :9200 (or bad hostname?)

荒凉一梦 提交于 2019-12-11 01:38:26
问题 I am using Elasticsearch / SearchKick / Bonsai to set up search in production on Heroku. This is working beautifully locally, but I am having trouble indexing my objects on Heroku. in config/initializers/bonsai.rb require 'elasticsearch/model' if ENV['BONSAI_URL'] Elasticsearch::Model.client = Elasticsearch::Client.new({url: ENV['BONSAI_URL'], logs: true}) end in lib/tasks/elasticsearch.rb require 'elasticsearch/rails/tasks/import' in user.rb include Elasticsearch::Model include Elasticsearch

Searchkick not searching multiple terms when specify fields

不打扰是莪最后的温柔 提交于 2019-12-09 12:49:40
问题 Can anyone provide advice on the following please? I'm using searchkick / elasticsearch and would like to search for a key term or terms across multiple fields (name, manufacturer). So for example if im looking for a product called "myproduct" made my "somemanufacturer" i'd expect to see this result appear if I search either "myproduct", "somemanufacturer" or "myproduct somemanufacturer" as both these terms are included either in name or manufacturer fields. My problem is the following:

rake environment elastic search:import:all FORCE=y keeps failing

半世苍凉 提交于 2019-12-06 08:32:16
I'm running search kick and elastic search and i keep trying to recreate my index because my rails app is crashing but this keeps failing too. I am very new to this so feeling quite lost. I run rake environment elasticsearch:import:all FORCE=y But the error is Starting up a new ElasticSearch client with [IMPORT] Loading models from: /home/ubuntu/workspace/sample_app/app/models 2016-03-11 16:32:07 +0000: [Faraday::ConnectionFailed] Connection refused - connect(2) for "localhost" port 9200 {:host=>"localhost", :port=>9200, :protocol=>"http"} rake aborted! ArgumentError: users does not exist to

Searchkick + Bloodhound + Typeahead for autocomplete

五迷三道 提交于 2019-12-06 05:29:53
问题 I am trying to implement a simple autocomplete feature for a single attribute. Model: searchkick text_start: [:name],autocomplete: ['name'] After reindexing the behaviour on the Rails console is ok . 2.2.0-p0 :002 >Doctor.search("a", autocomplete: true).map(&:name) gives the output- => ["a", "aa", "aaa", "aaaa"] After this i added the Autocomplete action to the controller and a new route to the routes.rb file. Controller: def autocomplete console.log("In auto") render json: Doctor.search

searchkick index related model fields

天涯浪子 提交于 2019-12-05 19:18:04
问题 I have a rails application and I'm switching from Sphinx to ElasticSearch and using the gem searchkick. I have a model Teacher and a model Tags (via a gem), where a Teacher can have multiple tags associated. In the Teacher model I've defined the index like this: def search_data { name: name, intro: intro, bio: bio, tag_name: tags.name } end Name, intro and bio are Teacher attributes, but I want to index the name od the tags associeted to the teacher. How can I do this? The way it is now, it

Rails Searchkick / Elasticsearch has_many and belongs_to associations

心已入冬 提交于 2019-12-04 14:29:15
问题 Im trying to use Searchkick to run a search and return based on multiple models. My book model contains this class Book < ActiveRecord::Base searchkick has_many :book_subjects has_many :subjects, through: :book_subjects belongs_to :author belongs_to :publisher end and then my controller has this def index if params[:search].present? @books = Book.search(params[:search], operator: "or") else @books = Book.all end end I want the search results to search the associated models and return any