Wednesday, March 7, 2012

Find Exact word in Full-Text Search

Hi,

I have the fields like this.

Session1 Session2 Session3 Session4
---------------------------
SQL Server-Part1 SQL Server-Part2 ASP.Net CSS

C# SQL Server-Part3 ASP.Net Javascript

I have set the Full-Text to all the columns. For searching i wrote the below query

SELECT * FROM <TABLE NAME> WHERE CONTAINS(*,'"SQL Server-Part1"')

My Result expectation is: The First Record should come. But the result of the query bring the two records. It see the "SQL Server" string also. I need to find the exact word. How to do it?

Please answer me as soon as possible.


Ganesh.

Hi there,

Why don't you try this:

SELECT TOP 1 * FROM <TABLE NAME> WHERE CONTAINS(*,'"SQL Server-Part1"')

Hope this helps,

thanks,

Murthy here

|||

Murthy Puvvada:

Hi there,

Why don't you try this:

SELECT TOP 1 * FROM <TABLE NAME> WHERE CONTAINS(*,'"SQL Server-Part1"')

Hope this helps,

thanks,

Murthy here

Sorry, but I think that is bad sql advice!

There is no guarantee that the correct record will be returned first in the query. Next time, it could be the second record returned.

In fact, if there is no order by clause, the sql standard maintains that the order of records returned in indeterminate, meaning officially unpredictable. Any sub-sub-release of sql server (or any other sql database) is free to make internal performance enhancements that could result in the records being returned in a different order.


|||

On another note, I haven't used Full Text indexing yet. Sorry, I can'tgive definitive advice there. But I'm guessing, from the sample datathat you showed, that maybe some of the characters you typed are wildcards of some sort within the context of the Contains function. Beingignorant on Full Indexing, I would read up on the specifications forthe Contains function more carefully.

And why do you have both single and double quotes around the search string? It sure looks weird!

|||

Oh! No. I can not use SELECT TOP 1 . Because the table may have duplicate of the string in more than a time.

So, please give me the exact answer.

Thanks

|||

Again, you need to research the Contains function and what it does. It clearly brings back data that you do not expect it to.

Have you researched that function yet?

|||

I glanced at the online documentation for the contains function and the mdx language for the search parameter.

It looks like it treats a - character as an Except command in some circumstances. I noticed that you had a - in the text you were searching for.

Might want to do an experiment and see if that's the problem.

No comments:

Post a Comment