Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Help with a searching a string within a specified word proximity Expand / Collapse
Author
Message
Posted Tuesday, November 8, 2011 3:52 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, September 16, 2014 2:36 AM
Points: 26, Visits: 109
Hi,

I'd be very grateful if someone could help me with this, I do hope someone can :) 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
Post #1201909
Posted Tuesday, November 8, 2011 3:11 PM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Tuesday, January 28, 2014 8:15 AM
Points: 3,065, Visits: 4,639
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.
Post #1202514
Posted Tuesday, November 8, 2011 7:20 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Yesterday @ 8:02 PM
Points: 35,397, Visits: 31,955
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."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1202587
Posted Wednesday, November 9, 2011 12:28 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, September 16, 2014 2:36 AM
Points: 26, Visits: 109
Answers available here.... thanks for the input

http://www.sqlservercentral.com/Forums/Topic1201910-391-1.aspx#bm1202127
Post #1202654
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse