문제

SELECT cat.CategoryId
  ,cat.CategoryImageURL
  ,cat.CategoryName
  ,cat.isDeleted
  ,ap.AppCreatedBy
  ,ap.AppCreatedOn
  ,ap.AppDetails
  ,ap.AppId
  ,ap.AppImageURL
  ,ap.AppModifiedBy
  ,ap.AppModifiedOn
  ,ap.AppName
  ,ap.isDeleted
  ,subcat.SubCategoryId
  ,subcat.SubCategoryName
  ,subcat.SubCategoryImageUrl
FROM Category cat
INNER JOIN App ap
  ON cat.CategoryID = ap.CategoryID
INNER JOIN SubCategory subcat
  ON subcat.SubCategoryId = ap.SubCategoryId
WHERE FREETEXT (
    cat.CategoryName
    ,@searchparameter
    )
  OR FREETEXT (
    subcat.SubCategoryName
    ,@searchparameter
    )
  OR FREETEXT (
    ap.AppName
    ,@searchparameter
    )
  OR CONTAINS (
    ap.AppDetails
    ,@searchparameter
    )
  OR CONTAINS (
    cat.CategoryName
    ,@searchparameter
    )
  OR CONTAINS (
    subcat.SubCategoryName
    ,@searchparameter
    )
  OR CONTAINS (
    ap.AppName
    ,@searchparameter
    )
  OR CONTAINS (
    ap.AppDetails
    ,@searchparameter
    )

USE [AppStore]
GO

DECLARE @return_value INT

EXEC @return_value = [dbo].[IndianAppStore_Search] @searchparameter = N'wishpicker'

SELECT 'Return Value' = @return_value
GO

In the AppName column in App table there is a row which contains wishpicker as an AppName i want to show this result even if the user writes only wish for the search query.

Is that possible with freetext or any other search algo in sql server?

도움이 되었습니까?

해결책

Read up on the LIKE keyword. But in short...

WHERE (ap.AppName LIKE 'wish%')  -- Finds app names BEGINNING with wish
WHERE (ap.AppName LIKE '%wish%') -- Finds app names CONTAINING wish
WHERE (ap.AppName LIKE '%wish')  -- Finds app names ENDING with wish

다른 팁

How about adding this condition?

OR (@searchparameter = 'wish' and ap.AppName = 'wishpicker')

Or, if the AppName field needs wildcards:

OR (@searchparameter = 'wish' and ap.AppName like '%wishpicker%')
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top