Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / Other Technologies / Full-Text Search / July 2006

Tip: Looking for answers? Try searching our database.

Strange result : contains() returns less rows than like '%xxx%'??

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Peter van Wilrijk - 18 Jul 2006 15:28 GMT
Hi,

I have a table ADSFULL containing ADVERTISMENTS with a FTI index on 2 fields
FADS_TITLE and FADS_TEXT (see script at the end).

--
The following query returns 94 rows.

SELECT fads_title, fads_text
FROM VWADS
WHERE (ADS_ADID IN (SELECT FADS_ADID FROM ADSFULL WHERE (CONTAINS(*,
'"twingo"') ) ) )

(To be clear VWADS is a view, joining the table ADS and ADSFULL, having a 1
on 1 relation via the fields
ADS.ADS_ADID and ADSFULL.FADS_ADID)

--

I see there are some rows containing the word (colour) beige.
So the following query returns 2 rows.  That's fine.

SELECT ads_adid, fads_id, fads_adid, fads_title, fads_text
FROM VWADS
WHERE (ADS_ADID IN (SELECT FADS_ADID FROM ADSFULL WHERE (CONTAINS(*,
'"twingo"') ) ) )
AND fads_text like '%beige%'

45592 45234 45592 Renault Twingo initilal cuir beige et jantes initiale,
bleu métal superbe voiture a saisir
11947 11700 11947 Renault Twingo Initiale, ... 2001, full options, toit
panoramique, cuir beige, airco, couleur champagne, jantes, installation cd,
80.000 km, carnet, ct ok, coup de coeur assuré

--

But when I try to achieve that with my FTI using the following query,
SQL Server returns NOT TWO BUT ZERO ROWS

SELECT ads_adid, fads_id, fads_adid, fads_title, fads_text
FROM VWADS
WHERE (ADS_ADID IN (SELECT FADS_ADID FROM ADSFULL WHERE (CONTAINS(*,
'"twingo" AND "beige"') ) ) )

--

I've already rebuild the FTC, but that does not solve this mistery.  Is
there a logical explanation that I don't see?

Any help really appreciated.

PS:
I've read timestamp isn't really convertible to datetime, but can the
timestamp tell me when the FTI for the two rows above was updated in order
be sure the words beige where not added after the rows where indexed?
Can I get a list of all words that have been indexed?
Can I see for each word how many times they appear in the table?
and ...
Is there a command that tells me which noise word file my FTI is using?
I've got 2 FT indexed databases with same tablestructure, one storing dutch
and one storing french content,
but I guess they both use the same (english) noise word file?

Thanks a lot,
Kind regards,
Peter Van Wilrijk.

--
The script
--

