Help with a searching a string within a specified word proximity

  • 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

  • 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.
  • 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.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Answers available here.... thanks for the input

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

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply