1

I haven't ever dug into cleaning/reformatting search queries too much in the past, at least not more than general security things like preventing sql injection.

I am realizing that I should be implementing keywords like AND, OR, NOT, etc... and doing things like clearing punctuation such as apostrophes, hyphens, etc... As when a user types "Smiths" in a searchbox, the query would not return "Smith's" (with an apostrophe).

What other things can I do to improve my user's search queries (without being damaging to them)?

I am coming from a PHP MySQL-FTS setup; however, I'm sure that this could be extended to multiple platforms.

EDIT

Let me clarify that I'm not so interested in the SQL query to the database, what I'm interested in optimizing is the query that the user provides in the search box.

Community
  • 1
  • 1
bimbom22
  • 4,510
  • 2
  • 31
  • 46
  • FTS moderately transferrable between database vendors - the keywords are mostly identical, but syntax can be slightly different. You could look at 3rd FTS like Sphinx to make FTS more portable. – OMG Ponies Jul 09 '10 at 19:22
  • That's not actually what I'm asking. I'm wanting to know what else I should do to *the query that the user provides*, not the query to the database. – bimbom22 Jul 09 '10 at 19:31
  • Your title is wrong. Improving Search Queries = Query optimization. – Susheel Javadi Jul 09 '10 at 20:00

2 Answers2

1
  • NEAR keyword
  • double quotes for "exact phrases"
  • remove short/common words ("a", "an", "the", etc)
  • stemming (remove common prefixes and suffixes)

I'd suggest reading through the answers to this similar question: Optimizing a simple search algorithm and also this article on some of Google's features.

Community
  • 1
  • 1
BenV
  • 12,052
  • 13
  • 64
  • 92
0
  1. Create an index on the "where" clause columns of your search queries.
  2. To enable naive spell Correction perhaps, you could also store the soundex of the column you would like to offer spell-check for.
  3. Enable logging for slow-queries which would help you in tracking down performance issues.
Susheel Javadi
  • 3,034
  • 3
  • 32
  • 34