I'm attempting to implement a search, the actual search uses CONTAINSTABLE - but here is an example using just CONTAINS:
The first query will return anything with "micro" in it, the second will only get words that start with "micro".
I'd really like to be able to search anywhere within the column (not just the beginning of words), with CONTAINS/CONTAINSTABLE - as I wouldn't have to refactor the entire search query (and what builds it).
Here is the search query (the group by doesn't really have vpl.*, but it trims down on the numerous columns vpl has).
Any ideas on how to search columns this way?
Code:
SELECT * FROM _productsearch WHERE searchtext LIKE '%micro%'
SELECT * FROM _productsearch WHERE CONTAINS(searchtext, ' "*micro*" ')
I'd really like to be able to search anywhere within the column (not just the beginning of words), with CONTAINS/CONTAINSTABLE - as I wouldn't have to refactor the entire search query (and what builds it).
Here is the search query (the group by doesn't really have vpl.*, but it trims down on the numerous columns vpl has).
Code:
WITH searchProd AS (
SELECT
ROW_NUMBER() OVER(ORDER BY SUM(st.[RANK]) DESC) AS RowNum,
st.productid,
vpl.*,
SUM(st.[RANK]) AS [search-rank]
FROM
(SELECT ps.productid, kt.RANK FROM _productsearch ps INNER JOIN CONTAINSTABLE(_productsearch, searchtext, '"*micro*"') AS kt ON ps.searchidx = kt.[KEY]) AS st LEFT OUTER JOIN
(SELECT * FROM v_productlisting) AS vpl ON st.productid = vpl.productid
WHERE st.productid NOT IN ('') AND vpl.mfgpartno IS NOT NULL
GROUP BY st.productid, vpl.*
)
SELECT * FROM searchProd WHERE RowNum BETWEEN 1 AND 15
Any ideas on how to search columns this way?