Click here to Skip to main content
15,894,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
dears,
i want to select all the the records in the table as the below:

if the search string is "i went to the supermarket yesterday with a friend"
i want to discard these words "i, to, the, with, a" so the remain words are "went supermarket yesterday friend" so i search in the table for the follows:

1-first select * from mytable where title = 'i went to the supermarket yesterday with a friend' the whole string,

2-select any title contains two or more words in the string "went supermarket yesterday friend"
regardless the order of the word

3- at the end select any record contains any word in "went supermarket yesterday friend"

example:

i have three rows in mytable:

1-"i bough a supermarket"
2-"meet your friend in the supermarket"
3-"i went to the supermarket yesterday with a friend"
4-"John went to the supermarket"

the result of the selection must be :

in first row
"i went to the supermarket yesterday with a friend" (exactly same)

in the second or third row (contains 2 words: went, supermarket)
"John went to the supermarket"

in the second or third row
"meet your friend in the supermarket" (contains 2 words: friend, supermarket even if in different order)

in the last row
"i bough a supermarket" (contains 1 word: supermarket )

as a result i need an advanced search engine but i don't want to use temp table because i thing it will make troubles when many users are searching at the same time

thanks on advanced
Posted
Comments
[no name] 22-Aug-14 3:22am    
It's a big topic and nobody has that much time to give you a long solution. For this you have try it your self if you are facing any problem then ask here. Then anybody can help you happily
Member 10266297 22-Aug-14 3:39am    
ok you are right, i tried my self the below:

Declare @products varchar(200) = 'i went to the supermarket yesterday with a friend'
Declare @individual varchar(20) = null

WHILE LEN(@products) > 0
BEGIN
IF PATINDEX('% %',@products) > 0
BEGIN
SET @individual = SUBSTRING(@products, 0, PATINDEX('% %',@products))
SELECT @individual

SET @products = SUBSTRING(@products, LEN(@individual + '|') + 1,
LEN(@products))
END
ELSE
BEGIN
SET @individual = @products
SET @products = NULL
SELECT @individual
END
END

and i get this result:

i
went
to
the
supermarket
yesterday
with
a
friend

i separate them by space now how can i concatenate each two string with each other:
select * from mytable where title like '%i went to the supermarket yesterday with a friend%'

and

select * from mytable where title like '%i went%'

and

select * from mytable where title like '%to the%'

and

select * from mytable where title like '%supermarket yesterday%'

and

select * from mytable where title like '%with a%'

and

select * from mytable where title like '%friend%'
ravitv 15-May-21 7:32am    
Great Member_10266297 for sharing this code without prejudice.

1 solution

This is not a trivial job, and you are going to have to do some serious reading.
Start with MSDN: http://msdn.microsoft.com/en-us/library/ms142571.aspx[^]
Then try this: http://ewbi.blogs.com/develops/2007/05/normalizing_sql.html[^] once you have done all the basics from the MS links.
 
Share this answer
 
Comments
Member 10266297 22-Aug-14 4:58am    
Thank you very much OriginalFGriff it is very helpful

SELECT *
FROM dbo.mytable
INNER JOIN FREETEXTTABLE(dbo.mytable,Name,'search Key') FT
ON mytable.Id = FT.[Key]
ORDER BY RANK DESC
OriginalGriff 22-Aug-14 5:01am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900