I made a class for the search engine, that returns me one string consonant the words that I want to search and if it is for method âORâ or âANDâ.
I have two ways to solve the problem:
Or I pull one dataset entire with all the topics, or use the current system of the topics that is to pull alone dataset with the topics of a single page.
I prefer to only pull the topics of a page.
For this I liked to keep stored procedure and to only send string to make the search.
Let see :
If i wanted to search de word "blabla" i will send the string:
Code:
*** WHERE TopiRep.Message LIKE '%blabla%' OR Topi.Subject LIKE '%blabla%' ***
But this procedure should be prepared for 2... 4... 6... words
so, there is my procedure:
Code:
CREATE PROCEDURE sp_Forums_SearchWord
@myStr varchar(500),
@PageNumber int,
@PageSize int
AS
CREATE TABLE #TempSearchWord
(
ID int IDENTITY PRIMARY KEY,
TopicID int,
CategoryID int,
ForumID int,
Subject varchar(100),
AddedDate datetime,
TopicReplies int,
TopicLastReplyDate datetime,
TopicLastPostDate datetime,
MemberID int,
MemberName varchar(15),
LastMemberID int,
LastMemberName varchar(15)
)
INSERT INTO #TempSearchWord
(
TopicID,
CategoryID,
ForumID,
Subject,
AddedDate,
TopicReplies,
TopicLastReplyDate,
TopicLastPostDate,
MemberID,
MemberName,
LastMemberID,
LastMemberName
)
SELECT
DISTINCT(a.TopicID),
a.CategoryID,
a.ForumID,
a.Subject,
a.AddedDate,
a.TopicReplies,
a.TopicLastReplyDate,
a.TopicLastPostDate,
a.MemberID,
a.MemberName,
a.LastMemberID,
(SELECT Forums_Members.MemberName FROM Forums_Members WHERE Forums_Members.MemberID = a.LastMemberID) as LastMemberName
FROM
v_Forums_Topics a INNER JOIN (SELECT DISTINCT(TopiRep.TopicID) FROM (SELECT Forums_Topics.TopicID, Forums_Topics.Message FROM Forums_Topics UNION ALL SELECT Forums_Replies.TopicID, Forums_Replies.Message FROM Forums_Replies) TopiRep INNER JOIN Forums_Topics Topi ON Topi.TopicID = TopiRep.TopicID
@myStr --WHERE TopiRep.Message LIKE '%blabla%' OR Topi.Subject LIKE '%blabla%'
) as Results on Results.TopicID = a.TOPICID
ORDER BY TopicLastPostDate Desc
DECLARE @FromID int
DECLARE @ToID int
SET @FromID = ((@PageNumber - 1) * @PageSize) + 1
SET @ToID = @PageNumber * @PageSize
SELECT TopicID,
CategoryID,
ForumID,
Subject,
AddedDate,
TopicReplies,
TopicLastReplyDate,
TopicLastPostDate,
MemberID,
MemberName,
LastMemberID,
LastMemberName
FROM #TempSearchWord WHERE ID >= @FromID AND ID <= @ToID
GO
Please help me to make that this procedure can receive the string of search for the some words that I to want to search.
I already tried of everything without success!
If somebody want the class that sends the string for sql i can share this with you...
Thanks,
Max, from Portugal