I have a Wallet model with two fields user_id of type integer and balance of type floating point and have configured solr search on Wallets.
There are chances of wallet balance being negative value.
Below are the code blocks :
Wallet.rb
searchable do
text :balance
text :user do
user.name
end
end
WalletsController.rb
def index
@search = Wallet.search {
fulltext params[:search]
paginate :page => params[:page], :per_page => 10
}
end
Wallets/index.html.erb
<%= form_tag wallets_path, :method => :get do %>
<%= text_field_tag :search, params[:search] %>
<%= submit_tag "Search" %>
<% end %>
With this above implementation the search is returning incorrect records on searching for Wallets having negative balance.
Ex:
search : 30
results : 30, -30search : -30
results : -100, 500 (Wallets without balance = 30/-30 are returned)
Can someone provide an efficient logic to get this working?
Either solr configuration has to be changed to not consider "-" as special character or the search term needs to be changed and passed on to Sunspot.