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

  • Home
  • SEARCH
  • 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 6669225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:07:30+00:00 2026-05-26T03:07:30+00:00

I’ve used Ryan Bate’s search with Ajax episode to write some basic search functionality.

  • 0

I’ve used Ryan Bate’s search with Ajax episode to write some basic search functionality.

What it basically does is take a string from a form, and performs a like query via a model method. What I’m trying to do is conditionally search to different columns(due_date and name) in the database with a single string that I parse with the Date class. That way a user can search for items by a date, or the item name witht he same form. My method looks like:

def self.search(search) 
    if search
      search_date = Date.parse(search) rescue nil
    end

    if search_date
      where('due_date = ?', search_date)
    elsif search
      where('UPPER(name) LIKE ?', "%#{search.upcase}%")
    else
      scoped
    end
  end  

This works, as if the user types in a date, the Date class is able to parse it, an look in the database for any objects that have that due_date. The problem is, if it is a date and it’s able to be parse, the search is incredibly slow.

I was wondering if anyone had a way of speeding this up. Is it the Date class that is so slow? Should I have two different methods? or Should I completely rewrite my search?

  • 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-05-26T03:07:31+00:00Added an answer on May 26, 2026 at 3:07 am

    I really doubt it’s Date.parse being slow. You should check log/development.log to see what the query execution times are. What you’re most likely experiencing is a table scan because you’re missing an index on due_date.

    Always check slow queries using EXAMINE. An example:

    EXAMINE SELECT * FROM items WHERE due_date='2011-01-01'
    

    You’ll get some information on the number of rows it will have to sort through, plus any indexes that could be used.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
Does anyone know how can I replace this 2 symbol below from the string
I used javascript for loading a picture on my website depending on which small
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
Specifically, suppose I start with the string string =hello \'i am \' me And
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.