Showing posts with label clause. Show all posts
Showing posts with label clause. Show all posts

Wednesday, March 21, 2012

funny search results with 'contains' clause

hi,
it is really funny how ft search works:
it seems to depend highly on what could be indexed, but it still doesn't
follow a determined order.
consider the following queries:
select name from person where contains(name, 'hammer')
select name from person where contains(name, '"hammer*"')
the first is a query with a "simple term" and the second one with a
"prefix term".
mssql docu says that a simple term "specifies a match for an exact word",
but the first query returns other matches like "oberhammer" or
"hammerschmied" - this is not an exact match for me; the found words
rather consist of two words "ober", "schmied" and "hammer".
one would expect that the 1st and 2nd query work absolutely different but,
even the 2nd returns a lot more results, they seem to differ just slightly.
when searching for 'ober' (instead of 'hammer'), the 2nd query returns
"obermayr" and "oberlehner", but the 1st results only in "oberlehner",
although "ober", "mayr" and "lehner" are single words themselves.
and why does it find "Tober" or "Dober" if i only searched for 'ober'?
i need to know the rules which mssql uses for fulltext search. can someone
point me to a book or a website where i can find more information? or does
somebody have a good explanation?
btw, we use sql2000 and a german collation.
klaus triendl
unfortunately this behavior is caused by the German wordbreaker. You might
get better results with the neutral word breaker.
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"klaus triendl" <triendl.kj@.m-box.at> wrote in message
news:opsmm8g1r7cm4gx4@.dev4xp.wasser.local...
> hi,
> it is really funny how ft search works:
> it seems to depend highly on what could be indexed, but it still doesn't
> follow a determined order.
> consider the following queries:
> select name from person where contains(name, 'hammer')
> select name from person where contains(name, '"hammer*"')
> the first is a query with a "simple term" and the second one with a
> "prefix term".
> mssql docu says that a simple term "specifies a match for an exact word",
> but the first query returns other matches like "oberhammer" or
> "hammerschmied" - this is not an exact match for me; the found words
> rather consist of two words "ober", "schmied" and "hammer".
> one would expect that the 1st and 2nd query work absolutely different but,
> even the 2nd returns a lot more results, they seem to differ just
slightly.
> when searching for 'ober' (instead of 'hammer'), the 2nd query returns
> "obermayr" and "oberlehner", but the 1st results only in "oberlehner",
> although "ober", "mayr" and "lehner" are single words themselves.
> and why does it find "Tober" or "Dober" if i only searched for 'ober'?
>
> i need to know the rules which mssql uses for fulltext search. can someone
> point me to a book or a website where i can find more information? or does
> somebody have a good explanation?
> btw, we use sql2000 and a german collation.
>
> --
> klaus triendl
|||klaus,
Could you post the full output of the below SQL code as it is most helpful
in troubleshooting SQL FTS issues.
use <your_database_name_here>
go
SELECT @.@.language
SELECT @.@.version
sp_configure 'default full-text language'
EXEC sp_help_fulltext_catalogs
EXEC sp_help_fulltext_tables
EXEC sp_help_fulltext_columns
EXEC sp_help <your_FT-enable_table_name_here>
go
Specifically, the OS-supplied and language-specific wordbreaker along with
the actual text (single language or mixed?) you are storing in your
FT-enabled table's column is most important information!
Thanks,
John
SQL Full Text Search Blog
http://spaces.msn.com/members/jtkane/
"klaus triendl" <triendl.kj@.m-box.at> wrote in message
news:opsmm8g1r7cm4gx4@.dev4xp.wasser.local...
> hi,
> it is really funny how ft search works:
> it seems to depend highly on what could be indexed, but it still doesn't
> follow a determined order.
> consider the following queries:
> select name from person where contains(name, 'hammer')
> select name from person where contains(name, '"hammer*"')
> the first is a query with a "simple term" and the second one with a
> "prefix term".
> mssql docu says that a simple term "specifies a match for an exact word",
> but the first query returns other matches like "oberhammer" or
> "hammerschmied" - this is not an exact match for me; the found words
> rather consist of two words "ober", "schmied" and "hammer".
> one would expect that the 1st and 2nd query work absolutely different but,
> even the 2nd returns a lot more results, they seem to differ just
slightly.
> when searching for 'ober' (instead of 'hammer'), the 2nd query returns
> "obermayr" and "oberlehner", but the 1st results only in "oberlehner",
> although "ober", "mayr" and "lehner" are single words themselves.
> and why does it find "Tober" or "Dober" if i only searched for 'ober'?
>
> i need to know the rules which mssql uses for fulltext search. can someone
> point me to a book or a website where i can find more information? or does
> somebody have a good explanation?
> btw, we use sql2000 and a german collation.
>
> --
> klaus triendl
|||I am raising a support incident on this one Klaus.
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"Hilary Cotter" <hilary.cotter@.gmail.com> wrote in message
news:u3I$G3ZGFHA.4004@.tk2msftngp13.phx.gbl...[vbcol=seagreen]
> unfortunately this behavior is caused by the German wordbreaker. You might
> get better results with the neutral word breaker.
> --
> Hilary Cotter
> Looking for a SQL Server replication book?
> http://www.nwsu.com/0974973602.html
> Looking for a FAQ on Indexing Services/SQL FTS
> http://www.indexserverfaq.com
> "klaus triendl" <triendl.kj@.m-box.at> wrote in message
> news:opsmm8g1r7cm4gx4@.dev4xp.wasser.local...
word",[vbcol=seagreen]
but,[vbcol=seagreen]
> slightly.
someone[vbcol=seagreen]
does
>

