I have a Full-text search on view, the view returns all approved businesses & meta data about said business.
I implemented a stored procedure to utilize the full-text search with the following code:
CREATE PROCEDURE [dbo].[Search]
@SearchTerm varchar(8000),
@CurrentPage int = 1,
@PageSize int = 100
AS
BEGIN
DECLARE @NearPredicate varchar(8000),
@AndPredicate varchar(8000),
@TotalRecords int
SELECT
@NearPredicate = COALESCE(@NearPredicate + ' NEAR ', '') + Data
FROM Split(@SearchTerm, ' ')
LEFT JOIN sys.fulltext_system_stopwords ON Data = stopword
WHERE stopword IS NULL
SET @AndPredicate = REPLACE(@NearPredicate, 'NEAR', 'AND')
SET @NearPredicate = '(' + @NearPredicate + ')'
SET @TotalRecords = (
SELECT
COUNT(*)
FROM
vwApprovedBusiness
WHERE FREETEXT(*, @AndPredicate )
)
SELECT *,
ct.Rank,
@TotalRecords AS TotalRecords
FROM
vwApprovedBusiness a
INNER JOIN FREETEXTTABLE (vwApprovedBusiness, *, @NearPredicate ) AS ct ON a.MyBusinessID = ct.[KEY]
ORDER BY
ct.RANK DESC
OFFSET (@CurrentPage - 1) * @PageSize ROWS FETCH NEXT @PageSize ROWS only
END
If I search for a Business Name e.g. One Guy Transport which is an approved business, it only shows up in my search results around 6th or 7th and not the first result as expected. Any assistance with this would be greatly appreciated!