views:

48

answers:

0

Hi,

I'm using Ultrasphinx for a fulltext search in a rails app. I encountered a very strange behavior. When I search my User model and search for q = "user" I get all the users as a result, even though some of them havent got the term "user" in any field.

What is going wrong here?

Heres my setup:

# models/user.rb
class User < ActiveRecord::Base
  # Ultrasphinx searching
  is_indexed :fields => ['created_at', 'name', 'about', 'login', 'website', 'location', 'total_favorited_count', 'total_votes_value', 'credibility']
end

# controllers/searches_controller.rb
class SearchesController < ApplicationController
  # GET /leafs/search
  def users
    # Do the search
    @search = Ultrasphinx::Search.new( :query => @search_query,  
      :page => (params[:page] || 1),
      :weights => {'login' => 2.0, 'name' => 2.0, 'about' => 1.0, 'location' => 1.0, 'website' => 0.5},
      :per_page => 20,  
      :class_names => ["User"], :search_mode => 'relevance' )  
    @search.run  
    @users = @search.results
  end
end

Terminal output

searching for {"indexes"=>"main", "class_names"=>["User"], "sort_by"=>nil, "parsed_query"=>"user", "sort_mode"=>"relevance", "filters"=>{}, "weights"=>{"name"=>2.0, "website"=>0.5, "about"=>1.0, "login"=>2.0, "location"=>1.0}, "per_page"=>20, "page"=>1, "query"=>"user", "location"=>{"units"=>"radians", "long_attribute_name"=>"lng", "lat_attribute_name"=>"lat"}, "facets"=>[]}