Monday, March 19, 2012

Function with EXECUTE problem

Hello,

I'm running into some trouble writing a function that returns a table. I'm using OPENQUERY in the FROM clause to fetch data from a remote server (ORACLE). Because the query must be dynamic, I have to execute it using the EXECUTE command.

Basically, I first dynamically create a string containing my query and then I execute it by calling the EXECUTE function and passing my string as an argument.

Now, I'd like my function to return what's produced by the EXECUTE call. Here's how I wrote the function declaration:

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

CREATE FUNCTION [dbo].[beh_GetRemoteData] (@.STARTDATE varchar(20), @.POS int, @.ID_ANALOG varchar(10))
RETURNS @.RET TABLE (HIST_TIMESTAMP DATETIME, ID_ANALOG INT, STATUT INT, QUALITY INT, VALUE NUMERIC(12,5)) AS
BEGIN
DECLARE @.REMOTEQUERY varchar(300)
DECLARE @.LOCALQUERY varchar(400)

--======== Create remote Query =======--
SET @.REMOTEQUERY = 'SELECT * FROM [...]'


--======== Create local Query =======--

SET @.LOCALQUERY = 'SELECT [...] FROM OPENQUERY(REMOTE_SERVER, ''' + @.REMOTEQUERY + ''')'

INSERT INTO @.RET
EXEC(@.LOCALQUERY)

RETURN
END

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Of course, this doesn't even passes the "Check syntax" because the EXEC statement cannot be used as as source when inserting into a table variable. This might be but it's EXACTELY what I want to do.

Any ideas on how I should write my function?

Thanks,

Skip.According to my reading of books on line for SQL Server 2000 you can't execute anything other than an extended stored procedure inside a function anyway - and those can't return results sets. Therefore, you can't use dynamic sql either.

Friday, February 24, 2012

Full-Text Search gets syntax error and kills the transaction

I am having problems with syntax errors being generated from the search clause of a full-text search. When the syntax error is raised, the batch and transaction are stopped. Placing the search within a SQL Try/Catch allows the batch to continue, but the transaction is uncommitable.

I need to trap and handle the full-text search syntax error then control the commit or rollback of the transaction based on other transactions.

Below is a simplified version of the type of logic I am working with. The XACT_STATE goes to -1 because of the syntax error generated by the full-text search. This forces a rollback of the whole transaction.

Declare@.sSearch NVarChar(50)

/* @.sSearch is passed by a web page and could come back empty or with an invalid Full-Text search clause*/

Begin Transaction

Begin Try

Print XACT_STATE()

Select*

/*The table 'KnowledgeBase' is a table with a populated Full-Text Search*/

FromContainstable(KnowledgeBase,*,@.sSearch)

End Try

Begin Catch

Print XACT_STATE()

Print 'Number- ' + Convert(VarChar,ERROR_NUMBER()) + ', ' +

'Severity- ' + Convert(VarChar,ERROR_SEVERITY()) + ', ' +

'State- ' + Convert(VarChar,ERROR_STATE()) + ', ' +

'Message- "' + ERROR_MESSAGE() + '"'

End Catch

/*Some other logic would be here*/

Commit Transaction

I'm moving this post to the Transact-SQL forum because it's a better venue for code-related questions.

Regards,

Gail