Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 Full Text Indexing Question

Author  Topic 

staplebottom
Starting Member

29 Posts

Posted - 2007-11-29 : 13:41:47
If I have a table which has multiple child rows in another table, how I can index both tables to search the parent row, and all child rows in one go for a given term?

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2007-11-29 : 20:46:53
Create a view that queries the two tables, then create a regular index on that view and finally, create the full-text index on the indexed view.
Go to Top of Page

staplebottom
Starting Member

29 Posts

Posted - 2007-11-30 : 09:29:21
I dont suppose you have an example of this you can show me?

Ive create some functions that basically adds the strings from the child table into a single string, so the view has something like this :

Select textField, dbo.aggregateTags(@itemID) AS tags FROM table

If the tags table is changed this wont update the view will it? This is a problem for me if thats the case.
Go to Top of Page

staplebottom
Starting Member

29 Posts

Posted - 2007-11-30 : 09:47:40
Create a view that queries the two tables, then create a regular index on that view and finally, create the full-text index on the indexed view.

In this case if my full text search matches a string in the baser table, will I not get a match for every field in the child table, as creating a view on a join of the two will create an entry in the view for the base table every time there is a child row?

E.G. :

tbl_base

id | Text
------------------------
1 | BLah blah
2 | Dum de dum
3 | HAr HAr


tbl_base_tags

tagID | base_id | TagText
--------------------------
1 | 1 | first
2 | 1 | second
3 | 1 | third
4 | 2 | fourth

Then the view that queries these two tables will have

vw_tables

base_id | tagid | Text | TagText
---------------------------------------------
1 | 1 | Blah blah | first
1 | 2 | blah blah | second
1 | 3 | Blah blah | third
2 | 4 | Dum de dum | fourth

and so on with replication of the text field from the base table instead of :

base_id | Text | Tags
-------------------------------------
1 | Blah blah | first second third
2 | dum de dum | fourth


I hope this is clear.

Thanks,
C
Go to Top of Page

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2007-11-30 : 20:35:00
You don't need to aggregate the child rows, it sounds like you're looking for the parent row ID of a parent that either contains the search text or that has a child that contains the search text.

So the view will return multiple rows per parent, but that's fine, just put the full-text predicate in the WHERE clause to find the parent row IDs and then use them to get the individual rows however you want them.
Go to Top of Page
   

- Advertisement -