Thinking_Sphinx working in console but not in Rails application
Environment Rails 3.0.4, Ruby 1.8.7, Sphinx 0.99, Dreamhost VPS
I have a simple blog search set up as follows:
Controller:
def blog_search_results
@blog_search_results = BlogPost.search( params[:search_param] )
respond_to do |format|
format.html { render :partial => 'blog_search_results', :layout=>false }
format.xml { render :xml => @blog_search_results }
end
end
View:
<% if !@blog_search_results.empty? %>
<div id="main_content">
<table id="pending_blog_list"><tr id="header"><td>Blog Title</td><td>Created by</td><td>Created on</td></tr>
<% @blog_search_results.each do |blog_post| %>
<tr>
<td><%= link_to blog_post.title, blog_named_link(blog_post, :show) %></td>
<td><%= blog_post.posted_by.display_name -%></td>
<td><%= blog_post.created_at.strftime("%x") -%></td>
</tr>
<% end %>
</table>
<%= will_paginate(@blog_search_results, {:form_name => :blog_show_params, :param_name => :page} ) %>
</div>
<% else %>
<h2>No blog posts that match your search were found</h2>
<% end %>
Everything works perfectly in my development environment. In the production environment, when I launch a console ("rails c production") and type:
irb(main):003:0> BlogPost.search("video")
I get the expected 4 results of posts with the word 'video'. However in the actual app, the controller keeps returning a '404 Not Found'
Started GET "/blog_posts/blog_search_results?search_param=video"
Processing by BlogPostsController#blog_search_resul as HTML
Parameters: {"search_param"=>"video"}
Completed in 27ms
Rendered layouts/application.html.erb (22.3ms)
Rendered public/404.html within layouts/blog_posts (24.7ms)
My sphinx.yml setup is as follows:
staging:
pid_file: '/www.assetcorr.com/current/log/searchd.pid'
searchd_file_path: 'www.assetcorr.com/shared/db/sphinx'
bin_path: '/home/avitus/local/bin'
I see the index in the in the shared/db/sphinx folder. It appears after I run ts:index. The searchd.pid file is in the log folder and the PID matches the searchd daemon. The bin_path is correct and I've added it to the path in the .bash_profile file.
Does anyone have any ideas what could be causing this?
-- UPDATE --
It look as though the reason this isn't working is that the control开发者_开发技巧ler method is being accessed via an AJAX call:
$(document).ready(function() {
$("#search_param").observe_field(0.5, function( ) {
$.get("/blog_posts/blog_search_results", { search_param: this.value },
function(data){
$("#search_results").html(data);
}, "html");
});
});
});
When I remove the AJAX call and resort to a plain vanilla GET request then it works perfectly. I have no idea why that would be.
The problem is with the path of the Thinking Sphinx. I hope you are running on Passenger. please specify the path in sphinx.yml(what ever is your sphinx config yml file)
精彩评论