Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8219119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:02:59+00:00 2026-06-07T13:02:59+00:00

I have very large database and I’m use an advanced search form similar to

  • 0

I have very large database and I’m use an advanced search form similar to this railscast: http://railscasts.com/episodes/111-advanced-search-form-revised

Perhaps it’s a dumb question but imagine that you have 400,000 products (or more) that you are filtering with this chain of .where (and pagination).

products = Product.order(:name)
products = products.where("name like ?", "%#{keywords}%") if keywords.present?
products = products.where(category_id: category_id) if category_id.present?
products = products.where("price >= ?", min_price) if min_price.present?
products = products.where("price <= ?", max_price) if max_price.present?
products.page(params[:page])

As I see it the search executes the first condition, and then filters with the other where conditions so you’d have 400,000 products searched. Would that not kill performance, or am I totally (I wish) wrong?

Note: I also wrote asked this question on the railscast but, being an old railscasts, I don’t know if anybody will see the question there. For that reason I wrote here too.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T13:03:00+00:00Added an answer on June 7, 2026 at 1:03 pm

    just use an Hash from the parameters that comes from the form, it’s been a while since I’ve done and it and I dont even have the code anymore but in theory it should be like:

    finder = Hash.new
    params[:form].each {|index, val|
    finder[index] = val
    }
    

    that will create an Hash of all the parameters that have been passed and you can just pass that to the active record search like this.

    products = Products.where(finder)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very large set of string URL patterns like {http://www.imdb.com, http://www.amazon.com ,...}
I have a very large Oracle database, with many many tables and millions of
I have a very large UIView approx 3000x3000 in size. In this large view
Here is the main problem. I have very large database (25,000 or so) of
I have a very large database with about 120 Million records in one table.I
I have a very large table in my database and I am starting to
I have a very large database (~100Gb) primarily consisting of two tables I want
I have a very large table called paypal_ipn_orders . In this table I have
I use cucumber to run integration tests. I have a very large (30,000+ record)
We have a database with a very large amount of data in it (around

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.