Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL 2005 Full-Text-Search: How to default all user search words to a CONTAINS NEAR type FTS search
    primarykey
    data
    text
    <p>I have an asp.net web page with a simple search text box that returns matching rows from a MSSQL 2005 database. It is currently using a LIKE statement to bring back matches, but forces the user to to type an exact phrase. Users want a more Google search type experience and so I have decided to set up and index the needed tables with FTS.</p> <p>I would like the users search word or words to be used in a CONTAINS search with NEAR separating each word they type into the text box. I'm a new developer and do not know how to do this, or if there is already a built in function to cover this.</p> <p>So for example, if a user types "Sawyer Tom" into the search box the query should function like this:</p> <p>SELECT BookID, BookTitle FROM tblBooks WHERE CONTAINS(BookTitle, 'Sawyer NEAR Tom')</p> <p>And return:</p> <p>12032 The Adventures of Tom Sawyer</p> <p>Currently using the like statement I have now the user search would find no matches.</p> <p>If the user types simply Sawyer the query should function simply like this:</p> <p>SELECT BookID, BookTitle FROM tblBooks WHERE CONTAINS(BookTitle, 'Sawyer')</p> <p>Returning:</p> <p>12032 The Adventures of Tom Sawyer 72192 Roy Crane's Buz Sawyer: The War in the Pacific (Vol. 1)</p> <p>My current code just plugs in the search string into the query like this:</p> <p>SELECT BookID, BookTitle FROM tblBooks WHERE CONTAINS(BookTitle, @Search)</p> <p>Which obviously doesn't work. How can I separate each word automatically with NEAR?</p> <p>Thanks so much in advance for any help you can provide!</p> <p>-David</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload