I'm working with thinking sphinx
define_index do
indexes to
indexes created_on
has created_on
end
now while searching on console
Emaildumps.search 5.day.ago,
:group_by => 'created_on',
:group_function => :day
now the error i get is
Sphinx Daemon returned error: index emaildumps_core: INTERNAL ERROR: incoming-schema mismatch (in=timestamp created_on:32#160, my=timestamp created_on:32#0)
it may be a dumb question but i'm a newbee at sphinx and i can't understand the fundamentals of indexing and searching in it
what am I doing wrong??
so please help me out.
It's perhaps related, but you can't have fields and attributes with the same name. So, I'd recommend aliasing one of those (the field is better):
define_index do
indexes to
indexes created_on, :as => :created_on_field
has created_on
end
That said, not sure if there's much value in having created_on as a field, but up to you.
Related
UPDATE:
Ok so I am no longer getting an error, but I am not getting any results back (even when there is only one search option).
I added the has clause to my list of indexes:
define_index do
has bar_profiles(:day), :as => :days
indexes bar_profiles.budget, :as => :budget_tags
.
.
end
So my search is:
bars = Bar.search(search_options)
with
search_options = {:conditions=>{:budget_tags=>"LOW BUDGET"}, :with=>{:days=>"thursday"}, :page=>1, :per_page=>20}
bar_profiles has rows for budget, experience, tags, day, etc.
Bar has many bar_profiles (potentially 1 for each day)
What I am trying to do is use the thinking sphinx search (in the bar model) to match the users selected criteria for budget, experience, tags against the bar_profile that has the day that matches with "today" (the current day).
This is the last thing I have to do to finish this app and I'm pulling my hair out cause I can't find any examples of how to set this up right...
If you have any insight please post it, anything helps. Thanks.
At first I thought my question was similar to this with an extra layer of abstraction, but I think my problem is with the search options not the indexing.
First off let me state that I have been having the worse time trying to fix a previous' groups implementation using thinking sphinx. I have finally got the project 90% working and the last 10% deals with being able to get the right filters to check against.
Here is a brief overview. The application has bars and bar_profiles (amongst many other tables that connect to these 2, and users, but they are not necessary to understand this issue.) There can be a bar_profile for each day of the week, for each bar.
So in the bar_profile model there is:
belongs_to :bar
and in bar there is:
has_many :bar_profiles
followed by the indexes in bar (written by the previous developer):
define_index do
# name is a reserved keyword so we need to specify it as a symbol to work
indexes :name
indexes tags
indexes bar_profiles.day, :as => :day
indexes bar_profiles.tags, :as => :daily_tags
indexes bar_profiles.budget, :as => :budget_tags
indexes bar_profiles.experience, :as => :experience_tags
set_property :delta => true
end
The issue I am having is this current implementation does not constrain the search properly to the current day. Instead of checking the current days profile for the bar, it seems to be checking against ALL the bars profiles.
So I set the current day at the start of the method:
today = (Time.now + Time.zone_offset('EST')).strftime("%A")
Then I think it needs to be something like below. I referenced this post by pat about using 'with', but I am not sure if I am messing up the syntax (because I am getting an error):
search_options = {:conditions => {}, :with => {:day=>today}, :page => 1, :per_page => algorithm.results_per_page}
Then I use these search options:
search_options[:conditions][:experience_tags] = options[:experience] unless options[:experience].blank?
budget = combine_budgets(options[:budget])
search_options[:conditions][:budget_tags] = budget unless budget.blank?
But when I try to run the search I get this in my development log:
^^^^ ERROR! Reason: index bar_core,bar_delta: no such filter attribute 'day'
Now I am pretty confused by this since the index for :day was set up as shown above... I'm not sure if 'filter attribute' is different then an index attribute. If someone could please offer some insight into this it would be greatly appreciated (looking at you #pat).
This is the final issue in this app, so if anyone can help me I would be very grateful.
Thanks,
Alan
I am facing problem in thinking sphinx
What i have following table structure
title => varchar
desc => varchar
is_deleted => boolean
Here is my denine_index
define_index do
indexes title, :sortable => :insensitive
has :is_deleted, :type=>:boolean
where "is_deleted = false"
set_property :delta => true
end
Here when I edit the topic and search it with edited name, I get the topic and when I search it with old name I get the same topic. For eg if earlier topic had name "Foo" and I renamed "Foo" to "Woo", on searching "Woo" I get "Woo", but on searching "Foo", I again get "Woo". Moreover when I set is_deleted => true and search "Woo" I don't get anything, but on searching "Foo" again I get "Woo". I can't understand why it is happening? Does sphinx don't delete the older index on creating newer index for delta=true.
Again on rebuilding sphinx, i don't get such problems, and all delta is set to false as expected.
Use sphinx sql_query_killist to kill results from main index when you know it exists in your delta index similar to these: http://sphinxsearch.com/docs/1.10/conf-sql-query-killlist.html
i have this:
User model
define_index do
indexes username
indexes [contact.last_name,contact.first_name] ,:sortable => true,:as=>:user_full_name
#no results
indexes profiles.working_experiences.job_title,:as=>:user_job_title
end
I never get results for job_title...
What i missing here?
1) Check your associations through the models
2) Make sure you reference :user_job_title in the search command, not job_title as you are aliasing it
What should I do to speed up Sphinx indexing (using MySQL)?
Should I use other database, noSQL database?
Note also that delta indexing is fast, only a full reindeinx process is slow.
Please explain in details. Thx!
UPDATE:
I'm reindexing over 100.000 items and my thinking-sphinx index definition looks like this
define_index do
indexes [text, user(:nickname), user(:full_name)]
has rewrites(:id), :as => :rewrite_id
has rewrites(:user_id), :as => :rewrite_user_id
has [rewrites(:user_id), user_id], :as => :user_id_or_rewrites_user_id
has comments(:user_id), :as => :comments_user_id
has simbols(:id), :as => :simbol_ids
has followings(:follower_id), :as => :follower_id
has follows(:followable_id), :as => :followable_id
has created_at, :sortable => true
has rewrites_count, :sortable => true
has relevance, :sortable => true
has user_id
set_property :delta => :datetime
end
Building a full index is slow. How slow?
Building a delta index is fast.
This sounds normal in my experience.
noSQL databases (last I heard #Rails 2.3.5) were kind of difficult to integrate with Rails. No SQL speeds depend on your data sets and relations.
Without more information this sounds normal.
== Edit ==
Make sure you have SQL indexes on
created_at
rewrites_count
relevance
in addition to your primary keys naturally.
When working with thinking_sphinx always look at the SQL it generates in the real sphinx configuration file. Run a query analyzer against all the queries it will run. I have found you can also manipulate the queries quite a bit.
Also for one to many relationships you may need to add this:
:source => :ranged_query
It will cause the sphinx to use a separate query to gather the children rather than an outer join. It is much faster in many cases.
how about using Real Time indexes (with adjusting appropriate memory limit)
I have model Products with columns:
name, number, description
Index defined for this model looks like this:
define_index do
indexes :name, :sortable => true
indexes :number
indexes :description
where "amount > 0"
has :price
end
Since in description can be lots of random words I want to exclude it from searching sometimes (when user clicks chceckbox 'don't search in descriptions').
I went to the sphinx page and found following:
#(name, number) *pencil* *123*
And it seems like I don't understand how sphinx works. When I execute search
*pencil* *123*
word 'pencil' is found in name and '123' is found in number and I get 1 result. But when I execute
#(name, number) *pencil* *123*
no results are found.
Is searching by columns somehow different?
You can only search on fields when using the :extended match mode - Thinking Sphinx sets this automatically if you use :conditions - but you're constructing a multi-field query yourself, hence why this isn't happening. Try this:
Product.search "#(name, number) *pencil* *123*", :match_mode => :extended
Hope this helps.
It was all about spaces :/
This works:
#(name,number) *pencil* *123*