SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Help with a searching a string within a specified word proximity


Help with a searching a string within a specified word proximity

Author
Message
lewisdow123
lewisdow123
Valued Member
Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)

Group: General Forum Members
Points: 70 Visits: 135
Hi,

I'd be very grateful if someone could help me with this, I do hope someone can Smile I'll try and provide as much info as possible so to avoid confusion as to what my question is.

Client requirement: Client has a table that holds articles in one column, think of them as digital newspaper articles. They have a search webpage to find articles that match the user's keywords. Along with this search functionality the user can specify the proximity that the keywords must be from each other to qualify. Basically how many words (not characters) one word must be from the other to return true.

Search Example: If the user specifies 5 words apart and enters the search term as 'search word', then the query should return all rows where an article contains the words 'search' and 'word' and they are no more than 5 words apart.

Result example

True because only 2 words apart from each other: 'This is a search that has word in it'
False because 7 words apart from each other: 'The search will not come out true because the word is more than 5 words apart.'

Added complexity 1: This seems reasonable enough however there is the added complexity that you could have more than two search keywords, in which case they must all be within the specified word proximity.

Added complexity 2: The whole article must be searched not just the first occurance of a keyword.

i.e. if we use the example:

Search keyword: 'search word' within 5 words...
Article: 'The search will not come out true because the word is more than 5 words apart. But this is a search that has word in it.'

The above is true because the second sentence contains the keywords within 5 words proximity even if the first sentence did not.

I know that Full Text Search has the ability to use the operator NEAR however in 2008 you can not set a proximity limit that the words must be from each other. I know that 2012 does but because I am running on 2008 I need to find a way to programatically do this.

Please oh please can someone help me. Right now I am stuck and do not know how to do this.

Many thanks in advance, :-)

Lewis
PaulB-TheOneAndOnly
PaulB-TheOneAndOnly
SSChampion
SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)

Group: General Forum Members
Points: 13525 Visits: 4639
Nice one.

I would probably...

1- Parse the text string picking up every single word.
2- Assign a sequence number to every single word - I think a temp table would do it nicely.
3- Search on the sequence/word temp table
4- Check how far words are - apply whatever logic goes there
5- Reach for the bottle of brandy-celebrate! ;-)

_____________________________________
Pablo (Paul) Berzukov

Author of Understanding Database Administration available at Amazon and other bookstores.

Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (206K reputation)SSC Guru (206K reputation)SSC Guru (206K reputation)SSC Guru (206K reputation)SSC Guru (206K reputation)SSC Guru (206K reputation)SSC Guru (206K reputation)SSC Guru (206K reputation)

Group: General Forum Members
Points: 206675 Visits: 41960
You could spend a whole lot of time and money on this. For example, what is a word? As well as the normal "separated by spaces" requirement, what if there is a double space somewhere? Will hyphens, carriage returns, parenthesis, brackets, braces, and other special characters be treated as spaces?

My recommendation is to NOT redevelop the proverbial wheel. See the following product, please. And, no, I don't work for them. :-)
http://www.dtsearch.com/

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
lewisdow123
lewisdow123
Valued Member
Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)Valued Member (70 reputation)

Group: General Forum Members
Points: 70 Visits: 135
Answers available here.... thanks for the input

http://www.sqlservercentral.com/Forums/Topic1201910-391-1.aspx#bm1202127
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search