0

I'm trying to select a 255 characters max from a text and returns only the substring containing the matched words a user is looking for or the first one.

This is a script for a search engine in my site where results preview only posts containing the set of words the user is searching.

Here is an example for a preview:

  A user type in search box "manufacturing companies"

 ...visited the campus to announce the creation of a new public-private **Manufacturing** Innovation Institute that will soon take up residence at NC State. Eighteen **companies** headquartered in North Carolina will partner...

In case there are more coincidences, select only the substring that contains more words matched.

How can I accomplish this within a query?

Thanks.

Apalabrados
  • 1,098
  • 8
  • 21
  • 38
  • SQL (and even regular expressions) are not suited for this task, particularly the part about getting the substring with 255 characters that has the most matches. – Gordon Linoff Jan 19 '14 at 17:43
  • `select REGEXP_REPLACE() from where REGEXP_LIKE()` is supported by multiple SQL DBs, for MySql - You'll need a plugin/module: http://stackoverflow.com/questions/986826/how-to-do-a-regular-expression-replace-in-mysql, once You install those and read the manuals - show some effort of trying to acheive it on Your own (as required by StackOverflow rules to avoid down-votes)
    – Vlad Jan 19 '14 at 20:07

0 Answers0