473,378 Members | 1,605 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Help With Full Text Search. Performing AND across columns

I am trying to perform the following query on a table that has been
indexed using Full Text Search.

The table contains multiple columns than have been indexed. (Below,
all xml columns are indexed).
dbo.maintable(ProfileID int pk)
dbo.fts_table(ProfileID int pk fk, col1 xml, col2 xml, col3 xml)

I want to perform a query that will return any rows that contain ‘x’
and ‘y’ in any columns. I.e. ‘x’ could be in col1 and ‘y’ could be in
col3. (This is passed in by a user in a front end GUI)

The query to achieve this is:

SELECT ProfileID
FROM dbo.fts_table
WHERE CONTAINS (*,’”x” )
AND
CONTAINS (*,’”y”’)

Separating the search string in this way reduces performance and adds
complication in parsing the search string and extracting the AND
clauses from the OR, NOTs and parentheses (If a user has entered
them).

The query I want to perform:
SELECT *
FROM dbo.fts_table
WHERE CONTAINS (*,’”x” AND “y”’)

But this query is performed on a per column bases and will only return
the result if ‘x’ and ‘y’ are in the same column.

My first thought was to create a view, combining the data from each
column and use full text indexing on this.

CREATE VIEW fts_table_Joined with schemabinding as
SELECT mt.ProfileID as ProfileID,(SELECT col1, col2, col3 FROM
fts_table t WHERE t.ProfileID = mt.ProfileID)
FROM dbo.maintable mt

CREATE UNIQUE CLUSTERED INDEX fts_table_Joined_Index
ON fts_table_Joined (ProfileID);

But you cannot create an index on a view that has a nested query.
(The index is required for Full Text Search and the nested query is
needed to obtain a row for each record.)

The option I am left with is to create a table that replicates the
data in all the columns into one xml column and maintain this data
with triggers. This adds obvious overhead and data replication.

My question is am I missing something, is there a better way to solve
this problem?
Jul 10 '08 #1
8 5078
On Jul 10, 7:00*am, Sham <shamil.s...@gmail.comwrote:
I am trying to perform the following query on a table that has been
indexed using Full Text Search.

The table contains multiple columns than have been indexed. (Below,
all xml columns are indexed).
dbo.maintable(ProfileID int pk)
dbo.fts_table(ProfileID int pk fk, col1 xml, col2 xml, col3 xml)

I want to perform a query that will return any rows that contain ‘x’
and ‘y’ in any columns. *I.e. ‘x’ could be in col1 and ‘y’ could be in
col3. (This is passed in by a user in a front end GUI)

The query to achieve this is:

SELECT ProfileID
FROM dbo.fts_table
WHERE CONTAINS (*,’”x” )
AND
* * * * CONTAINS (*,’”y”’)

Separating the search string in this way reduces performance and adds
complication in parsing the search string and *extracting the AND
clauses from the OR, NOTs and parentheses (If a user has entered
them).

The query I want to perform:
SELECT *
FROM dbo.fts_table
WHERE CONTAINS (*,’”x” AND “y”’)

But this query is performed on a per column bases and will only return
the result if ‘x’ and ‘y’ are in the same column.

My first thought was to create a view, combining the data from each
column and use full text indexing on this.

CREATE VIEW fts_table_Joined with schemabinding as
SELECT mt.ProfileID as ProfileID,(SELECT col1, col2, col3 FROM
fts_table t WHERE t.ProfileID = mt.ProfileID)
FROM dbo.maintable mt

CREATE UNIQUE CLUSTERED INDEX fts_table_Joined_Index
ON fts_table_Joined (ProfileID);

But you cannot create an index on a view that has a nested query.
(The index is required for Full Text Search and the nested query is
needed to obtain a row for each record.)

The option I am left with is to create a table that replicates the
data in all the columns into one xml column and maintain this data
with triggers. *This adds obvious overhead and data replication.

My question is am I missing something, is there a better way to solve
this problem?
The subquery when used in the select part of the query should be
single column (in fact that's the goal, combining xml columns). Like
below:

CREATE VIEW fts_table_Joined with schemabinding as
SELECT mt.ProfileID as ProfileID,(SELECT col1+ col2+ col3 FROM
fts_table t WHERE t.ProfileID = mt.ProfileID)
FROM dbo.maintable mt

But since add operator can not be used on columns with xml data type,
first converting the columns to character data type and reconverting
back to xml may help:

SELECT mt.ProfileID,
(SELECT convert(xml,convert(nvarchar(MAX),col1)+
convert(nvarchar(MAX),col2)+ convert(nvarchar(MAX),col3))
FROM fts_table
WHERE (ProfileID = mt.ProfileID)) AS
ConsolidatedXMLColumns
FROM maintable AS mt
Finally, a more convenient solution can be just creating a persisted
computed column in fts_table and using the formula in the above
subquery:

convert(xml,convert(nvarchar(MAX),col1)+ convert(nvarchar(MAX),col2)+
convert(nvarchar(MAX),col3)).
Jul 12 '08 #2
Thank you for you comment nidaar.

I had forgot to add FOR XML AUTO on the sub query, which would achieve
combining the columns into one.

This still does not solve my issue. As I would like to perform a full
text index (MS Full Text Search) on the data, to do this I need to
create a view with a unique index on it. This is not possible if a
view has a nested query in it?

Thanks,

Shamil

On 12 Jul, 05:29, nidaar <nid...@gmail.comwrote:
On Jul 10, 7:00*am, Sham <shamil.s...@gmail.comwrote:


I am trying to perform the following query on a table that has been
indexed using Full Text Search.
The table contains multiple columns than have been indexed. (Below,
all xml columns are indexed).
dbo.maintable(ProfileID int pk)
dbo.fts_table(ProfileID int pk fk, col1 xml, col2 xml, col3 xml)
I want to perform a query that will return any rows that contain ‘x’
and ‘y’ in any columns. *I.e. ‘x’ could be in col1 and ‘y’ could be in
col3. (This is passed in by a user in a front end GUI)
The query to achieve this is:
SELECT ProfileID
FROM dbo.fts_table
WHERE CONTAINS (*,’”x” )
AND
* * * * CONTAINS (*,’”y”’)
Separating the search string in this way reduces performance and adds
complication in parsing the search string and *extracting the AND
clauses from the OR, NOTs and parentheses (If a user has entered
them).
The query I want to perform:
SELECT *
FROM dbo.fts_table
WHERE CONTAINS (*,’”x” AND “y”’)
But this query is performed on a per column bases and will only return
the result if ‘x’ and ‘y’ are in the same column.
My first thought was to create a view, combining the data from each
column and use full text indexing on this.
CREATE VIEW fts_table_Joined with schemabinding as
SELECT mt.ProfileID as ProfileID,(SELECT col1, col2, col3 FROM
fts_table t WHERE t.ProfileID = mt.ProfileID)
FROM dbo.maintable mt
CREATE UNIQUE CLUSTERED INDEX fts_table_Joined_Index
ON fts_table_Joined (ProfileID);
But you cannot create an index on a view that has a nested query.
(The index is required for Full Text Search and the nested query is
needed to obtain a row for each record.)
The option I am left with is to create a table that replicates the
data in all the columns into one xml column and maintain this data
with triggers. *This adds obvious overhead and data replication.
My question is am I missing something, is there a better way to solve
this problem?

The subquery when used in the select part of the query should be
single column (in fact that's the goal, combining xml columns). Like
below:

CREATE VIEW fts_table_Joined with schemabinding as
SELECT mt.ProfileID as ProfileID,(SELECT col1+ col2+ col3 FROM
fts_table t WHERE t.ProfileID = mt.ProfileID)
FROM dbo.maintable mt

But since add operator can not be used on columns with xml data type,
first converting the columns to character data type and reconverting
back to xml may help:

SELECT * * mt.ProfileID,
* * * (SELECT * * convert(xml,convert(nvarchar(MAX),col1)+
convert(nvarchar(MAX),col2)+ convert(nvarchar(MAX),col3))
* * * * FROM * * * * *fts_table
* * * * WHERE * * *(ProfileID = mt.ProfileID)) AS
ConsolidatedXMLColumns
FROM * * * * maintable AS mt

Finally, a more convenient solution can be just creating a persisted
computed column in fts_table and using the formula in the above
subquery:

convert(xml,convert(nvarchar(MAX),col1)+ convert(nvarchar(MAX),col2)+
convert(nvarchar(MAX),col3)).- Hide quoted text -

- Show quoted text -
Jul 14 '08 #3
On Jul 14, 5:07*am, Sham <shamil.s...@gmail.comwrote:
Thank you for you commentnidaar.

I had forgot to add FOR XML AUTO on the sub query, which would achieve
combining the columns into one.

This still does not solve my issue. *As I would like to perform a full
text index (MS Full Text Search) on the data, to do this I need to
create a view with a unique index on it. *This is not possible if a
view has a nested query in it?

Thanks,

Shamil

On 12 Jul, 05:29,nidaar<nid...@gmail.comwrote:
On Jul 10, 7:00*am, Sham <shamil.s...@gmail.comwrote:
I am trying to perform the following query on a table that has been
indexed using Full Text Search.
The table contains multiple columns than have been indexed. (Below,
all xml columns are indexed).
dbo.maintable(ProfileID int pk)
dbo.fts_table(ProfileID int pk fk, col1 xml, col2 xml, col3 xml)
I want to perform a query that will return any rows that contain ‘x’
and ‘y’ in any columns. *I.e. ‘x’ could be in col1 and ‘y’ could be in
col3. (This is passed in by a user in a front end GUI)
The query to achieve this is:
SELECT ProfileID
FROM dbo.fts_table
WHERE CONTAINS (*,’”x” )
AND
* * * * CONTAINS (*,’”y”’)
Separating the search string in this way reduces performance and adds
complication in parsing the search string and *extracting the AND
clauses from the OR, NOTs and parentheses (If a user has entered
them).
The query I want to perform:
SELECT *
FROM dbo.fts_table
WHERE CONTAINS (*,’”x” AND “y”’)
But this query is performed on a per column bases and will only return
the result if ‘x’ and ‘y’ are in the same column.
My first thought was to create a view, combining the data from each
column and use full text indexing on this.
CREATE VIEW fts_table_Joined with schemabinding as
SELECT mt.ProfileID as ProfileID,(SELECT col1, col2, col3 FROM
fts_table t WHERE t.ProfileID = mt.ProfileID)
FROM dbo.maintable mt
CREATE UNIQUE CLUSTERED INDEX fts_table_Joined_Index
ON fts_table_Joined (ProfileID);
But you cannot create an index on a view that has a nested query.
(The index is required for Full Text Search and the nested query is
needed to obtain a row for each record.)
The option I am left with is to create a table that replicates the
data in all the columns into one xml column and maintain this data
with triggers. *This adds obvious overhead and data replication.
My question is am I missing something, is there a better way to solve
this problem?
The subquery when used in the select part of the query should be
single column (in fact that's the goal, combining xml columns). Like
below:
CREATE VIEW fts_table_Joined with schemabinding as
SELECT mt.ProfileID as ProfileID,(SELECT col1+ col2+ col3 FROM
fts_table t WHERE t.ProfileID = mt.ProfileID)
FROM dbo.maintable mt
But since add operator can not be used on columns with xml data type,
first converting the columns to character data type and reconverting
back to xml may help:
SELECT * * mt.ProfileID,
* * * (SELECT * * convert(xml,convert(nvarchar(MAX),col1)+
convert(nvarchar(MAX),col2)+ convert(nvarchar(MAX),col3))
* * * * FROM * * * * *fts_table
* * * * WHERE * * *(ProfileID = mt.ProfileID)) AS
ConsolidatedXMLColumns
FROM * * * * maintable AS mt
Finally, a more convenient solution can be just creating a persisted
computed column in fts_table and using the formula in the above
subquery:
convert(xml,convert(nvarchar(MAX),col1)+ convert(nvarchar(MAX),col2)+
convert(nvarchar(MAX),col3)).- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -

Since indexed views do not support subqueries, the subquery needs to
be converted to a join and a unique index has to be defined on the
indexed view (ProfileID), then a Full-text index on the consolidated
column can be created. Like below:

View:
CREATE VIEW [dbo].[View_1]
WITH SCHEMABINDING
AS
SELECT mt.ProfileID, CONVERT(xml, CONVERT(nvarchar(MAX),
dbo.fts_table.col1) + CONVERT(nvarchar(MAX), dbo.fts_table.col2) +
CONVERT(nvarchar(MAX),
dbo.fts_table.col3)) AS ConsolidatedXMLColumns
FROM dbo.maintable AS mt INNER JOIN
dbo.fts_table ON mt.ProfileID =
dbo.fts_table.ProfileID
Unique Index:
CREATE UNIQUE CLUSTERED INDEX [uix_view1] ON [dbo].[View_1]
(
[ProfileID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB
= OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
Full-Text Index:
CREATE FULLTEXT INDEX ON [dbo].[View_1] KEY INDEX [uix_view1] ON [aaa]
WITH CHANGE_TRACKING AUTO
GO
USE [ApptitudeSQL]
GO
ALTER FULLTEXT INDEX ON [dbo].[View_1] ADD ([ConsolidatedXMLColumns])
GO
USE [ApptitudeSQL]
GO
ALTER FULLTEXT INDEX ON [dbo].[View_1] ENABLE
Full-text query:
SELECT ProfileID
FROM View_1
WHERE CONTAINS(ConsolidatedXMLColumns,'SearchCriteria')

Of course a computed column with a full text index would be easier to
implement.
Jul 14 '08 #4
On Jul 14, 5:07*am, Sham <shamil.s...@gmail.comwrote:
Thank you for you commentnidaar.

I had forgot to add FOR XML AUTO on the sub query, which would achieve
combining the columns into one.

This still does not solve my issue. *As I would like to perform a full
text index (MS Full Text Search) on the data, to do this I need to
create a view with a unique index on it. *This is not possible if a
view has a nested query in it?

Thanks,

Shamil

On 12 Jul, 05:29,nidaar<nid...@gmail.comwrote:
On Jul 10, 7:00*am, Sham <shamil.s...@gmail.comwrote:
I am trying to perform the following query on a table that has been
indexed using Full Text Search.
The table contains multiple columns than have been indexed. (Below,
all xml columns are indexed).
dbo.maintable(ProfileID int pk)
dbo.fts_table(ProfileID int pk fk, col1 xml, col2 xml, col3 xml)
I want to perform a query that will return any rows that contain ‘x’
and ‘y’ in any columns. *I.e. ‘x’ could be in col1 and ‘y’ could be in
col3. (This is passed in by a user in a front end GUI)
The query to achieve this is:
SELECT ProfileID
FROM dbo.fts_table
WHERE CONTAINS (*,’”x” )
AND
* * * * CONTAINS (*,’”y”’)
Separating the search string in this way reduces performance and adds
complication in parsing the search string and *extracting the AND
clauses from the OR, NOTs and parentheses (If a user has entered
them).
The query I want to perform:
SELECT *
FROM dbo.fts_table
WHERE CONTAINS (*,’”x” AND “y”’)
But this query is performed on a per column bases and will only return
the result if ‘x’ and ‘y’ are in the same column.
My first thought was to create a view, combining the data from each
column and use full text indexing on this.
CREATE VIEW fts_table_Joined with schemabinding as
SELECT mt.ProfileID as ProfileID,(SELECT col1, col2, col3 FROM
fts_table t WHERE t.ProfileID = mt.ProfileID)
FROM dbo.maintable mt
CREATE UNIQUE CLUSTERED INDEX fts_table_Joined_Index
ON fts_table_Joined (ProfileID);
But you cannot create an index on a view that has a nested query.
(The index is required for Full Text Search and the nested query is
needed to obtain a row for each record.)
The option I am left with is to create a table that replicates the
data in all the columns into one xml column and maintain this data
with triggers. *This adds obvious overhead and data replication.
My question is am I missing something, is there a better way to solve
this problem?
The subquery when used in the select part of the query should be
single column (in fact that's the goal, combining xml columns). Like
below:
CREATE VIEW fts_table_Joined with schemabinding as
SELECT mt.ProfileID as ProfileID,(SELECT col1+ col2+ col3 FROM
fts_table t WHERE t.ProfileID = mt.ProfileID)
FROM dbo.maintable mt
But since add operator can not be used on columns with xml data type,
first converting the columns to character data type and reconverting
back to xml may help:
SELECT * * mt.ProfileID,
* * * (SELECT * * convert(xml,convert(nvarchar(MAX),col1)+
convert(nvarchar(MAX),col2)+ convert(nvarchar(MAX),col3))
* * * * FROM * * * * *fts_table
* * * * WHERE * * *(ProfileID = mt.ProfileID)) AS
ConsolidatedXMLColumns
FROM * * * * maintable AS mt
Finally, a more convenient solution can be just creating a persisted
computed column in fts_table and using the formula in the above
subquery:
convert(xml,convert(nvarchar(MAX),col1)+ convert(nvarchar(MAX),col2)+
convert(nvarchar(MAX),col3)).- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -
Since indexed views do not support subqueries, the subquery needs to
be converted to a join and a unique index has to be defined on the
indexed view (ProfileID), then a Full-text index on the consolidated
column can be created. Like below:

View:
CREATE VIEW [dbo].[View_1]
WITH SCHEMABINDING
AS
SELECT mt.ProfileID, CONVERT(xml, CONVERT(nvarchar(MAX),
dbo.fts_table.col1) + CONVERT(nvarchar(MAX), dbo.fts_table.col2) +
CONVERT(nvarchar(MAX),
dbo.fts_table.col3)) AS ConsolidatedXMLColumns
FROM dbo.maintable AS mt INNER JOIN
dbo.fts_table ON mt.ProfileID =
dbo.fts_table.ProfileID
Unique Index:
CREATE UNIQUE CLUSTERED INDEX [uix_view1] ON [dbo].[View_1]
(
[ProfileID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
SORT_IN_TEMPDB
= OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
Full-Text Index:
CREATE FULLTEXT INDEX ON [dbo].[View_1] KEY INDEX [uix_view1] ON
[aaa]
WITH CHANGE_TRACKING AUTO
GO
ALTER FULLTEXT INDEX ON [dbo].[View_1] ADD ([ConsolidatedXMLColumns])
GO
ALTER FULLTEXT INDEX ON [dbo].[View_1] ENABLE
Full-text query:
SELECT ProfileID
FROM View_1
WHERE CONTAINS(ConsolidatedXMLColumns,'SearchCriteria')
Of course a computed column with a full text index would be easier to
implement.

Jul 14 '08 #5
On Jul 14, 5:07*am, Sham <shamil.s...@gmail.comwrote:
Thank you for you commentnidaar.

I had forgot to add FOR XML AUTO on the sub query, which would achieve
combining the columns into one.

This still does not solve my issue. *As I would like to perform a full
text index (MS Full Text Search) on the data, to do this I need to
create a view with a unique index on it. *This is not possible if a
view has a nested query in it?

Thanks,

Shamil

On 12 Jul, 05:29,nidaar<nid...@gmail.comwrote:
On Jul 10, 7:00*am, Sham <shamil.s...@gmail.comwrote:
I am trying to perform the following query on a table that has been
indexed using Full Text Search.
The table contains multiple columns than have been indexed. (Below,
all xml columns are indexed).
dbo.maintable(ProfileID int pk)
dbo.fts_table(ProfileID int pk fk, col1 xml, col2 xml, col3 xml)
I want to perform a query that will return any rows that contain ‘x’
and ‘y’ in any columns. *I.e. ‘x’ could be in col1 and ‘y’ could be in
col3. (This is passed in by a user in a front end GUI)
The query to achieve this is:
SELECT ProfileID
FROM dbo.fts_table
WHERE CONTAINS (*,’”x” )
AND
* * * * CONTAINS (*,’”y”’)
Separating the search string in this way reduces performance and adds
complication in parsing the search string and *extracting the AND
clauses from the OR, NOTs and parentheses (If a user has entered
them).
The query I want to perform:
SELECT *
FROM dbo.fts_table
WHERE CONTAINS (*,’”x” AND “y”’)
But this query is performed on a per column bases and will only return
the result if ‘x’ and ‘y’ are in the same column.
My first thought was to create a view, combining the data from each
column and use full text indexing on this.
CREATE VIEW fts_table_Joined with schemabinding as
SELECT mt.ProfileID as ProfileID,(SELECT col1, col2, col3 FROM
fts_table t WHERE t.ProfileID = mt.ProfileID)
FROM dbo.maintable mt
CREATE UNIQUE CLUSTERED INDEX fts_table_Joined_Index
ON fts_table_Joined (ProfileID);
But you cannot create an index on a view that has a nested query.
(The index is required for Full Text Search and the nested query is
needed to obtain a row for each record.)
The option I am left with is to create a table that replicates the
data in all the columns into one xml column and maintain this data
with triggers. *This adds obvious overhead and data replication.
My question is am I missing something, is there a better way to solve
this problem?
The subquery when used in the select part of the query should be
single column (in fact that's the goal, combining xml columns). Like
below:
CREATE VIEW fts_table_Joined with schemabinding as
SELECT mt.ProfileID as ProfileID,(SELECT col1+ col2+ col3 FROM
fts_table t WHERE t.ProfileID = mt.ProfileID)
FROM dbo.maintable mt
But since add operator can not be used on columns with xml data type,
first converting the columns to character data type and reconverting
back to xml may help:
SELECT * * mt.ProfileID,
* * * (SELECT * * convert(xml,convert(nvarchar(MAX),col1)+
convert(nvarchar(MAX),col2)+ convert(nvarchar(MAX),col3))
* * * * FROM * * * * *fts_table
* * * * WHERE * * *(ProfileID = mt.ProfileID)) AS
ConsolidatedXMLColumns
FROM * * * * maintable AS mt
Finally, a more convenient solution can be just creating a persisted
computed column in fts_table and using the formula in the above
subquery:
convert(xml,convert(nvarchar(MAX),col1)+ convert(nvarchar(MAX),col2)+
convert(nvarchar(MAX),col3)).- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -
View:
CREATE VIEW [dbo].[View_1]
WITH SCHEMABINDING
AS
SELECT mt.ProfileID, CONVERT(xml, CONVERT(nvarchar(MAX),
dbo.fts_table.col1) + CONVERT(nvarchar(MAX), dbo.fts_table.col2) +
CONVERT(nvarchar(MAX),
dbo.fts_table.col3)) AS ConsolidatedXMLColumns
FROM dbo.maintable AS mt INNER JOIN
dbo.fts_table ON mt.ProfileID =
dbo.fts_table.ProfileID
Unique Index:
CREATE UNIQUE CLUSTERED INDEX [uix_view1] ON [dbo].[View_1]
(
[ProfileID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
SORT_IN_TEMPDB
= OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
Full-Text Index:
CREATE FULLTEXT INDEX ON [dbo].[View_1] KEY INDEX [uix_view1] ON
[MyFullTextCatalog]
WITH CHANGE_TRACKING AUTO
GO
ALTER FULLTEXT INDEX ON [dbo].[View_1] ADD ([ConsolidatedXMLColumns])
GO
ALTER FULLTEXT INDEX ON [dbo].[View_1] ENABLE
Full-text query:
SELECT ProfileID
FROM View_1
WHERE CONTAINS(ConsolidatedXMLColumns,'SearchCriteria')
Jul 14 '08 #6
On Jul 14, 5:07*am, Sham <shamil.s...@gmail.comwrote:
Thank you for you commentnidaar.

I had forgot to add FOR XML AUTO on the sub query, which would achieve
combining the columns into one.

This still does not solve my issue. *As I would like to perform a full
text index (MS Full Text Search) on the data, to do this I need to
create a view with a unique index on it. *This is not possible if a
view has a nested query in it?

Thanks,

Shamil

On 12 Jul, 05:29,nidaar<nid...@gmail.comwrote:
On Jul 10, 7:00*am, Sham <shamil.s...@gmail.comwrote:
I am trying to perform the following query on a table that has been
indexed using Full Text Search.
The table contains multiple columns than have been indexed. (Below,
all xml columns are indexed).
dbo.maintable(ProfileID int pk)
dbo.fts_table(ProfileID int pk fk, col1 xml, col2 xml, col3 xml)
I want to perform a query that will return any rows that contain ‘x’
and ‘y’ in any columns. *I.e. ‘x’ could be in col1 and ‘y’ could be in
col3. (This is passed in by a user in a front end GUI)
The query to achieve this is:
SELECT ProfileID
FROM dbo.fts_table
WHERE CONTAINS (*,’”x” )
AND
* * * * CONTAINS (*,’”y”’)
Separating the search string in this way reduces performance and adds
complication in parsing the search string and *extracting the AND
clauses from the OR, NOTs and parentheses (If a user has entered
them).
The query I want to perform:
SELECT *
FROM dbo.fts_table
WHERE CONTAINS (*,’”x” AND “y”’)
But this query is performed on a per column bases and will only return
the result if ‘x’ and ‘y’ are in the same column.
My first thought was to create a view, combining the data from each
column and use full text indexing on this.
CREATE VIEW fts_table_Joined with schemabinding as
SELECT mt.ProfileID as ProfileID,(SELECT col1, col2, col3 FROM
fts_table t WHERE t.ProfileID = mt.ProfileID)
FROM dbo.maintable mt
CREATE UNIQUE CLUSTERED INDEX fts_table_Joined_Index
ON fts_table_Joined (ProfileID);
But you cannot create an index on a view that has a nested query.
(The index is required for Full Text Search and the nested query is
needed to obtain a row for each record.)
The option I am left with is to create a table that replicates the
data in all the columns into one xml column and maintain this data
with triggers. *This adds obvious overhead and data replication.
My question is am I missing something, is there a better way to solve
this problem?
The subquery when used in the select part of the query should be
single column (in fact that's the goal, combining xml columns). Like
below:
CREATE VIEW fts_table_Joined with schemabinding as
SELECT mt.ProfileID as ProfileID,(SELECT col1+ col2+ col3 FROM
fts_table t WHERE t.ProfileID = mt.ProfileID)
FROM dbo.maintable mt
But since add operator can not be used on columns with xml data type,
first converting the columns to character data type and reconverting
back to xml may help:
SELECT * * mt.ProfileID,
* * * (SELECT * * convert(xml,convert(nvarchar(MAX),col1)+
convert(nvarchar(MAX),col2)+ convert(nvarchar(MAX),col3))
* * * * FROM * * * * *fts_table
* * * * WHERE * * *(ProfileID = mt.ProfileID)) AS
ConsolidatedXMLColumns
FROM * * * * maintable AS mt
Finally, a more convenient solution can be just creating a persisted
computed column in fts_table and using the formula in the above
subquery:
convert(xml,convert(nvarchar(MAX),col1)+ convert(nvarchar(MAX),col2)+
convert(nvarchar(MAX),col3)).- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -


Since subqueries are not supported by indexed views, the subquery
needs to be converted to a join, before defining a unique index (on
ProfileID). Then a full-text index can be created on the consolidated
column. Like below:
View:
CREATE VIEW [dbo].[View_1]
WITH SCHEMABINDING
AS
SELECT mt.ProfileID, CONVERT(xml, CONVERT(nvarchar(MAX),
dbo.fts_table.col1) + CONVERT(nvarchar(MAX), dbo.fts_table.col2) +
CONVERT(nvarchar(MAX),
dbo.fts_table.col3)) AS ConsolidatedXMLColumns
FROM dbo.maintable AS mt INNER JOIN
dbo.fts_table ON mt.ProfileID =
dbo.fts_table.ProfileID
Unique Index:
CREATE UNIQUE CLUSTERED INDEX [uix_view1] ON [dbo].[View_1]
(
[ProfileID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
SORT_IN_TEMPDB
= OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
Full-Text Index:
CREATE FULLTEXT INDEX ON [dbo].[View_1] KEY INDEX [uix_view1] ON
[MyFullTextCatalog]
WITH CHANGE_TRACKING AUTO
GO
ALTER FULLTEXT INDEX ON [dbo].[View_1] ADD ([ConsolidatedXMLColumns])
GO
ALTER FULLTEXT INDEX ON [dbo].[View_1] ENABLE
Full-text query:
SELECT ProfileID
FROM View_1
WHERE CONTAINS(ConsolidatedXMLColumns,'SearchCriteria')
Of course, a persisted computed column on fts_table with a full text
index can be implemented in fewer steps.
Jul 14 '08 #7
On Jul 14, 5:07*am, Sham <shamil.s...@gmail.comwrote:
Thank you for you commentnidaar.

I had forgot to add FOR XML AUTO on the sub query, which would achieve
combining the columns into one.

This still does not solve my issue. *As I would like to perform a full
text index (MS Full Text Search) on the data, to do this I need to
create a view with a unique index on it. *This is not possible if a
view has a nested query in it?

Thanks,

Shamil

On 12 Jul, 05:29,nidaar<nid...@gmail.comwrote:
On Jul 10, 7:00*am, Sham <shamil.s...@gmail.comwrote:
I am trying to perform the following query on a table that has been
indexed using Full Text Search.
The table contains multiple columns than have been indexed. (Below,
all xml columns are indexed).
dbo.maintable(ProfileID int pk)
dbo.fts_table(ProfileID int pk fk, col1 xml, col2 xml, col3 xml)
I want to perform a query that will return any rows that contain ‘x’
and ‘y’ in any columns. *I.e. ‘x’ could be in col1 and ‘y’ could be in
col3. (This is passed in by a user in a front end GUI)
The query to achieve this is:
SELECT ProfileID
FROM dbo.fts_table
WHERE CONTAINS (*,’”x” )
AND
* * * * CONTAINS (*,’”y”’)
Separating the search string in this way reduces performance and adds
complication in parsing the search string and *extracting the AND
clauses from the OR, NOTs and parentheses (If a user has entered
them).
The query I want to perform:
SELECT *
FROM dbo.fts_table
WHERE CONTAINS (*,’”x” AND “y”’)
But this query is performed on a per column bases and will only return
the result if ‘x’ and ‘y’ are in the same column.
My first thought was to create a view, combining the data from each
column and use full text indexing on this.
CREATE VIEW fts_table_Joined with schemabinding as
SELECT mt.ProfileID as ProfileID,(SELECT col1, col2, col3 FROM
fts_table t WHERE t.ProfileID = mt.ProfileID)
FROM dbo.maintable mt
CREATE UNIQUE CLUSTERED INDEX fts_table_Joined_Index
ON fts_table_Joined (ProfileID);
But you cannot create an index on a view that has a nested query.
(The index is required for Full Text Search and the nested query is
needed to obtain a row for each record.)
The option I am left with is to create a table that replicates the
data in all the columns into one xml column and maintain this data
with triggers. *This adds obvious overhead and data replication.
My question is am I missing something, is there a better way to solve
this problem?
The subquery when used in the select part of the query should be
single column (in fact that's the goal, combining xml columns). Like
below:
CREATE VIEW fts_table_Joined with schemabinding as
SELECT mt.ProfileID as ProfileID,(SELECT col1+ col2+ col3 FROM
fts_table t WHERE t.ProfileID = mt.ProfileID)
FROM dbo.maintable mt
But since add operator can not be used on columns with xml data type,
first converting the columns to character data type and reconverting
back to xml may help:
SELECT * * mt.ProfileID,
* * * (SELECT * * convert(xml,convert(nvarchar(MAX),col1)+
convert(nvarchar(MAX),col2)+ convert(nvarchar(MAX),col3))
* * * * FROM * * * * *fts_table
* * * * WHERE * * *(ProfileID = mt.ProfileID)) AS
ConsolidatedXMLColumns
FROM * * * * maintable AS mt
Finally, a more convenient solution can be just creating a persisted
computed column in fts_table and using the formula in the above
subquery:
convert(xml,convert(nvarchar(MAX),col1)+ convert(nvarchar(MAX),col2)+
convert(nvarchar(MAX),col3)).- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -
Since subqueries are not supported by indexed views, the subquery
needs to be converted to a join, before defining a unique index (on
ProfileID). Then a full-text index can be created on the consolidated
column. Like below:

View:
CREATE VIEW [dbo].[View_1]
WITH SCHEMABINDING
AS
SELECT mt.ProfileID, CONVERT(xml, CONVERT(nvarchar(MAX),
dbo.fts_table.col1) + CONVERT(nvarchar(MAX), dbo.fts_table.col2) +
CONVERT(nvarchar(MAX),
dbo.fts_table.col3)) AS ConsolidatedXMLColumns
FROM dbo.maintable AS mt INNER JOIN
dbo.fts_table ON mt.ProfileID =
dbo.fts_table.ProfileID
Unique Index:
CREATE UNIQUE CLUSTERED INDEX [uix_view1] ON [dbo].[View_1]
(
[ProfileID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
SORT_IN_TEMPDB
= OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
Full-Text Index:
CREATE FULLTEXT INDEX ON [dbo].[View_1] KEY INDEX [uix_view1] ON
[MyFullTextCatalog]
WITH CHANGE_TRACKING AUTO
GO
ALTER FULLTEXT INDEX ON [dbo].[View_1] ADD ([ConsolidatedXMLColumns])
GO
ALTER FULLTEXT INDEX ON [dbo].[View_1] ENABLE
Full-text query:
SELECT ProfileID
FROM View_1
WHERE CONTAINS(ConsolidatedXMLColumns,'SearchCriteria')
Actually FOR XML AUTO is not required. And of course, a persisted
computed column on fts_table with a full text
index can be implemented in fewer steps.
Jul 14 '08 #8

On 14 Jul, 20:20, nidaar <nid...@gmail.comwrote:
On Jul 14, 5:07 am, Sham <shamil.s...@gmail.comwrote:


Thank you for you commentnidaar.
I had forgot to add FOR XML AUTO on the sub query, which would achieve
combining the columns into one.
This still does not solve my issue. As I would like to perform a full
text index (MS Full Text Search) on the data, to do this I need to
create a view with a unique index on it. This is not possible if a
view has a nested query in it?
Thanks,
Shamil
On 12 Jul, 05:29,nidaar<nid...@gmail.comwrote:
On Jul 10, 7:00 am, Sham <shamil.s...@gmail.comwrote:
I am trying to perform the following query on a table that has been
indexed using Full Text Search.
The table contains multiple columns than have been indexed. (Below,
all xml columns are indexed).
dbo.maintable(ProfileID int pk)
dbo.fts_table(ProfileID int pk fk, col1 xml, col2 xml, col3 xml)
I want to perform a query that will return any rows that contain ‘x’
and ‘y’ in any columns. I.e. ‘x’ could be in col1 and ‘y’ could be in
col3. (This is passed in by a user in a front end GUI)
The query to achieve this is:
SELECT ProfileID
FROM dbo.fts_table
WHERE CONTAINS (*,’”x” )
AND
CONTAINS (*,’”y”’)
Separating the search string in this way reduces performance and adds
complication in parsing the search string and extracting the AND
clauses from the OR, NOTs and parentheses (If a user has entered
them).
The query I want to perform:
SELECT *
FROM dbo.fts_table
WHERE CONTAINS (*,’”x” AND “y”’)
But this query is performed on a per column bases and will only return
the result if ‘x’ and ‘y’ are in the same column.
My first thought was to create a view, combining the data from each
column and use full text indexing on this.
CREATE VIEW fts_table_Joined with schemabinding as
SELECT mt.ProfileID as ProfileID,(SELECT col1, col2, col3 FROM
fts_table t WHERE t.ProfileID = mt.ProfileID)
FROM dbo.maintable mt
CREATE UNIQUE CLUSTERED INDEX fts_table_Joined_Index
ON fts_table_Joined (ProfileID);
But you cannot create an index on a view that has a nested query.
(The index is required for Full Text Search and the nested query is
needed to obtain a row for each record.)
The option I am left with is to create a table that replicates the
data in all the columns into one xml column and maintain this data
with triggers. This adds obvious overhead and data replication.
My question is am I missing something, is there a better way to solve
this problem?
The subquery when used in the select part of the query should be
single column (in fact that's the goal, combining xml columns). Like
below:
CREATE VIEW fts_table_Joined with schemabinding as
SELECT mt.ProfileID as ProfileID,(SELECT col1+ col2+ col3 FROM
fts_table t WHERE t.ProfileID = mt.ProfileID)
FROM dbo.maintable mt
But since add operator can not be used on columns with xml data type,
first converting the columns to character data type and reconverting
back to xml may help:
SELECT mt.ProfileID,
(SELECT convert(xml,convert(nvarchar(MAX),col1)+
convert(nvarchar(MAX),col2)+ convert(nvarchar(MAX),col3))
FROM fts_table
WHERE (ProfileID = mt.ProfileID)) AS
ConsolidatedXMLColumns
FROM maintable AS mt
Finally, a more convenient solution can be just creating a persisted
computed column in fts_table and using the formula in the above
subquery:
convert(xml,convert(nvarchar(MAX),col1)+ convert(nvarchar(MAX),col2)+
convert(nvarchar(MAX),col3)).- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -

Since subqueries are not supported by indexed views, the subquery
needs to be converted to a join, before defining a unique index (on
ProfileID). Then a full-text index can be created on the consolidated
column. Like below:

View:
CREATE VIEW [dbo].[View_1]
WITH SCHEMABINDING
AS
SELECT mt.ProfileID, CONVERT(xml, CONVERT(nvarchar(MAX),
dbo.fts_table.col1) + CONVERT(nvarchar(MAX), dbo.fts_table.col2) +
CONVERT(nvarchar(MAX),
dbo.fts_table.col3)) AS ConsolidatedXMLColumns
FROM dbo.maintable AS mt INNER JOIN
dbo.fts_table ON mt.ProfileID =
dbo.fts_table.ProfileID

Unique Index:
CREATE UNIQUE CLUSTERED INDEX [uix_view1] ON [dbo].[View_1]
(
[ProfileID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
SORT_IN_TEMPDB
= OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

Full-Text Index:
CREATE FULLTEXT INDEX ON [dbo].[View_1] KEY INDEX [uix_view1] ON
[MyFullTextCatalog]
WITH CHANGE_TRACKING AUTO
GO
ALTER FULLTEXT INDEX ON [dbo].[View_1] ADD ([ConsolidatedXMLColumns])
GO
ALTER FULLTEXT INDEX ON [dbo].[View_1] ENABLE

Full-text query:
SELECT ProfileID
FROM View_1
WHERE CONTAINS(ConsolidatedXMLColumns,'SearchCriteria')

Actually FOR XML AUTO is not required. And of course, a persisted
computed column on fts_table with a full text
index can be implemented in fewer steps.- Hide quoted text -

- Show quoted text -
Thanks a lot, that works well.

The database I am going to be performing this on has 80 columns across
6 tables that need to be joined.

Would you know if there is a performance implication when performing
the conversion on all of these fields?

Thanks

Sham

Jul 15 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: karolina | last post by:
Hi, I building a little site using PHP and mysql. Now I want to make full text searches on some columns in one table. The problem is that I have 25 colums in the table that I want to put at...
4
by: dave | last post by:
I am wondering if the following can be done. I want to setup a search page that utilizes full text searching in sql2000. I want the user to type in say "where is bill" and have the query search...
0
by: Adam | last post by:
I am currently determining the architecture for a rewrite of an existing retailed software product - moving from Smalltalk to C# .Net. It is to be a rich-client single-user desktop application. The...
1
by: John | last post by:
Hello, We are developing an application against an MS SQL Server 2000 database which requires that we implement full-text searching across columns in multiple tables. The research that we have...
1
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
2
by: rufpirat | last post by:
Hello I'm in the middle of trying to build an "AD phone book", and this being my first try at asp.net, I have a few questions that I hope some of you might be able to help with: 1. Is it...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
8
by: inFocus | last post by:
Hello, I am new to python and wanted to write something for myself where after inputing two words it would search entire drive and when finding both names in files name would either copy or move...
1
by: vikjohn | last post by:
I have a new perl script sent to me which is a revision of the one I am currently running. The permissions are the same on each, the paths are correct but I am getting the infamous : The specified...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.