CREATE TABLE [dbo].[ADSFULL] (
[FADS_ID] [int] IDENTITY (1, 1) NOT NULL ,
[FADS_ADID] [int] NOT NULL ,
[FADS_TITLE] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
,
[FADS_TEXT] [nvarchar] (500) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
,
[FADS_MEMO] [nvarchar] (1500) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
,
[FADS_FTISTAMP] [timestamp] NOT NULL ,
[FADS_HTMLTEXT] [nvarchar] (1000) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[ADSFULL] WITH NOCHECK ADD
CONSTRAINT [PK_ADSFULL] PRIMARY KEY  CLUSTERED
(
 [FADS_ID]
)  ON [PRIMARY]
GO
if (select DATABASEPROPERTY(DB_NAME(), N'IsFullTextEnabled')) <> 1
exec sp_fulltext_database N'enable'
GO
if not exists (select * from dbo.sysfulltextcatalogs where name =
N'FTADSFR')
exec sp_fulltext_catalog N'FTADSFR', N'create'
GO
exec sp_fulltext_table N'[dbo].[ADSFULL]', N'create', N'FTADSFR',
N'PK_ADSFULL'
GO
exec sp_fulltext_column N'[dbo].[ADSFULL]', N'FADS_TITLE', N'add', 1033
GO
exec sp_fulltext_column N'[dbo].[ADSFULL]', N'FADS_TEXT', N'add', 1033
GO
exec sp_fulltext_table N'[dbo].[ADSFULL]', N'activate'
GO
ALTER TABLE [dbo].[ADSFULL] WITH NOCHECK ADD
CONSTRAINT [DF_ADSFULL_FADS_ADID] DEFAULT (0) FOR [FADS_ADID],
CONSTRAINT [DF_ADSFULL_FADS_TITLE] DEFAULT ('') FOR [FADS_TITLE],
CONSTRAINT [DF_ADSFULL_FADS_TEXT] DEFAULT ('') FOR [FADS_TEXT],
CONSTRAINT [DF_ADSFULL_FADS_MEMO] DEFAULT ('') FOR [FADS_MEMO],
CONSTRAINT [DF_ADSFULL_FADS_HTMLTEXT] DEFAULT ('') FOR [FADS_HTMLTEXT]
GO
CREATE  INDEX [IX_FOREIGNADID] ON [dbo].[ADSFULL]([FADS_ADID]) ON [PRIMARY]
GO
Daniel Crichton - 19 Jul 2006 09:46 GMT
Peter wrote  on Tue, 18 Jul 2006 14:28:56 GMT:

> I have a table ADSFULL containing ADVERTISMENTS with a FTI index on 2
> fields FADS_TITLE and FADS_TEXT (see script at the end).
[quoted text clipped - 37 lines]
>  WHERE (ADS_ADID IN (SELECT FADS_ADID FROM ADSFULL WHERE (CONTAINS(*,
> '"twingo" AND "beige"') ) ) )

I'm pretty sure that this requires that both "twingo" and "beige" are in the
same column - from the looks of things twingo is in fads_title and beige is
in fads_text, so that's why you get zero results. You could get it to return
the two results will be to create a new column which contains all the words
from the ad together (which is how I handle the FTS on my own sites where I
need to search across all searchable columns), and FTI that single column.
Or use multiple CONTAINS:

SELECT ads_adid, fads_id, fads_adid, fads_title, fads_text
FROM VWADS
WHERE (ADS_ADID IN (SELECT FADS_ADID FROM ADSFULL WHERE (CONTAINS(*,
'"twingo"') AND CONTAINS(*,'"beige"') ) ) )

Dan
Peter van Wilrijk - 19 Jul 2006 11:25 GMT
Thanks a lot Dan,

Testing your query tells you're right.  I'm stupefied.  We have more than
20.000 searches today since january 2005 and nobody ever noticed.  I just
saw it while testing another issue.  Bizarre.

> SELECT ads_adid, fads_id, fads_adid, fads_title, fads_text
> FROM VWADS
> WHERE (ADS_ADID IN (SELECT FADS_ADID FROM ADSFULL WHERE (CONTAINS(*,
> '"twingo"') AND CONTAINS(*,'"beige"') ) ) )

I don't feel like starting to use this solution since users can enter more
than 2 words (1 to n actually), so we'll have to follow the technique of
merging columns.  I stay surprised since SQL Server offered me the
possibility to add two columns to one full text index ... not much sence
there ... and merging the columns will increase the database with Gigabytes.

exec sp_fulltext_catalog N'FTADSFR', N'create'
exec sp_fulltext_table N'[dbo].[ADSFULL]', N'create', N'FTADSFR',
exec sp_fulltext_column N'[dbo].[ADSFULL]', N'FADS_TITLE', N'add', 1033
exec sp_fulltext_column N'[dbo].[ADSFULL]', N'FADS_TEXT', N'add', 1033

Kind regards,
Peter.
Daniel Crichton - 19 Jul 2006 12:05 GMT
Peter wrote  on Wed, 19 Jul 2006 10:25:04 GMT:

> Thanks a lot Dan,
>
[quoted text clipped - 13 lines]
> there ... and merging the columns will increase the database with
> Gigabytes.

It gives you the choice because that's the way it works. A table may only be
indexed in a single catalog - so every column that you want indexed will
need to be in that same catalog. However, the indexed words will be stored
against the column name they are stored in. It does seem strange that MS
didn't provide an option to allow the terms to be found from all columns
rather than just one, but unfortunately that's the way it has been
implemented.

Dan
Peter van Wilrijk - 19 Jul 2006 13:59 GMT
I see, thanks for the additional info.

'really like working MS dev tools, but this topic is a pitty.  I hope they
can improve this in a future release.

Peter.

> Peter wrote  on Wed, 19 Jul 2006 10:25:04 GMT:
>
[quoted text clipped - 25 lines]
>
> Dan
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.