SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast mitsy's Avatar
    Join Date
    Jul 2006
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    good search query

    hello,
    let's say our database has an entry "hello world".
    i need a mysql select query which must match "hello world":

    when searched for "hello"
    when searched for "hell"
    when searched for "hello earth"

    so can somebody write me an sql query which can meet these 3 points?
    thanks
    erdem

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    can't be done

    the first two will work with LIKE on the search string with a trailing wildcard

    the third won't work unless you split the search string up into individual words and test them separately, which leaves open the question as to why you would accept only a partial search string match
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Enthusiast mitsy's Avatar
    Join Date
    Jul 2006
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i need this because i have a gaming database which has less than 1000 entries. so when visitors search for a game title, they mainly enter wrong title and sees empty result. but the title exists with correct spellling.

    i mean the correct title is "space inpact" for example.
    and the visitor cant remember and mistakely searches for "space invasion"

  4. #4
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,653
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    You might want to try using whatever fulltext engine your database supports. That will at least catch some mispellings of other words.

    Another trick would be to use some ajax-style autocomplete to help spell for users.

    Insofar as autocorrection goes, the usual tactic is to track how users correct searches, then start feeding that back after users after you get enough data to have an accurate idea of mispellings.

  5. #5
    SitePoint Member
    Join Date
    Oct 2009
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Misty.
    I am new to Database world but I would like to suggest you something to try out.
    Just check this for your string.
    select * from table_name where column_name like search_string;


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •