Metasearch rails gem multiple time search by field - ruby-on-rails

I have such code of searching (with metasearch rails gem):
#pre_oils = Oil.search({:manufacturer_like => params[:oilbrand], :description_like => params[:oiloiliness], :description_like => params[:oilstructure], :capacity_eq => params[:oilsize]})
But i must to search via description with like on two params: oiloiliness, oilstructure... In some cases i could have first, but didn'r have oilstructure or have oilstructure but didn't have oiloiliness...
if i leave
#pre_oils = Oil.search({:manufacturer_like => params[:oilbrand], :description_like => params[:oiloiliness], :capacity_eq => params[:oilsize]})
all is ok
Now it is not searching via oiloiliness, but why ? How to do it? How to search via both fields?

Related

Undefined local variables in Rails 3 partials after upgrade to Ruby 1.9.3

I know there are several posts on this issue but none of the solutions I've read help here.
I've just upgraded from Ruby 1.8.7 to 1.9.3p429 and now, I get undefined local variable in my partials.
I am calling a partial (from a partial in case that's relevant) thusly:
= render :partial => 'user_name', :locals => {:user => item_user, :extra_class => "active"}
In the partial, I access these locals thusly:
- if(current_user and user.silhouette_user_id.to_i == current_user.silhouette_user_id)
= notranslate(current_user.full_name)
- else
- if !local_assigns[:extra_class].nil?
= notranslate(link_to( h(user.full_name), stream_url(:user_id => user.silhouette_user_id), :class => extra_class )) rescue "Anonymous"
- else
= notranslate(link_to( h(user.full_name), stream_url(:user_id => user.silhouette_user_id) )) rescue "Anonymous"
= notranslate(link_to "Pro", "#", :class => "badge badge-pro", :title => "#{user.part_name} is pro") if SSO.is_pro? user
I can access the locals via the local_assigns hash, so if I add these lines to the top, I have access:
user = local_assigns[:user]
extra_class = local_assigns[:extra_class]
I could live with that. However, it gets worse. user is an ActiveRecord model object. I cannot, however, access the attributes of this object with user.attribute notation. Instead I have to user user[:attribute].
I could still get by with this except that some of the attributes of user are actually methods, which I cannot access using user[:method].
I thought it might be the Rails, which was at 3.1.12 so I upgraded to 3.2.13 with no change.
Any ideas? Could it be the HAML processor? All other posts that were solved used ERB.
Try using this way for rendering partials (it's correct way for Rails 3):
= render 'user_name', user: item_user, extra_class: "active"
And access to objects using user and extra_class

Tire + Will_Paginate not taking Tire.options

I'm trying to integrate Tire into my site and I'm having difficulty with pagination. I've tried paginating the results outside of the context of Tire and will_paginate is working on that Array. However, when I try will_paginate within the context of Tire I'm having one large problem.
Will_Paginate will display the correct number of pages with consideration of :per_page but when I click on that page the results are not loaded, rather they are the same as on the first page. The page number is highlighted in the will_paginate navigation.
#results.inspect yields this:
#<Tire::Search::Search:0x007f88ab9153d0 #indices=["deja-set-development"], #types=[], #options={:load=>true, :page=>1, :per_page=>2}, #path="/deja-set-development/_search", #query=#<Tire::Search::Query:0x007f88ab915088 #value={:query_string=>{:query=>"oh"}}>, #facets={"type"=>{:terms=>{:field=>:_type, :size=>10, :all_terms=>false}}}>
Here is where I call will_paginate:
= will_paginate #search_results.results, params
Here is where I iterate through the results
#search_results.results.each
Does anyone have any thoughts?
Edit ---
I'm not sure what is going on, but I did this and it is working.
#search_results = #search_results.paginate(:page => params[:page], :per_page => 5)
Please see the integration test in Tire, and make sure you're passing all options properly.
So to clarify, I've attached my github correspondence with #karmi here.
https://github.com/karmi/tire/issues/627#issuecomment-13449368
I was using Tire.search as opposed to searching by model. As #karmi notes, at the moment :per_page and :page are not supported with Tire.
Here is how I solved this:
#search_results = Tire.search [:index1, :index2, :index3], :load => true, :from => from, :size => size do
query do
string q, :default_operator => 'AND', :fields => [:name1, :name2]
end
end
I ended up having to spin my own small pagination system to increment 'size' and 'from'. Here's the elasticsearch link on the topic.
http://www.elasticsearch.org/guide/reference/api/search/from-size.html
You're able to still access
= #search_results.results.total_entries/next_page/previous_page
which helps with pagination.
Thank you again #karmi.

How to paginate with act_as_api rails 3?

Hi I'm using act_as_api to render my xml and json, all is well until i want to add the will_paginate fields into my outputs.
Has anyone been successful?
Found the solution in one of the feature requests for acts_as_api gem
format.xml { render_for_api :template,
:xml => #posts ,
:root => :posts,
:meta => {:current_page => #posts.current_page,
:total_pages => #posts.total_pages,
:per_page => #posts.per_page }}
So there you have it, with meta support, you can add whatever you want, in this case I wanted my pagination data in there.
Metadata support - Add pagination fields
as of today, there is a wiki entry about this topic on github:
https://github.com/fabrik42/acts_as_api/wiki/Add-meta-data-%28like-pagination-info%29-to-your-response

Thinking Sphinx text search

Hi people I'm having a problem with one search that I'm making in one of my projects. I am new using Sphinx and the problem is when I make a search like = "ipad" it work perfect but when I put "ipa" the full text search seems no to work the way I want cause I'm not receiving anything back.
my_variable = self.search searchTxt, :match_mode => :any, :sort_mode => :extended, :order => sortType, :page => page, :per_page => perPage
Am I doing something wrong with the search?
I think there is some additional configuration necessary to search with wildcards, as explained in the documentation.

memorable name generator gem for ruby

Before I go roll my own and start pulling out the dictionary, does anyone know a rubygem to generate memorable names suitable for app keys. I need something pronounceable so that I can give users unique email addresses to submit content to. I like Heroku's naming for it's apps as an example.
floating-sky-58
simple-fog-45
I just did an implementation of this for a project and my solution was to use the Forgery gem and something like this:
[Forgery::Basic.color, Forgery::Address.street_name.split(" ").first, rand(100)].join("-").downcase
This results in strings like this:
=> "orange-nobel-93"
=> "indigo-holmberg-41"
=> "khaki-sunfield-31"
=> "goldenrod-warrior-92"
=> "fuscia-manley-75"
=> "violet-village-17"
=> "violet-west-11"
=> "goldenrod-oak-74"
=> "yellow-hermina-74"
=> "red-shopko-36"
=> "purple-esch-43"
=> "teal-sutherland-44"
=> "blue-butterfield-56"
=> "yellow-mcbride-41"
You can use randexp gem. It's use the dictionnary from your OS ( UNIX only )
with randexp gem you can do something like :
/[:word:]-[:word:]-\d+/.gen
and have like heroku naming.
If your server has no dict library install you can try faker or Lorem
but really much limitated.
Take a look at my gem, does exactly this
gem 'bazaar'
Bazaar.heroku
=> "inquisitive-cavern-6617"
=> "jubilant-sunset-9301"
=> "frightened-geyser-4542"
https://rubygems.org/gems/bazaar
The haikunator gem is a good choice.

Resources