0

I've three tables say brands,sites and item categories. I want to perform search functionality in all the three tables simultaneosly. I've used solr to perform searching. Previously I was doing search one at a time. That means if the user enters 'adidas' then I was searching in brands table if didn't get then I was searching in sites table and so on. Based on the obtained results I was searching in some other table say main_nav_url using that brand_id or site_id or category_id and getting the required columns from main_nav_url table. Later on I came across this conflict like if the 'adidas' name is present in both brands and sites table I was getting only the search results of brands.

Please help me to solve this issue where I can search in all the three tables simultaneously,based on the result obtained extract their brand-id and site_id category_id, and perform One more search in main_nav_url table.

1
  • hello are see "Ransack gem " search gem it help to search data with multipale table at time using "Advance search query". please see tutorial on rails cast : 370. Apr 23, 2013 at 5:57

1 Answer 1

0

I got the answer.

Perform solr search separately to retreive their brand_id,site_id and category_id. Store the corresponding ids in an array. For example

@storesearch.results.each do |result|
    siteids << result.id
end

Depending on the length of brandids,siteids,catids perform the solr search in main_nav_url table. In this case have to perform solr search for 9 different cases. 1 of the cases is shown below.

if(siteids.length == 0 && brandids.length != 0 && catids.length != 0) @searchresults=MainNavigationUrl.search do any_of do with :brand_id, brandids[0..brandids.length] with :main_category_id, catids[0..catids.length] end end

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.