I have developed an application with rails and solr sunspot full text search.
Here users can post a topic. And the user need to wait for approval of the post from the administrator.
Eg: If a user post a topic in domain.com
and the approval is made from admin.domain.com
@search = Post.where(status: 1).search do
fulltext params[:search] do
minimum_match 1
end
with :status, 1
paginate page: params[:page], per_page: 15
end
@posts = @search.results
Unless admin approve the post status will be 2
. In administrator if I change the status from 2 to 1 from admin I could not find the result. How can I interlink with it.
How can I handle this kind of problem. Can any one help
Edit-1
I am going to make this as a bounty question. I am facing lot of difficulty with this. Can any one solve this with better solution else anyone know any other way of performing such a search
If you have 2 applications, I presume they used same database but only your main app use sunspot.
The problem is when an admin update an object this object is not reindexed in sunspot/solr.
Option 1 Add sunspot on your admin app with same searchable block for concerned models, and used same solr server configuration.
Option 2 Create a custom controller method ( like an api ) on your main app. This method forces reindex of an object like
Sunspot.index Post.find(params[:id])
After each update on a Post on your admin app, you need to call reindex post method of your main app.Option 3 (easiest) Remove your scope on :status like this :
Edit
This update add more informations for use option 1 :
I create an application with one model : Article
I want to show all articles on my admin app and only articles with status=1 on my user app. Both applications use same database and same solr server.
Configuration for both applications
I use sunspot_rails(https://github.com/sunspot/sunspot) and sunspot_solr for this test.
Note : I launch solr only one time on user app with this command
Article controller for admin app
I want to show all articles on my admin app like this :
Article controller for user app
In my user app, I just want to see articles with statuts == 1
Now when I use my admin app, and I update an article's status solr is updated simultaneously. And if I refresh my articles index page on my main app, this article appears.
I hope you have more informations now.