Important Notice from AspDotNetStorefront
It is with dismay that we report that we have been forced, through the action of hackers, to shut off write-access to this forum. We are keen to leave the wealth of material available to you for research. We have opened a new forum from which our community of users can seek help, support and advice from us and from each other. To post a new question to our community, please visit: http://forums.vortx.com
Results 1 to 22 of 22

Thread: Full Text Search Question

  1. #1
    akeller is offline Member
    Join Date
    Dec 2008
    Posts
    78

    Default Full Text Search Question

    I setup full text search on our dev and staging site and I am confused on the results. I have set the full text index on the product table to just use the Name column for now.

    The manual indicates;
    "With the standard search features, if a customer looks for "Green shirt", only products that have exactly that phrase in that order will be returned. With full text search, the same query would return all products that contain the word "green" and all products that contain the word "shirt", with products that contain the phrase "green shirt" placed higher in the results list."

    So would "placed higher in the results" indicate that the search results returned for "Green Shirt" on the search.aspx page would have "Green Shirt" listed before "Green Pants", "Green Jacket" etc?

    As it is now this is not that case for me. My search results appear to be returned in alphanumeric order. How do I set the search results to be ordered by relevance to the search term?

    Thanks in advance.

  2. #2
    mmcgeachy is offline Senior Member
    Join Date
    Sep 2008
    Posts
    174

    Default

    This would require editing the KeyWordSearch function made when enabling full text search is enabled and/or editing of the aspdnsf_GetProducts stored procedure.

    The reason for that is so you can use FREETEXTTABLE instead of FREETEXT so the rank information is returned.

    Hope this helps.

  3. #3
    harsha.gus is offline Senior Member
    Join Date
    Mar 2009
    Posts
    301

    Exclamation Could you please elaborate

    Quote Originally Posted by mmcgeachy View Post
    This would require editing the KeyWordSearch function made when enabling full text search is enabled and/or editing of the aspdnsf_GetProducts stored procedure.

    The reason for that is so you can use FREETEXTTABLE instead of FREETEXT so the rank information is returned.

    Hope this helps.
    Could you please elaborate or provide a sample code
    because i have the same problem.

    sincerely appreciate your effort.

    thanks
    rbgx
    AspDotNetStorefront ML
    v8.0.1.4

  4. #4
    mmcgeachy is offline Senior Member
    Join Date
    Sep 2008
    Posts
    174

    Default

    Sure will try explain as best I can but full text search a little bit complex. Also please don't take the example I give as the end all example that will work for everything. This is because one of the reasons full text search can be complex is it has a decent amount of options.

    Each row/search result can has a rank saying how relevant the result is. Since FREETEXT is used in the where statement of SQL the rank information can't be returned there. To get the information returned we need to use a table instead which FREETEXTTABLE does. The way to filter with using a table is joins. So for example here this SQL statement loosely based off of the aspdnsf_GetProducts procedure:

    C#/VB.NET Code:
    declare @searchstr nvarchar(4000)
    declare @
    ViewType bit
    declare @categoryID int, @sectionID int, @localeID int,@affiliateID int, @manufacturerID int,@distributorID int, @genreID int, @vectorID int ,@ProductTypeID int, @OnSaleOnly int, @publishedonly int, @ExcludePacks int, @ExcludeKits int, @ExcludeSysProds int
    set 
    @localeID=0
    set 
    @categoryID 0
    set 
    @searchstr 'Pallet Rack'
    set @ViewType =0
    set 
    @affiliateID=0
    set 
    @OnSaleOnly=0
    set 
    @publishedonly=0
    set 
    @ExcludePacks=0
    set 
    @ExcludeKits=0
    set 
    @ExcludeSysProds=0
    declare @CustomerLevelID int
    set 
    @CustomerLevelID=null

    SET 
    @categoryID      nullif(@categoryID0)
        
    SET @sectionID       nullif(@sectionID0)
        
    SET @manufacturerID  nullif(@manufacturerID0)
        
    SET @distributorID   nullif(@distributorID0)
        
    SET @genreID         nullif(@genreID0)
        
    SET @vectorID        nullif(@vectorID0)
        
    SET @affiliateID     nullif(@affiliateID0)
        
    SET @ProductTypeID   nullif(@ProductTypeID0)
    DECLARE @
    FilterProductsByAffiliate tinyint, @FilterProductsByCustomerLevel tinyint, @HideProductsWithLessThanThisInventoryLevel int
    SELECT 
    @FilterProductsByAffiliate = case ConfigValue when 'true' then 1 else 0 end FROM dbo.AppConfig with (nolockWHERE [Name] = 'FilterProductsByAffiliate'
        
    SELECT @FilterProductsByCustomerLevel = case ConfigValue when 'true' then 1 else 0 end FROM dbo.AppConfig with (nolockWHERE [Name] = 'FilterProductsByCustomerLevel'
        
    SELECT @HideProductsWithLessThanThisInventoryLevel convert(intConfigValueFROM dbo.AppConfig with (nolockWHERE [Name] = 'HideProductsWithLessThanThisInventoryLevel' and isnumeric(ConfigValue) = 1

    DECLARE @custlevelcount int, @sectioncount int, @localecount int, @affiliatecount int, @categorycount int, @CustomerLevelFilteringIsAscending bit, @distributorcount int, @genrecount int, @vectorcount int, @manufacturercount int
     select 
    @categorycount     si.rows from sysobjects so with (nolockjoin sysindexes si with (nolockon so.id si.id where so.id object_id('productcategory') and si.indid and type 'u'
        
    select @sectioncount      si.rows from sysobjects so with (nolockjoin sysindexes si with (nolockon so.id si.id where so.id object_id('productsection') and si.indid and type 'u'
        
    select @localecount       si.rows from sysobjects so with (nolockjoin sysindexes si with (nolockon so.id si.id where so.id object_id('ProductLocaleSetting') and si.indid and type 'u'
        
    select @custlevelcount    si.rows from sysobjects so with (nolockjoin sysindexes si with (nolockon so.id si.id where so.id object_id('ProductCustomerLevel') and si.indid and type 'u'
        
    select @affiliatecount    si.rows from sysobjects so with (nolockjoin sysindexes si with (nolockon so.id si.id where so.id object_id('ProductAffiliate') and si.indid and type 'u'
        
    select @distributorcount  si.rows from sysobjects so with (nolockjoin sysindexes si with (nolockon so.id si.id where so.id object_id('ProductDistributor') and si.indid and type 'u'
        
    select @genrecount        si.rows from sysobjects so with (nolockjoin sysindexes si with (nolockon so.id si.id where so.id object_id('ProductGenre') and si.indid and type 'u'
        
    select @vectorcount       si.rows from sysobjects so with (nolockjoin sysindexes si with (nolockon so.id si.id where so.id object_id('ProductVector') and si.indid and type 'u'
        
    select @manufacturercount si.rows from sysobjects so with (nolockjoin sysindexes si with (nolockon so.id si.id where so.id object_id('ProductManufacturer') and si.indid and type 'u'

    SELECT distinct p.productidpv.VariantIDpv.DisplayOrderp.Namepv.Name,ft.rank
            FROM 
                product p with 
    (nolock)
                
    inner join FREETEXTTABLE (product,(*),@searchstr) as ft on p.ProductID=ft.[key]            
                
    join ProductVariant pv             with (NOLOCKon p.ProductID pv.ProductID and pv.IsDefault >= @ViewType
                left join productcategory pc       with 
    (nolockon p.ProductID pc.ProductID 
                left join productsection ps        with 
    (nolockon p.ProductID ps.ProductID 
                left join ProductManufacturer pm   with 
    (nolockon p.ProductID pm.ProductID 
                left join ProductDistributor pd    with 
    (nolockon p.ProductID pd.ProductID 
                left join ProductGenre px          with 
    (nolockon p.ProductID px.ProductID 
                left join ProductVector px2        with 
    (nolockon p.ProductID px2.ProductID 
                left join ProductLocaleSetting pl  with 
    (nolockon p.ProductID pl.ProductID 
                left join ProductCustomerLevel pcl with 
    (nolockon p.ProductID pcl.ProductID 
                left join ProductAffiliate pa      with 
    (nolockon p.ProductID pa.ProductID 
                
            WHERE 
                  
    (pc.categoryid = @categoryID or @categoryID is null or @categorycount 0)
              and (
    ps.sectionid = @sectionID or @sectionID is null or @sectioncount 0)
              and (
    pl.LocaleSettingID = @localeID or @localeID is null or @localecount 0)
              and (
    pa.AffiliateID = @affiliateID or pa.AffiliateID is null or @affiliatecount or @FilterProductsByAffiliate 0)
              and (
    pm.manufacturerid = @manufacturerID or @manufacturerID is null or @manufacturercount 0)
              and (
    pd.DistributorID = @distributorID or @distributorID is null or @distributorcount 0)
              and (
    px.GenreID = @genreID or @genreID is null or @genrecount 0)
              and (
    px2.VectorID = @vectorID or @vectorID is null or @vectorcount 0)
              and 
    p.ProductTypeID coalesce(@ProductTypeIDp.ProductTypeID)
              and (case 
                    
    when @FilterProductsByCustomerLevel or @custlevelcount or pcl.CustomerLevelID is null or @CustomerLevelID is null then 1
                    when 
    @CustomerLevelFilteringIsAscending and pcl.CustomerLevelID <= @CustomerLevelID then 1 
                    when pcl
    .CustomerLevelID = @CustomerLevelID or pcl.CustomerLevelID is null then 1 
                    
    else 0
                   end  
    1
                  
    )
              or (
                     @
    searchstr is null
                  
    or patindex(@searchstrisnull(convert(nvarchar(20),p.productid), '')) > 0              
                  
    )
              and case 
    when isnull(pv.saleprice,0) = 0 then 0 else 1 end >= @OnSaleOnly
              
    and p.published >= @publishedonly
              
    and pv.published >= @publishedonly
              
    and isnull(p.IsAPack0) <= 1-@ExcludePacks
              
    and isnull(p.IsAKit0) <= 1-@ExcludeKits
              
    and p.IsSystem <= 1-@ExcludeSysProds
              
    and p.Deleted 0
              
    and pv.Deleted 0
              
    and getdate() between isnull(p.AvailableStartDate'1/1/1900') and isnull(p.AvailableStopDate'1/1/2999')
            
    order by ft.rank desc,p.Namepv.DisplayOrderpv.Name 
    Hopefully this example is helpful enough to get the basic idea of what I'm talking about.

  5. #5
    akeller is offline Member
    Join Date
    Dec 2008
    Posts
    78

    Default

    Should this example work on it's own? As it is I get a an error when trying to execute the example;

    Error: Msg 206, Level 16, State 2, Line 41
    Operand type clash: uniqueidentifier is incompatible with int

    Which appears to be an issue with trying to join the FREETEXTTABLE by using the FREETEXTTABLE Key(which is a uniqueidentifier) and the Product Table ProductID (which is an INT).

    Wouldn't you need to compare the ProductGUID? I don't know if that would work.

    Any ideas?
    Last edited by akeller; 01-06-2011 at 12:24 PM.

  6. #6
    mmcgeachy is offline Senior Member
    Join Date
    Sep 2008
    Posts
    174

    Default

    Opps sorry about that. I was basing this of the full text search I use which was made before full text search was offered fully out of the box. Should still be an easy fix to make in the SQL statment.

    Change

    C#/VB.NET Code:
    inner join FREETEXTTABLE (product,(*),@searchstr) as ft on p.ProductID=ft.[key
    to

    C#/VB.NET Code:
    inner join FREETEXTTABLE (product,(*),@searchstr) as ft on p.ProductGUID=ft.[key

  7. #7
    akeller is offline Member
    Join Date
    Dec 2008
    Posts
    78

    Default

    Yeah that is what I ended up doing and it works fantastically!

    Thanks for sharing your code with us.

  8. #8
    harsha.gus is offline Senior Member
    Join Date
    Mar 2009
    Posts
    301

    Exclamation Can you please help me

    Quote Originally Posted by akeller View Post
    Yeah that is what I ended up doing and it works fantastically!

    Thanks for sharing your code with us.
    hi i need the same issue to be fixed, but i didn't understand where to put the above code, can you please help me understanding this changes.

    which file i should edit what are the changes i have to do.

    thanks you very much for your help.


    thanks
    rbgx
    AspDotNetStorefront ML
    v8.0.1.4

  9. #9
    mmcgeachy is offline Senior Member
    Join Date
    Sep 2008
    Posts
    174

    Default

    Mostly what that example shows is how to get the rank information from full text search. As for how to do the changes you would need alter the aspdnsf_GetProducts procedure in the SQL database.

    There are two options on how to alter it though that I can think of off hand. One would edit the KeyWordSearch function, add a rank column to the displayorder temporary table and then add sorting by rank in front of do.displayorder.

    The second would be to take the full text search out of the displayorder table, add full text search in a sql join statement, and then add sorting by rank in front of do.displayorder

    The reason I don't want show an alter procedure statement is I use some extra columns that aren't there normally out of the box and other things that are easy for me to forget about due being a somewhat larger SQL statement. Also aspdnsf_GetProducts effects more than just the search pages. For that reason I would recommend testing alterations to aspdnsf_GetProducts on a staging or development sever 1st.

  10. #10
    harsha.gus is offline Senior Member
    Join Date
    Mar 2009
    Posts
    301

    Exclamation conclusion

    Quote Originally Posted by mmcgeachy View Post
    Mostly what that example shows is how to get the rank information from full text search. As for how to do the changes you would need alter the aspdnsf_GetProducts procedure in the SQL database.

    There are two options on how to alter it though that I can think of off hand. One would edit the KeyWordSearch function, add a rank column to the displayorder temporary table and then add sorting by rank in front of do.displayorder.

    The second would be to take the full text search out of the displayorder table, add full text search in a sql join statement, and then add sorting by rank in front of do.displayorder

    The reason I don't want show an alter procedure statement is I use some extra columns that aren't there normally out of the box and other things that are easy for me to forget about due being a somewhat larger SQL statement. Also aspdnsf_GetProducts effects more than just the search pages. For that reason I would recommend testing alterations to aspdnsf_GetProducts on a staging or development sever 1st.
    so if i run below Code in my SQL Server, i will get my requirement right?

    HTML Code:
    declare @searchstr nvarchar(4000) 
    declare @ViewType bit 
    declare @categoryID int, @sectionID int, @localeID int,@affiliateID int, @manufacturerID int,@distributorID int, @genreID int, @vectorID int ,@ProductTypeID int, @OnSaleOnly int, @publishedonly int, @ExcludePacks int, @ExcludeKits int, @ExcludeSysProds int 
    set @localeID=0 
    set @categoryID = 0 
    set @searchstr = 'Pallet Rack' 
    set @ViewType =0 
    set @affiliateID=0 
    set @OnSaleOnly=0 
    set @publishedonly=0 
    set @ExcludePacks=0 
    set @ExcludeKits=0 
    set @ExcludeSysProds=0 
    declare @CustomerLevelID int 
    set @CustomerLevelID=null 
    
    SET @categoryID      = nullif(@categoryID, 0) 
        SET @sectionID       = nullif(@sectionID, 0) 
        SET @manufacturerID  = nullif(@manufacturerID, 0) 
        SET @distributorID   = nullif(@distributorID, 0) 
        SET @genreID         = nullif(@genreID, 0) 
        SET @vectorID        = nullif(@vectorID, 0) 
        SET @affiliateID     = nullif(@affiliateID, 0) 
        SET @ProductTypeID   = nullif(@ProductTypeID, 0) 
    DECLARE @FilterProductsByAffiliate tinyint, @FilterProductsByCustomerLevel tinyint, @HideProductsWithLessThanThisInventoryLevel int 
    SELECT @FilterProductsByAffiliate = case ConfigValue when 'true' then 1 else 0 end FROM dbo.AppConfig with (nolock) WHERE [Name] = 'FilterProductsByAffiliate' 
        SELECT @FilterProductsByCustomerLevel = case ConfigValue when 'true' then 1 else 0 end FROM dbo.AppConfig with (nolock) WHERE [Name] = 'FilterProductsByCustomerLevel' 
        SELECT @HideProductsWithLessThanThisInventoryLevel = convert(int, ConfigValue) FROM dbo.AppConfig with (nolock) WHERE [Name] = 'HideProductsWithLessThanThisInventoryLevel' and isnumeric(ConfigValue) = 1 
    
    DECLARE @custlevelcount int, @sectioncount int, @localecount int, @affiliatecount int, @categorycount int, @CustomerLevelFilteringIsAscending bit, @distributorcount int, @genrecount int, @vectorcount int, @manufacturercount int 
     select @categorycount     = si.rows from sysobjects so with (nolock) join sysindexes si with (nolock) on so.id = si.id where so.id = object_id('productcategory') and si.indid < 2 and type = 'u' 
        select @sectioncount      = si.rows from sysobjects so with (nolock) join sysindexes si with (nolock) on so.id = si.id where so.id = object_id('productsection') and si.indid < 2 and type = 'u' 
        select @localecount       = si.rows from sysobjects so with (nolock) join sysindexes si with (nolock) on so.id = si.id where so.id = object_id('ProductLocaleSetting') and si.indid < 2 and type = 'u' 
        select @custlevelcount    = si.rows from sysobjects so with (nolock) join sysindexes si with (nolock) on so.id = si.id where so.id = object_id('ProductCustomerLevel') and si.indid < 2 and type = 'u' 
        select @affiliatecount    = si.rows from sysobjects so with (nolock) join sysindexes si with (nolock) on so.id = si.id where so.id = object_id('ProductAffiliate') and si.indid < 2 and type = 'u' 
        select @distributorcount  = si.rows from sysobjects so with (nolock) join sysindexes si with (nolock) on so.id = si.id where so.id = object_id('ProductDistributor') and si.indid < 2 and type = 'u' 
        select @genrecount        = si.rows from sysobjects so with (nolock) join sysindexes si with (nolock) on so.id = si.id where so.id = object_id('ProductGenre') and si.indid < 2 and type = 'u' 
        select @vectorcount       = si.rows from sysobjects so with (nolock) join sysindexes si with (nolock) on so.id = si.id where so.id = object_id('ProductVector') and si.indid < 2 and type = 'u' 
        select @manufacturercount = si.rows from sysobjects so with (nolock) join sysindexes si with (nolock) on so.id = si.id where so.id = object_id('ProductManufacturer') and si.indid < 2 and type = 'u' 
    
    SELECT distinct p.productid, pv.VariantID, pv.DisplayOrder, p.Name, pv.Name,ft.rank 
            FROM  
                product p with (nolock) 
                inner join FREETEXTTABLE (product,(*),@searchstr) as ft on p.ProductGUID=ft.[key]  
                join ProductVariant pv             with (NOLOCK) on p.ProductID = pv.ProductID and pv.IsDefault >= @ViewType 
                left join productcategory pc       with (nolock) on p.ProductID = pc.ProductID  
                left join productsection ps        with (nolock) on p.ProductID = ps.ProductID  
                left join ProductManufacturer pm   with (nolock) on p.ProductID = pm.ProductID  
                left join ProductDistributor pd    with (nolock) on p.ProductID = pd.ProductID  
                left join ProductGenre px          with (nolock) on p.ProductID = px.ProductID  
                left join ProductVector px2        with (nolock) on p.ProductID = px2.ProductID  
                left join ProductLocaleSetting pl  with (nolock) on p.ProductID = pl.ProductID  
                left join ProductCustomerLevel pcl with (nolock) on p.ProductID = pcl.ProductID  
                left join ProductAffiliate pa      with (nolock) on p.ProductID = pa.ProductID  
                 
            WHERE  
                  (pc.categoryid = @categoryID or @categoryID is null or @categorycount = 0) 
              and (ps.sectionid = @sectionID or @sectionID is null or @sectioncount = 0) 
              and (pl.LocaleSettingID = @localeID or @localeID is null or @localecount = 0) 
              and (pa.AffiliateID = @affiliateID or pa.AffiliateID is null or @affiliatecount = 0 or @FilterProductsByAffiliate = 0) 
              and (pm.manufacturerid = @manufacturerID or @manufacturerID is null or @manufacturercount = 0) 
              and (pd.DistributorID = @distributorID or @distributorID is null or @distributorcount = 0) 
              and (px.GenreID = @genreID or @genreID is null or @genrecount = 0) 
              and (px2.VectorID = @vectorID or @vectorID is null or @vectorcount = 0) 
              and p.ProductTypeID = coalesce(@ProductTypeID, p.ProductTypeID) 
              and (case  
                    when @FilterProductsByCustomerLevel = 0 or @custlevelcount = 0 or pcl.CustomerLevelID is null or @CustomerLevelID is null then 1 
                    when @CustomerLevelFilteringIsAscending = 1 and pcl.CustomerLevelID <= @CustomerLevelID then 1  
                    when pcl.CustomerLevelID = @CustomerLevelID or pcl.CustomerLevelID is null then 1  
                    else 0 
                   end  = 1 
                  ) 
              or ( 
                     @searchstr is null 
                  or patindex(@searchstr, isnull(convert(nvarchar(20),p.productid), '')) > 0               
                  ) 
              and case when isnull(pv.saleprice,0) = 0 then 0 else 1 end >= @OnSaleOnly 
              and p.published >= @publishedonly 
              and pv.published >= @publishedonly 
              and isnull(p.IsAPack, 0) <= 1-@ExcludePacks 
              and isnull(p.IsAKit, 0) <= 1-@ExcludeKits 
              and p.IsSystem <= 1-@ExcludeSysProds 
              and p.Deleted = 0 
              and pv.Deleted = 0 
              and getdate() between isnull(p.AvailableStartDate, '1/1/1900') and isnull(p.AvailableStopDate, '1/1/2999') 
            order by ft.rank desc,p.Name, pv.DisplayOrder, pv.Name
    rbgx
    AspDotNetStorefront ML
    v8.0.1.4

  11. #11
    harsha.gus is offline Senior Member
    Join Date
    Mar 2009
    Posts
    301

    Exclamation can you provide your Alter aspdnsf_GetProducts

    can you please provide your Alter aspdnsf_GetProducts code

    so that i will alter the Procedure.


    thanks
    rbgx
    AspDotNetStorefront ML
    v8.0.1.4

  12. #12
    mmcgeachy is offline Senior Member
    Join Date
    Sep 2008
    Posts
    174

    Default

    Ok just be warned anyone that uses this alter proc script may not have the script work right at the start... It more than likely will work with small tweaks will be done. I do not grantee 100% that things will work right from the start however. This is due customizations I have done, different versions, ect.

    The stored procedure depends on a few code changes being done to the search page code behind and the search xmlpackage. This is due to feature to help filter out more certain words also But I will talk about those later here is the alter statement:

    C#/VB.NET Code:
    ALTER proc [dbo].[aspdnsf_GetProducts]
        @
    categoryID      int null,
        @
    sectionID       int null,
        @
    manufacturerID  int null,
        @
    distributorID   int null,
        @
    genreID         int null,
        @
    vectorID        int null,
        @
    localeID        int null,
        @
    CustomerLevelID int null,
        @
    affiliateID     int null,
        @
    ProductTypeID   int null,
        @
    ViewType        bit 1, -- all variantsone variant
        
    @sortEntity      int 0, -- categorysectionmanufacturerdistributor5genrevector
        
    @pagenum         int 1,
        @
    pagesize        int null,
        @
    StatsFirst      tinyint 1,
        @
    searchstr       nvarchar(4000) = null,
        @
    searchstr2       nvarchar(4000) = null,
        @
    extSearch       tinyint 0,
        @
    publishedonly   tinyint 0,
        @
    ExcludePacks    tinyint 0,
        @
    ExcludeKits     tinyint 0,
        @
    ExcludeSysProds tinyint 0,
        @
    InventoryFilter int 0,  --  will only show products with an inventory level GREATER OR EQUAL TO than the number specified in this parameterset to -1 to disable inventory filtering
        
    @sortEntityName  varchar(20) = '', -- usely only when the entity id is providedallowed valuescategorysectionmanufacturerdistributorgenrevector
        
    @localeName      varchar(20) = '',
        @
    OnSaleOnly      tinyint 0,
        @
    IncludeAll      bit 0, -- Don't filter products that have a start date in the future or a stop date in the past  
        @storeID         int = 1,
        @filterProduct     bit = 0
    AS
    BEGIN

        SET NOCOUNT ON 

        DECLARE @rcount int
        DECLARE @productfilter table (rownum int not null identity  primary key, productid int not null,displayorder int null, VariantID int not null, VariantDisplayOrder int not null, ProductName nvarchar(400) null, VariantName nvarchar(400) null, [rank] int null)
        DECLARE @FilterProductsByAffiliate tinyint, @FilterProductsByCustomerLevel tinyint, @HideProductsWithLessThanThisInventoryLevel int
        CREATE TABLE #displayorder ([name] nvarchar (800), productid int not null primary key, displayorder int not null)
        CREATE TABLE #inventoryfilter (productid int not null, variantid int not null, InvQty int not null)
        CREATE CLUSTERED INDEX tmp_inventoryfilter ON #inventoryfilter (productid, variantid)

        DECLARE @custlevelcount int, @sectioncount int, @localecount int, @affiliatecount int, @categorycount int, @CustomerLevelFilteringIsAscending bit, @distributorcount int, @genrecount int, @vectorcount int, @manufacturercount int

        SELECT @FilterProductsByAffiliate = case ConfigValue when '
    true' then 1 else 0 end FROM dbo.AppConfig with (nolock) WHERE [Name] = 'FilterProductsByAffiliate'
        SELECT @FilterProductsByCustomerLevel = case ConfigValue when '
    true' then 1 else 0 end FROM dbo.AppConfig with (nolock) WHERE [Name] = 'FilterProductsByCustomerLevel'
        SELECT @HideProductsWithLessThanThisInventoryLevel = convert(int, ConfigValue) FROM dbo.AppConfig with (nolock) WHERE [Name] = '
    HideProductsWithLessThanThisInventoryLevel' and isnumeric(ConfigValue) = 1

        IF @InventoryFilter <> -1 and (@HideProductsWithLessThanThisInventoryLevel > @InventoryFilter or @HideProductsWithLessThanThisInventoryLevel  = -1)
            SET @InventoryFilter  = @HideProductsWithLessThanThisInventoryLevel


        SET @categoryID      = nullif(@categoryID, 0)
        SET @sectionID       = nullif(@sectionID, 0)
        SET @manufacturerID  = nullif(@manufacturerID, 0)
        SET @distributorID   = nullif(@distributorID, 0)
        SET @genreID         = nullif(@genreID, 0)
        SET @vectorID        = nullif(@vectorID, 0)
        SET @affiliateID     = nullif(@affiliateID, 0)
        SET @ProductTypeID   = nullif(@ProductTypeID, 0)


        SET @CustomerLevelFilteringIsAscending  = 0
        SELECT @CustomerLevelFilteringIsAscending  = case configvalue when '
    true' then 1 else 0 end
        FROM dbo.AppConfig with (nolock) 
        WHERE name = '
    FilterByCustomerLevelIsAscending'

        IF @localeID is null and ltrim(rtrim(@localeName)) <> ''
            SELECT @localeID = LocaleSettingID FROM dbo.LocaleSetting with (nolock) WHERE Name = ltrim(rtrim(@localeName))

        select @categorycount     = si.rows from sysobjects so with (nolock) join sysindexes si with (nolock) on so.id = si.id where so.id = object_id('
    productcategory') and si.indid < 2 and type = 'u'
        select @sectioncount      = si.rows from sysobjects so with (nolock) join sysindexes si with (nolock) on so.id = si.id where so.id = object_id('
    productsection') and si.indid < 2 and type = 'u'
        select @localecount       = si.rows from sysobjects so with (nolock) join sysindexes si with (nolock) on so.id = si.id where so.id = object_id('
    ProductLocaleSetting') and si.indid < 2 and type = 'u'
        select @custlevelcount    = si.rows from sysobjects so with (nolock) join sysindexes si with (nolock) on so.id = si.id where so.id = object_id('
    ProductCustomerLevel') and si.indid < 2 and type = 'u'
        select @affiliatecount    = si.rows from sysobjects so with (nolock) join sysindexes si with (nolock) on so.id = si.id where so.id = object_id('
    ProductAffiliate') and si.indid < 2 and type = 'u'
        select @distributorcount  = si.rows from sysobjects so with (nolock) join sysindexes si with (nolock) on so.id = si.id where so.id = object_id('
    ProductDistributor') and si.indid < 2 and type = 'u'
        select @genrecount        = si.rows from sysobjects so with (nolock) join sysindexes si with (nolock) on so.id = si.id where so.id = object_id('
    ProductGenre') and si.indid < 2 and type = 'u'
        select @vectorcount       = si.rows from sysobjects so with (nolock) join sysindexes si with (nolock) on so.id = si.id where so.id = object_id('
    ProductVector') and si.indid < 2 and type = 'u'
        select @manufacturercount = si.rows from sysobjects so with (nolock) join sysindexes si with (nolock) on so.id = si.id where so.id = object_id('
    ProductManufacturer') and si.indid < 2 and type = 'u'


        -- get page size  
        IF @pagesize is null or @pagesize = 0 BEGIN  
            IF @categoryID is not null  
                SELECT @pagesize = PageSize FROM dbo.Category with (nolock) WHERE categoryID = @categoryID  
            ELSE IF @sectionID is not null  
                SELECT @pagesize = PageSize FROM dbo.Section with (nolock) WHERE sectionID = @sectionID  
            ELSE IF @manufacturerID is not null  
                SELECT @pagesize = PageSize FROM dbo.Manufacturer with (nolock) WHERE manufacturerID = @manufacturerID  
            ELSE IF @distributorID is not null  
                SELECT @pagesize = PageSize FROM dbo.Distributor with (nolock) WHERE distributorID = @distributorID  
            ELSE IF @genreID is not null  
                SELECT @pagesize = PageSize FROM dbo.Genre with (nolock) WHERE genreID = @genreID  
            ELSE IF @vectorID is not null  
                SELECT @pagesize = PageSize FROM dbo.Vector with (nolock) WHERE vectorID = @vectorID  
            ELSE   
                SELECT @pagesize = convert(int, ConfigValue) FROM dbo.AppConfig with (nolock) WHERE [Name] = '
    Default_CategoryPageSize'  
        END  
      
        IF @pagesize is null or @pagesize = 0  
            SET @pagesize = 20  
      
        -- get sort order  
        IF @sortEntity = 1 or @sortEntityName = '
    category' BEGIN  
            INSERT #displayorder select distinct null as [name], a.productid, displayorder from dbo.ProductCategory a with (nolock) inner join (select distinct a.ProductID from ProductCategory a with (nolock) 
            left join ProductStore b with (nolock) on a.ProductID = b.ProductID where (@filterProduct = 0 or StoreID = @storeID)) b  on a.ProductID = b.ProductID where categoryID = @categoryID 
        END  
        ELSE IF @sortEntity = 2 or @sortEntityName = '
    section' BEGIN  
            INSERT #displayorder select distinct null as [name], a.productid, displayorder from dbo.ProductSection a with (nolock) inner join (select distinct a.ProductID from ProductSection a with (nolock) 
            left join ProductStore b with (nolock) on a.ProductID = b.ProductID where (@filterProduct = 0 or StoreID = @storeID)) b on a.ProductID = B.ProductID where sectionId = @sectionID
        END  
        ELSE IF @sortEntity = 3 or @sortEntityName = '
    manufacturer' BEGIN  
            INSERT #displayorder select distinct null as [name], a.productid, displayorder from dbo.ProductManufacturer a with (nolock) inner join (select distinct a.ProductID from ProductManufacturer a with (nolock) 
            left join ProductStore b with (nolock) on a.ProductID = b.ProductID where (@filterProduct = 0 or StoreID = @storeID)) b on a.ProductID = B.ProductID where ManufacturerID = @manufacturerID
        END  
        ELSE IF @sortEntity = 4 or @sortEntityName = '
    distributor' BEGIN  
            INSERT #displayorder select distinct null as [name], a.productid, displayorder from dbo.ProductDistributor a with (nolock) inner join (select distinct a.ProductID from ProductDistributor a with (nolock) 
            left join ProductStore b with (nolock) on a.ProductID = b.ProductID where (@filterProduct = 0 or StoreID = @storeID)) b on a.ProductID = B.ProductID where DistributorID = @distributorID
        END  
        ELSE IF @sortEntity = 5 or @sortEntityName = '
    genre' BEGIN  
            INSERT #displayorder select distinct null as [name], a.productid, displayorder from dbo.ProductGenre a with (nolock) inner join (select distinct a.ProductID from ProductGenre a with (nolock) 
            left join ProductStore b with (nolock) on a.ProductID = b.ProductID where (@filterProduct = 0 or StoreID = @storeID)) b on a.ProductID = B.ProductID where GenreID = @genreID
        END  
        ELSE IF @sortEntity = 6 or @sortEntityName = '
    vector' BEGIN  
            INSERT #displayorder select distinct null as [name], a.productid, displayorder from dbo.ProductVector a with (nolock) inner join (select distinct a.ProductID from ProductVector a with (nolock) 
            left join ProductStore b with (nolock) on a.ProductID = b.ProductID where (@filterProduct = 0 or StoreID = @storeID)) b on a.ProductID = B.ProductID where VectorID = @vectorID
        END  
        ELSE BEGIN  
            INSERT #displayorder select distinct [name], a.productid, 1 from dbo.Product a with (nolock) inner join (select distinct a.ProductID from Product a with (nolock) 
            left join ProductStore b with (nolock) on a.ProductID = b.ProductID where (@filterProduct = 0 or StoreID = @storeID)) b on a.ProductID = B.ProductID ORDER BY Name  
        END



        --SET @searchstr = '
    %' + rtrim(ltrim(@searchstr)) + '%'
    declare @ftscount int
    CREATE TABLE #fts ([key] int not null, [rank] int not null)
        IF @InventoryFilter <> -1 BEGIN

            IF @ViewType = 1 BEGIN
                INSERT #inventoryfilter
                SELECT p.productid, pv.VariantID, sum(case p.TrackInventoryBySizeAndColor when 1 then isnull(i.quan, 0) else pv.inventory end ) invqty
                FROM product p with (NOLOCK) join #displayorder d on p.ProductID = d.ProductID
                    join ProductVariant pv with (NOLOCK) on p.ProductID = pv.ProductID  and pv.IsDefault = 1
                    left join Inventory i with (NOLOCK) on pv.VariantID = i.VariantID
                GROUP BY p.productid, pv.VariantID
                HAVING sum(case p.TrackInventoryBySizeAndColor when 1 then isnull(i.quan, 0) else pv.inventory end ) >= @InventoryFilter
            END
            ELSE
                INSERT #inventoryfilter
                SELECT p.productid, pv.VariantID, sum(case p.TrackInventoryBySizeAndColor when 1 then isnull(i.quan, 0) else pv.inventory end ) invqty
                FROM product p with (NOLOCK) join #displayorder d on p.ProductID = d.ProductID
                    join ProductVariant pv with (NOLOCK) on p.ProductID = pv.ProductID
                    left join Inventory i with (NOLOCK) on pv.VariantID = i.VariantID
                GROUP BY p.productid, pv.VariantID
                HAVING sum(case p.TrackInventoryBySizeAndColor when 1 then isnull(i.quan, 0) else pv.inventory end ) >= @InventoryFilter
                    IF @searchstr is not null BEGIN                
                    
                    INSERT #fts SELECT [key],[rank] from CONTAINSTABLE (product,*,@searchstr)
                    SELECT @ftscount = (SELECT count(*) from #fts)
                        IF @ftscount  <> 0 BEGIN
                            INSERT @productfilter (productid, VariantID, VariantDisplayOrder, ProductName, VariantName, [rank])
                            SELECT distinct p.productid, pv.VariantID, pv.DisplayOrder, p.Name, pv.Name, ft.rank
                            FROM 
                                product p with (nolock)
                                inner join #fts as ft on p.ProductID=ft.[key]
                                left join ProductVariant pv        with (NOLOCK) ON p.ProductID = pv.ProductID and pv.IsDefault >= @ViewType
                                left join productcategory pc       with (nolock) on p.ProductID = pc.ProductID                             
                                left join ProductCustomerLevel pcl with (nolock) on p.ProductID = pcl.ProductID                             
                                join #inventoryfilter i on pv.VariantID = i.VariantID            
                            WHERE 
                                  (pc.categoryid = @categoryID or @categoryID is null or @categorycount = 0)                                                                          
                              and p.ProductTypeID = coalesce(@ProductTypeID, p.ProductTypeID)
                              and (case 
                                    when @FilterProductsByCustomerLevel = 0 or @custlevelcount = 0 or pcl.CustomerLevelID is null or @CustomerLevelID is null then 1
                                    when @CustomerLevelFilteringIsAscending = 1 and pcl.CustomerLevelID <= @CustomerLevelID then 1 
                                    when pcl.CustomerLevelID = @CustomerLevelID or pcl.CustomerLevelID is null then 1 
                                    else 0
                                   end  = 1
                                  )
                              and case when isnull(pv.saleprice,0) = 0 then 0 else 1 end >= @OnSaleOnly
                              and p.published >= @publishedonly
                              and pv.published >= @publishedonly
                              and isnull(p.IsAPack, 0) <= 1-@ExcludePacks
                              and isnull(p.IsAKit, 0) <= 1-@ExcludeKits
                              and p.IsSystem <= 1-@ExcludeSysProds
                              and p.Deleted = 0
                              and pv.Deleted = 0                          
                              or (
                                     @searchstr2 is null
                                  or patindex(@searchstr2, isnull(convert(nvarchar(20),p.productid), '')) > 0              
                                  )
                            order by ft.rank desc
                        END
                        ELSE BEGIN
                            INSERT @productfilter (productid, VariantID, VariantDisplayOrder, ProductName, VariantName)
                            SELECT distinct p.productid, pv.VariantID, pv.DisplayOrder, p.Name, pv.Name
                            FROM 
                                product p with (nolock)                            
                                left join ProductVariant pv        with (NOLOCK) ON p.ProductID = pv.ProductID and pv.IsDefault >= @ViewType
                                left join productcategory pc       with (nolock) on p.ProductID = pc.ProductID                             
                                left join ProductCustomerLevel pcl with (nolock) on p.ProductID = pcl.ProductID                             
                                join #inventoryfilter i on pv.VariantID = i.VariantID            
                            WHERE 
                                  (pc.categoryid = @categoryID or @categoryID is null or @categorycount = 0)                          
                              and p.ProductTypeID = coalesce(@ProductTypeID, p.ProductTypeID)
                              and (case 
                                    when @FilterProductsByCustomerLevel = 0 or @custlevelcount = 0 or pcl.CustomerLevelID is null or @CustomerLevelID is null then 1
                                    when @CustomerLevelFilteringIsAscending = 1 and pcl.CustomerLevelID <= @CustomerLevelID then 1 
                                    when pcl.CustomerLevelID = @CustomerLevelID or pcl.CustomerLevelID is null then 1 
                                    else 0
                                   end  = 1
                                  )                          
                              and (
                                 @searchstr2 is null
                              or patindex('
    %'+@searchstr2+'%', isnull(p.name, '')) > 0
                              or patindex(@searchstr2, isnull(convert(nvarchar(20),p.productid), '')) > 0 
                              or patindex('
    %'+@searchstr2+'%', isnull(pv.name, '')) > 0
                              or patindex('
    %'+@searchstr2+'%', isnull(p.sku , '')+isnull(pv.skusuffix, '')) > 0
                              or patindex('
    %'+@searchstr2+'%', isnull(p.manufacturerpartnumber, '')) > 0
                              or patindex('
    %'+@searchstr2+'%', isnull(pv.manufacturerpartnumber, '')) > 0                      
                              )   
                              and case when isnull(pv.saleprice,0) = 0 then 0 else 1 end >= @OnSaleOnly
                              and p.published >= @publishedonly
                              and pv.published >= @publishedonly
                              and isnull(p.IsAPack, 0) <= 1-@ExcludePacks
                              and isnull(p.IsAKit, 0) <= 1-@ExcludeKits
                              and p.IsSystem <= 1-@ExcludeSysProds
                              and p.Deleted = 0
                              and pv.Deleted = 0                          
                        END
                    END
                    ELSE BEGIN
                        INSERT @productfilter (productid, displayorder, VariantID, VariantDisplayOrder, ProductName, VariantName)
                        SELECT distinct p.productid, do.displayorder, pv.VariantID, pv.DisplayOrder, p.Name, pv.Name
                        FROM 
                            product p with (nolock)
                            join #displayorder do on p.ProductID = do.ProductID 
                            left join ProductVariant pv        with (NOLOCK) ON p.ProductID = pv.ProductID and pv.IsDefault >= @ViewType
                            left join productcategory pc       with (nolock) on p.ProductID = pc.ProductID                         
                            left join ProductCustomerLevel pcl with (nolock) on p.ProductID = pcl.ProductID                         
                            join #inventoryfilter i on pv.VariantID = i.VariantID
                        WHERE 
                              (pc.categoryid = @categoryID or @categoryID is null or @categorycount = 0)                      
                          and p.ProductTypeID = coalesce(@ProductTypeID, p.ProductTypeID)
                          and (case 
                                when @FilterProductsByCustomerLevel = 0 or @custlevelcount = 0 or pcl.CustomerLevelID is null or @CustomerLevelID is null then 1
                                when @CustomerLevelFilteringIsAscending = 1 and pcl.CustomerLevelID <= @CustomerLevelID then 1 
                                when pcl.CustomerLevelID = @CustomerLevelID or pcl.CustomerLevelID is null then 1 
                                else 0
                               end  = 1
                              )
                          and (
                                 @searchstr2 is null
                              or patindex('
    %'+@searchstr2+'%', isnull(p.name, '')) > 0
                              or patindex(@searchstr2, isnull(convert(nvarchar(20),p.productid), '')) > 0 
                              or patindex('
    %'+@searchstr2+'%', isnull(pv.name, '')) > 0
                              or patindex('
    %'+@searchstr2+'%', isnull(p.sku , '')+isnull(pv.skusuffix, '')) > 0
                              or patindex('
    %'+@searchstr2+'%', isnull(p.manufacturerpartnumber, '')) > 0
                              or patindex('
    %'+@searchstr2+'%', isnull(pv.manufacturerpartnumber, '')) > 0
                              or (patindex('
    %'+@searchstr2+'%', isnull(p.Description, '')) > 0 and @extSearch = 1)
                              or (patindex('
    %'+@searchstr2+'%', isnull(p.Summary, '')) > 0 and @extSearch = 1)
                              )
                          and case when isnull(pv.saleprice,0) = 0 then 0 else 1 end >= @OnSaleOnly
                          and p.published >= @publishedonly
                          and pv.published >= @publishedonly
                          and isnull(p.IsAPack, 0) <= 1-@ExcludePacks
                          and isnull(p.IsAKit, 0) <= 1-@ExcludeKits
                          and p.IsSystem <= 1-@ExcludeSysProds
                          and p.Deleted = 0
                          and pv.Deleted = 0
                          
                        order by do.displayorder, p.Name, pv.DisplayOrder, pv.Name
                    END
        END 
        ELSE BEGIN
                IF @searchstr is not null BEGIN                 
                    
                    INSERT #fts SELECT [key],[rank] from CONTAINSTABLE (product,*,@searchstr)
                    SELECT @ftscount = (SELECT count(*) from #fts)
                    IF @ftscount  <> 0 BEGIN
                        INSERT @productfilter (productid, VariantID, VariantDisplayOrder, ProductName, VariantName, [rank])
                        SELECT distinct p.productid, pv.VariantID, pv.DisplayOrder, p.Name, pv.Name, ft.rank
                        FROM 
                            product p with (nolock)
                            inner join #fts as ft on p.ProductID=ft.[key]                        
                            join ProductVariant pv             with (NOLOCK) on p.ProductID = pv.ProductID and pv.IsDefault >= @ViewType
                            left join productcategory pc       with (nolock) on p.ProductID = pc.ProductID 
                            left join ProductCustomerLevel pcl with (nolock) on p.ProductID = pcl.ProductID                         
                        WHERE 
                              (pc.categoryid = @categoryID or @categoryID is null or @categorycount = 0)                      
                          and p.ProductTypeID = coalesce(@ProductTypeID, p.ProductTypeID)
                          and (case 
                                when @FilterProductsByCustomerLevel = 0 or @custlevelcount = 0 or pcl.CustomerLevelID is null or @CustomerLevelID is null then 1
                                when @CustomerLevelFilteringIsAscending = 1 and pcl.CustomerLevelID <= @CustomerLevelID then 1 
                                when pcl.CustomerLevelID = @CustomerLevelID or pcl.CustomerLevelID is null then 1 
                                else 0
                               end  = 1
                              )                              
                          and case when isnull(pv.saleprice,0) = 0 then 0 else 1 end >= @OnSaleOnly
                          and p.published >= @publishedonly
                          and pv.published >= @publishedonly
                          and isnull(p.IsAPack, 0) <= 1-@ExcludePacks
                          and isnull(p.IsAKit, 0) <= 1-@ExcludeKits
                          and p.IsSystem <= 1-@ExcludeSysProds
                          and p.Deleted = 0
                          and pv.Deleted = 0                      
                          or patindex(@searchstr2, isnull(convert(nvarchar(20),p.productid), '')) > 0 
                        order by ft.rank desc
                    END
                    ELSE BEGIN
                        INSERT @productfilter (productid, VariantID, VariantDisplayOrder, ProductName, VariantName)
                        SELECT distinct p.productid, pv.VariantID, pv.DisplayOrder, p.Name, pv.Name
                        FROM 
                            product p with (nolock)
                            
                            
                            join ProductVariant pv             with (NOLOCK) on p.ProductID = pv.ProductID and pv.IsDefault >= @ViewType
                            left join productcategory pc       with (nolock) on p.ProductID = pc.ProductID                         
                            left join ProductCustomerLevel pcl with (nolock) on p.ProductID = pcl.ProductID 
                            
                        WHERE 
                              (pc.categoryid = @categoryID or @categoryID is null or @categorycount = 0)                      
                          and p.ProductTypeID = coalesce(@ProductTypeID, p.ProductTypeID)
                          and (case 
                                when @FilterProductsByCustomerLevel = 0 or @custlevelcount = 0 or pcl.CustomerLevelID is null or @CustomerLevelID is null then 1
                                when @CustomerLevelFilteringIsAscending = 1 and pcl.CustomerLevelID <= @CustomerLevelID then 1 
                                when pcl.CustomerLevelID = @CustomerLevelID or pcl.CustomerLevelID is null then 1 
                                else 0
                               end  = 1
                              )                      
                          and (
                             @searchstr2 is null
                          or patindex('
    %'+@searchstr2+'%', isnull(p.name, '')) > 0
                          or patindex(@searchstr2, isnull(convert(nvarchar(20),p.productid), '')) > 0 
                          or patindex('
    %'+@searchstr2+'%', isnull(pv.name, '')) > 0
                          or patindex('
    %'+@searchstr2+'%', isnull(p.sku , '')+isnull(pv.skusuffix , '')) > 0
                          or patindex('
    %'+@searchstr2+'%', isnull(p.manufacturerpartnumber, '')) > 0
                          or patindex('
    %'+@searchstr2+'%', isnull(pv.manufacturerpartnumber, '')) > 0
                          or (patindex('
    %'+@searchstr2+'%', isnull(p.Description, '')) > 0 and @extSearch = 1)
                          or (patindex('
    %'+@searchstr2+'%', isnull(p.Summary, '')) > 0 and @extSearch = 1)
                          )                                  
                          and case when isnull(pv.saleprice,0) = 0 then 0 else 1 end >= @OnSaleOnly
                          and p.published >= @publishedonly
                          and pv.published >= @publishedonly
                          and isnull(p.IsAPack, 0) <= 1-@ExcludePacks
                          and isnull(p.IsAKit, 0) <= 1-@ExcludeKits
                          and p.IsSystem <= 1-@ExcludeSysProds
                          and p.Deleted = 0
                          and pv.Deleted = 0                    
                    END
                END
                ELSE BEGIN
                INSERT @productfilter (productid, displayorder, VariantID, VariantDisplayOrder, ProductName, VariantName)
                    SELECT distinct p.productid, do.displayorder, pv.VariantID, pv.DisplayOrder, p.Name, pv.Name
                    FROM 
                        product p with (nolock)
                        join #displayorder do on p.ProductID = do.ProductID 
                        join ProductVariant pv             with (NOLOCK) on p.ProductID = pv.ProductID and pv.IsDefault >= @ViewType
                        left join productcategory pc       with (nolock) on p.ProductID = pc.ProductID                     
                        left join ProductCustomerLevel pcl with (nolock) on p.ProductID = pcl.ProductID 
                    WHERE 
                          (pc.categoryid = @categoryID or @categoryID is null or @categorycount = 0)                  
                      and p.ProductTypeID = coalesce(@ProductTypeID, p.ProductTypeID)
                      and (case 
                            when @FilterProductsByCustomerLevel = 0 or @custlevelcount = 0 or pcl.CustomerLevelID is null or @CustomerLevelID is null then 1
                            when @CustomerLevelFilteringIsAscending = 1 and pcl.CustomerLevelID <= @CustomerLevelID then 1 
                            when pcl.CustomerLevelID = @CustomerLevelID or pcl.CustomerLevelID is null then 1 
                            else 0
                           end  = 1
                          )
                      and (
                             @searchstr2 is null
                          or patindex('
    %'+@searchstr2+'%', isnull(p.name, '')) > 0
                          or patindex(@searchstr2, isnull(convert(nvarchar(20),p.productid), '')) > 0 
                          or patindex('
    %'+@searchstr2+'%', isnull(pv.name, '')) > 0
                          or patindex('
    %'+@searchstr2+'%', isnull(p.sku , '')+isnull(pv.skusuffix , '')) > 0
                          or patindex('
    %'+@searchstr2+'%', isnull(p.manufacturerpartnumber, '')) > 0
                          or patindex('
    %'+@searchstr2+'%', isnull(pv.manufacturerpartnumber, '')) > 0
                          or (patindex('
    %'+@searchstr2+'%', isnull(p.Description, '')) > 0 and @extSearch = 1)
                          or (patindex('
    %'+@searchstr2+'%', isnull(p.Summary, '')) > 0 and @extSearch = 1)
                          )
                      and case when isnull(pv.saleprice,0) = 0 then 0 else 1 end >= @OnSaleOnly
                      and p.published >= @publishedonly
                      and pv.published >= @publishedonly
                      and isnull(p.IsAPack, 0) <= 1-@ExcludePacks
                      and isnull(p.IsAKit, 0) <= 1-@ExcludeKits
                      and p.IsSystem <= 1-@ExcludeSysProds
                      and p.Deleted = 0
                      and pv.Deleted = 0                  
                    order by do.displayorder, p.Name, pv.DisplayOrder, pv.Name
                END            
        END

        SET @rcount = @@rowcount
        IF @StatsFirst = 1
            SELECT cast(ceiling(@rcount*1.0/@pagesize) as int) pages, @rcount ProductCount
    IF @searchstr is not null BEGIN
        SELECT pf.rank,
            p.ProductID,
            p.Name,
            pv.VariantID,
            pv.Name AS VariantName,
            p.ProductGUID,
            p.Summary,
            p.Description,
            p.SEKeywords,
            p.SEDescription,
            p.SpecTitle,
            p.MiscText,
            p.SwatchImageMap,
            p.IsFeaturedTeaser,
            p.FroogleDescription,
            p.SETitle,
            p.SENoScript,
            p.SEAltText,
            p.SizeOptionPrompt,
            p.ColorOptionPrompt,
            p.TextOptionPrompt,
            p.ProductTypeID,
            p.TaxClassID,
            p.SKU,
            p.ManufacturerPartNumber,
            p.SalesPromptID,
            p.SpecCall,
            p.SpecsInline,
            p.IsFeatured,
            p.XmlPackage,
            p.ColWidth,
            p.Published,
            p.RequiresRegistration,
            p.Looks,
            p.Notes,
            p.QuantityDiscountID,
            p.RelatedProducts,
            p.UpsellProducts,
            p.UpsellProductDiscountPercentage,
            p.RelatedDocuments,
            p.TrackInventoryBySizeAndColor,
            p.TrackInventoryBySize,
            p.TrackInventoryByColor,
            p.IsAKit,
            p.ShowInProductBrowser,
            p.IsAPack,
            p.PackSize,
            p.ShowBuyButton,
            p.RequiresProducts,
            p.HidePriceUntilCart,
            p.IsCalltoOrder,
            p.ExcludeFromPriceFeeds,
            p.RequiresTextOption,
            p.TextOptionMaxLength,
            p.SEName,
            p.Deleted,
            p.CreatedOn,
            p.ImageFileNameOverride,
            pv.VariantGUID,
            pv.Description AS VariantDescription,
            pv.SEKeywords AS VariantSEKeywords,
            pv.SEDescription AS VariantSEDescription,
            pv.Colors,
            pv.ColorSKUModifiers,
            pv.Sizes,
            pv.SizeSKUModifiers,
            pv.FroogleDescription AS VariantFroogleDescription,
            pv.SKUSuffix,
            pv.ManufacturerPartNumber AS VariantManufacturerPartNumber,
            pv.Price,
            pv.CustomerEntersPrice, 
            pv.CustomerEntersPricePrompt,
            isnull(pv.SalePrice, 0) SalePrice,
            cast(isnull(pv.Weight,0) as decimal(10,1)) Weight,
            pv.MSRP,
            pv.Cost,
            isnull(pv.Points,0) Points,
            pv.Dimensions,
            case p.TrackInventoryBySizeAndColor when 1 then isnull(i.quan, 0) else pv.inventory end Inventory,
            pv.DisplayOrder as VariantDisplayOrder,
            pv.Notes AS VariantNotes,
            pv.IsTaxable,
            pv.IsShipSeparately,
            pv.IsDownload,
            pv.DownloadLocation,
            pv.Published AS VariantPublished,
            pv.IsSecureAttachment,
            pv.IsRecurring,
            pv.RecurringInterval,
            pv.RecurringIntervalType,
            pv.SubscriptionInterval,
            pv.SEName AS VariantSEName,
            pv.RestrictedQuantities,
            pv.MinimumQuantity,
            pv.Deleted AS VariantDeleted,
            pv.CreatedOn AS VariantCreatedOn,
            d.Name AS DistributorName,
            d.DistributorID,
            d.SEName AS DistributorSEName,
            m.ManufacturerID,
            m.Name AS ManufacturerName,
            m.SEName AS ManufacturerSEName,
            s.Name AS SalesPromptName,
            case when pcl.productid is null then 0 else isnull(ep.Price, 0) end ExtendedPrice,
        p.ExtensionData,
        p.ExtensionData2,
        p.ExtensionData3,
        p.ExtensionData4,
        p.ExtensionData5
        FROM dbo.Product p with (NOLOCK) 
            left join dbo.ProductVariant       pv  with (NOLOCK) on p.ProductID = pv.ProductID and pv.IsDefault >= @ViewType
            join @productfilter                pf                on pv.ProductID = pf.ProductID and pv.VariantID = pf.VariantID 
            left join dbo.SalesPrompt           s  with (NOLOCK) on p.SalesPromptID = s.SalesPromptID 
            left join dbo.ProductManufacturer  pm  with (NOLOCK) on p.ProductID = pm.ProductID 
            left join dbo.Manufacturer          m  with (NOLOCK) on pm.ManufacturerID = m.ManufacturerID 
            left join dbo.ProductDistributor   pd  with (NOLOCK) on p.ProductID = pd.ProductID
            left join dbo.Distributor           d  with (NOLOCK) on pd.DistributorID = d.DistributorID
            left join dbo.ExtendedPrice        ep  with (NOLOCK) on ep.VariantID = pv.VariantID and ep.CustomerLevelID = @CustomerLevelID
            left join dbo.ProductCustomerLevel pcl with (NOLOCK) on p.ProductID = pcl.ProductID and pcl.CustomerLevelID = @CustomerLevelID
            left join (select VariantID, sum(quan) quan from dbo.Inventory with (nolock) group by VariantID) i  on pv.VariantID = i.VariantID
        WHERE pf.rownum >= @pagesize*(@pagenum-1)+1 and pf.rownum <= @pagesize*(@pagenum)
        ORDER BY pf.rank desc
    END
    ELSE BEGIN
        SELECT 
            p.ProductID,
            p.Name,
            pv.VariantID,
            pv.Name AS VariantName,
            p.ProductGUID,
            p.Summary,
            p.Description,
            p.SEKeywords,
            p.SEDescription,
            p.SpecTitle,
            p.MiscText,
            p.SwatchImageMap,
            p.IsFeaturedTeaser,
            p.FroogleDescription,
            p.SETitle,
            p.SENoScript,
            p.SEAltText,
            p.SizeOptionPrompt,
            p.ColorOptionPrompt,
            p.TextOptionPrompt,
            p.ProductTypeID,
            p.TaxClassID,
            p.SKU,
            p.ManufacturerPartNumber,
            p.SalesPromptID,
            p.SpecCall,
            p.SpecsInline,
            p.IsFeatured,
            p.XmlPackage,
            p.ColWidth,
            p.Published,
            p.RequiresRegistration,
            p.Looks,
            p.Notes,
            p.QuantityDiscountID,
            p.RelatedProducts,
            p.UpsellProducts,
            p.UpsellProductDiscountPercentage,
            p.RelatedDocuments,
            p.TrackInventoryBySizeAndColor,
            p.TrackInventoryBySize,
            p.TrackInventoryByColor,
            p.IsAKit,
            p.ShowInProductBrowser,
            p.IsAPack,
            p.PackSize,
            p.ShowBuyButton,
            p.RequiresProducts,
            p.HidePriceUntilCart,
            p.IsCalltoOrder,
            p.ExcludeFromPriceFeeds,
            p.RequiresTextOption,
            p.TextOptionMaxLength,
            p.SEName,
            p.Deleted,
            p.CreatedOn,
            p.ImageFileNameOverride,
            pv.VariantGUID,
            pv.Description AS VariantDescription,
            pv.SEKeywords AS VariantSEKeywords,
            pv.SEDescription AS VariantSEDescription,
            pv.Colors,
            pv.ColorSKUModifiers,
            pv.Sizes,
            pv.SizeSKUModifiers,
            pv.FroogleDescription AS VariantFroogleDescription,
            pv.SKUSuffix,
            pv.ManufacturerPartNumber AS VariantManufacturerPartNumber,
            pv.Price,
            pv.CustomerEntersPrice, 
            pv.CustomerEntersPricePrompt,
            isnull(pv.SalePrice, 0) SalePrice,
            cast(isnull(pv.Weight,0) as decimal(10,1)) Weight,
            pv.MSRP,
            pv.Cost,
            isnull(pv.Points,0) Points,
            pv.Dimensions,
            case p.TrackInventoryBySizeAndColor when 1 then isnull(i.quan, 0) else pv.inventory end Inventory,
            pv.DisplayOrder as VariantDisplayOrder,
            pv.Notes AS VariantNotes,
            pv.IsTaxable,
            pv.IsShipSeparately,
            pv.IsDownload,
            pv.DownloadLocation,
            pv.Published AS VariantPublished,
            pv.IsSecureAttachment,
            pv.IsRecurring,
            pv.RecurringInterval,
            pv.RecurringIntervalType,
            pv.SubscriptionInterval,
            pv.SEName AS VariantSEName,
            pv.RestrictedQuantities,
            pv.MinimumQuantity,
            pv.Deleted AS VariantDeleted,
            pv.CreatedOn AS VariantCreatedOn,
            d.Name AS DistributorName,
            d.DistributorID,
            d.SEName AS DistributorSEName,
            m.ManufacturerID,
            m.Name AS ManufacturerName,
            m.SEName AS ManufacturerSEName,
            s.Name AS SalesPromptName,
            case when pcl.productid is null then 0 else isnull(ep.Price, 0) end ExtendedPrice,
            p.ExtensionData,
            p.ExtensionData2,
            p.ExtensionData3,
            p.ExtensionData4,
            p.ExtensionData5
        FROM Product p with (NOLOCK) 
            left join ProductVariant       pv  with (NOLOCK) on p.ProductID = pv.ProductID and pv.IsDefault >= @ViewType
            join @productfilter            pf                on pv.ProductID = pf.ProductID and pv.VariantID = pf.VariantID 
            left join SalesPrompt           s  with (NOLOCK) on p.SalesPromptID = s.SalesPromptID 
            left join ProductManufacturer  pm  with (NOLOCK) on p.ProductID = pm.ProductID 
            left join Manufacturer          m  with (NOLOCK) on pm.ManufacturerID = m.ManufacturerID 
            left join ProductDistributor   pd  with (NOLOCK) on p.ProductID = pd.ProductID
            left join Distributor           d  with (NOLOCK) on pd.DistributorID = d.DistributorID
            left join ExtendedPrice        ep  with (NOLOCK) on ep.VariantID = pv.VariantID and ep.CustomerLevelID = @CustomerLevelID
            left join ProductCustomerLevel pcl with (NOLOCK) on p.ProductID = pcl.ProductID and pcl.CustomerLevelID = @CustomerLevelID
            left join (select VariantID, sum(quan) quan from Inventory with (nolock) group by VariantID) i  on pv.VariantID = i.VariantID
        WHERE pf.rownum >= @pagesize*(@pagenum-1)+1 and pf.rownum <= @pagesize*(@pagenum)
        ORDER BY pf.rownum
    END
        IF @StatsFirst <> 1
            SELECT cast(ceiling(@rcount*1.0/@pagesize) as int) pages, @rcount ProductCount
        
    END 
    As you may notice there is a there is SQL variable called searchstr2. It is used so I can use both full text search and the regular search. Some times the regular search is better to use when it comes to part numbers for me. This is because many of our part numbers have a "-" in them. Since "-" is considered white text it doesn't return the result I want for that search. For this reason the code behind and search xml package are also edited. The xmlpackage is simply adding SearchTerm2 to the sql statment and runtime. The code behind is a little be more complex. Due also note that my search page uses a aspdnsf:XmlPackage control but is should be easy to port over the code to the litSearch if that is used for output instead. Here is that code in C#:

    C#/VB.NET Code:
    StringBuilder sb = new StringBuilder();
                
    sb.Append(CommonLogic.QueryStringCanBeDangerousContent("SearchTerm"));
                
    Regex excl = new Regex(@"\s\-(\w+)(?: |$)"RegexOptions.IgnorePatternWhitespace);
                
    //Label1.Text = "";
                
    StringBuilder filter = new StringBuilder();
                foreach (
    Match m in excl.Matches(sb.ToString()))
                {
                    
    sb.Replace(" -" m.Groups[1].Value"");
                    
    filter.Append(" and not \"" m.Groups[1].Value "\"");
                }
                
    sb sb.Replace("\"""");
                if (
    sb.Length 0)
                {
                    
    Package1.RuntimeParams "SearchTerm=\"" sb.ToString() + "\"&SearchTerm2=FORMSOF(Thesaurus,\"" sb.ToString() + "\") " filter.ToString();
                    
    //Label1.Text = "SearchTerm=" + sb.ToString() + "&SearchTerm2=FORMSOF(Thesaurus,\"" + sb.ToString() + "\") " + filter.ToString();
                
    }
                else
                {
                    
    Package1.RuntimeParams "SearchTerm=\"" sb.ToString() + "\"";
                    
    //Label1.Text = "SearchTerm=" + sb.ToString() + "&SearchTerm2=FORMSOF(Thesaurus,\"" + sb.ToString() + "\") " + filter.ToString();
                

    Hope this helps.

  13. #13
    akeller is offline Member
    Join Date
    Dec 2008
    Posts
    78

    Default

    How are you getting around the "Operand type clash: uniqueidentifier is incompatible with int" error? Do I have to set something to make the [key] be an int instead of a uniqueidentifier? Did you change your ProductId's to a uniqueindentifier datatype?

    I only ask because on both your examples you compare uniqueidentifiers to ints.

  14. #14
    harsha.gus is offline Senior Member
    Join Date
    Mar 2009
    Posts
    301

    Exclamation question about Full Text Search

    How does Full Text Search Works

    i have a product Title 20" x 20" x 20"

    when i search for 20" x 20" x 20"

    it gives result which is fine.

    But When i Search for 20"x20"x20"
    No results will come up for this.

    is this how Full Text Search Works, or do i have to do anything to fix it.

    thanks
    rbgx
    AspDotNetStorefront ML
    v8.0.1.4

  15. #15
    mmcgeachy is offline Senior Member
    Join Date
    Sep 2008
    Posts
    174

    Default

    Quote Originally Posted by akeller View Post
    How are you getting around the "Operand type clash: uniqueidentifier is incompatible with int" error? Do I have to set something to make the [key] be an int instead of a uniqueidentifier? Did you change your ProductId's to a uniqueindentifier datatype?

    I only ask because on both your examples you compare uniqueidentifiers to ints.
    This mostly due to the fact that my full text search index uses ProductID (int) for the index. The code out of the box uses ProductGUID (uniqueidentifier) for the index. I had integrated full text search before it was offered out of the box. When it was offered out of the box I didn't see a reason to change it and rebuild the index. Due to the fact that it doesn't change how full text search would return results. It changes how SQL statements that use tables commands sure but past that it should be very similar. You can change what column is used for the index if you wish. Just make sure to rebuild the index after doing so.

    Quote Originally Posted by harsha.gus View Post
    How does Full Text Search Works

    i have a product Title 20" x 20" x 20"

    when i search for 20" x 20" x 20"

    it gives result which is fine.

    But When i Search for 20"x20"x20"
    No results will come up for this.

    is this how Full Text Search Works, or do i have to do anything to fix it.

    thanks
    As to how a search works it depends on what kind of full text search you are using. I would recommend reading http://www.developer.com/db/article.php/3446891 as linked in the manual to get a better understanding of Full text search.

    To make 20"x20"x20" return a result I would do a replace like this in code behind (C#)
    C#/VB.NET Code:
    searchTermFromQueryString searchTermFromQueryString.Replace("\"x""\" x "); 

  16. #16
    harsha.gus is offline Senior Member
    Join Date
    Mar 2009
    Posts
    301

    Exclamation This is my Get Products procedure

    Quote Originally Posted by mmcgeachy View Post
    Ok just be warned anyone that uses this alter proc script may not have the script work right at the start... It more than likely will work with small tweaks will be done. I do not grantee 100% that things will work right from the start however. This is due customizations I have done, different versions, ect.

    The stored procedure depends on a few code changes being done to the search page code behind and the search xmlpackage. This is due to feature to help filter out more certain words also But I will talk about those later here is the alter statement:

    C#/VB.NET Code:
    ALTER proc [dbo].[aspdnsf_GetProducts]
        @
    categoryID      int null,
        @
    sectionID       int null,
        @
    manufacturerID  int null,
        @
    distributorID   int null,
        @
    genreID         int null,
        @
    vectorID        int null,
        @
    localeID        int null,
        @
    CustomerLevelID int null,
        @
    affiliateID     int null,
        @
    ProductTypeID   int null,
        @
    ViewType        bit 1, -- all variantsone variant
        
    @sortEntity      int 0, -- categorysectionmanufacturerdistributor5genrevector
        
    @pagenum         int 1,
        @
    pagesize        int null,
        @
    StatsFirst      tinyint 1,
        @
    searchstr       nvarchar(4000) = null,
        @
    searchstr2       nvarchar(4000) = null,
        @
    extSearch       tinyint 0,
        @
    publishedonly   tinyint 0,
        @
    ExcludePacks    tinyint 0,
        @
    ExcludeKits     tinyint 0,
        @
    ExcludeSysProds tinyint 0,
        @
    InventoryFilter int 0,  --  will only show products with an inventory level GREATER OR EQUAL TO than the number specified in this parameterset to -1 to disable inventory filtering
        
    @sortEntityName  varchar(20) = '', -- usely only when the entity id is providedallowed valuescategorysectionmanufacturerdistributorgenrevector
        
    @localeName      varchar(20) = '',
        @
    OnSaleOnly      tinyint 0,
        @
    IncludeAll      bit 0, -- Don't filter products that have a start date in the future or a stop date in the past  
        @storeID         int = 1,
        @filterProduct     bit = 0
    AS
    BEGIN

        SET NOCOUNT ON 

        DECLARE @rcount int
        DECLARE @productfilter table (rownum int not null identity  primary key, productid int not null,displayorder int null, VariantID int not null, VariantDisplayOrder int not null, ProductName nvarchar(400) null, VariantName nvarchar(400) null, [rank] int null)
        DECLARE @FilterProductsByAffiliate tinyint, @FilterProductsByCustomerLevel tinyint, @HideProductsWithLessThanThisInventoryLevel int
        CREATE TABLE #displayorder ([name] nvarchar (800), productid int not null primary key, displayorder int not null)
        CREATE TABLE #inventoryfilter (productid int not null, variantid int not null, InvQty int not null)
        CREATE CLUSTERED INDEX tmp_inventoryfilter ON #inventoryfilter (productid, variantid)

        DECLARE @custlevelcount int, @sectioncount int, @localecount int, @affiliatecount int, @categorycount int, @CustomerLevelFilteringIsAscending bit, @distributorcount int, @genrecount int, @vectorcount int, @manufacturercount int

        SELECT @FilterProductsByAffiliate = case ConfigValue when '
    true' then 1 else 0 end FROM dbo.AppConfig with (nolock) WHERE [Name] = 'FilterProductsByAffiliate'
        SELECT @FilterProductsByCustomerLevel = case ConfigValue when '
    true' then 1 else 0 end FROM dbo.AppConfig with (nolock) WHERE [Name] = 'FilterProductsByCustomerLevel'
        SELECT @HideProductsWithLessThanThisInventoryLevel = convert(int, ConfigValue) FROM dbo.AppConfig with (nolock) WHERE [Name] = '
    HideProductsWithLessThanThisInventoryLevel' and isnumeric(ConfigValue) = 1

        IF @InventoryFilter <> -1 and (@HideProductsWithLessThanThisInventoryLevel > @InventoryFilter or @HideProductsWithLessThanThisInventoryLevel  = -1)
            SET @InventoryFilter  = @HideProductsWithLessThanThisInventoryLevel


        SET @categoryID      = nullif(@categoryID, 0)
        SET @sectionID       = nullif(@sectionID, 0)
        SET @manufacturerID  = nullif(@manufacturerID, 0)
        SET @distributorID   = nullif(@distributorID, 0)
        SET @genreID         = nullif(@genreID, 0)
        SET @vectorID        = nullif(@vectorID, 0)
        SET @affiliateID     = nullif(@affiliateID, 0)
        SET @ProductTypeID   = nullif(@ProductTypeID, 0)


        SET @CustomerLevelFilteringIsAscending  = 0
        SELECT @CustomerLevelFilteringIsAscending  = case configvalue when '
    true' then 1 else 0 end
        FROM dbo.AppConfig with (nolock) 
        WHERE name = '
    FilterByCustomerLevelIsAscending'

        IF @localeID is null and ltrim(rtrim(@localeName)) <> ''
            SELECT @localeID = LocaleSettingID FROM dbo.LocaleSetting with (nolock) WHERE Name = ltrim(rtrim(@localeName))

        select @categorycount     = si.rows from sysobjects so with (nolock) join sysindexes si with (nolock) on so.id = si.id where so.id = object_id('
    productcategory') and si.indid < 2 and type = 'u'
        select @sectioncount      = si.rows from sysobjects so with (nolock) join sysindexes si with (nolock) on so.id = si.id where so.id = object_id('
    productsection') and si.indid < 2 and type = 'u'
        select @localecount       = si.rows from sysobjects so with (nolock) join sysindexes si with (nolock) on so.id = si.id where so.id = object_id('
    ProductLocaleSetting') and si.indid < 2 and type = 'u'
        select @custlevelcount    = si.rows from sysobjects so with (nolock) join sysindexes si with (nolock) on so.id = si.id where so.id = object_id('
    ProductCustomerLevel') and si.indid < 2 and type = 'u'
        select @affiliatecount    = si.rows from sysobjects so with (nolock) join sysindexes si with (nolock) on so.id = si.id where so.id = object_id('
    ProductAffiliate') and si.indid < 2 and type = 'u'
        select @distributorcount  = si.rows from sysobjects so with (nolock) join sysindexes si with (nolock) on so.id = si.id where so.id = object_id('
    ProductDistributor') and si.indid < 2 and type = 'u'
        select @genrecount        = si.rows from sysobjects so with (nolock) join sysindexes si with (nolock) on so.id = si.id where so.id = object_id('
    ProductGenre') and si.indid < 2 and type = 'u'
        select @vectorcount       = si.rows from sysobjects so with (nolock) join sysindexes si with (nolock) on so.id = si.id where so.id = object_id('
    ProductVector') and si.indid < 2 and type = 'u'
        select @manufacturercount = si.rows from sysobjects so with (nolock) join sysindexes si with (nolock) on so.id = si.id where so.id = object_id('
    ProductManufacturer') and si.indid < 2 and type = 'u'


        -- get page size  
        IF @pagesize is null or @pagesize = 0 BEGIN  
            IF @categoryID is not null  
                SELECT @pagesize = PageSize FROM dbo.Category with (nolock) WHERE categoryID = @categoryID  
            ELSE IF @sectionID is not null  
                SELECT @pagesize = PageSize FROM dbo.Section with (nolock) WHERE sectionID = @sectionID  
            ELSE IF @manufacturerID is not null  
                SELECT @pagesize = PageSize FROM dbo.Manufacturer with (nolock) WHERE manufacturerID = @manufacturerID  
            ELSE IF @distributorID is not null  
                SELECT @pagesize = PageSize FROM dbo.Distributor with (nolock) WHERE distributorID = @distributorID  
            ELSE IF @genreID is not null  
                SELECT @pagesize = PageSize FROM dbo.Genre with (nolock) WHERE genreID = @genreID  
            ELSE IF @vectorID is not null  
                SELECT @pagesize = PageSize FROM dbo.Vector with (nolock) WHERE vectorID = @vectorID  
            ELSE   
                SELECT @pagesize = convert(int, ConfigValue) FROM dbo.AppConfig with (nolock) WHERE [Name] = '
    Default_CategoryPageSize'  
        END  
      
        IF @pagesize is null or @pagesize = 0  
            SET @pagesize = 20  
      
        -- get sort order  
        IF @sortEntity = 1 or @sortEntityName = '
    category' BEGIN  
            INSERT #displayorder select distinct null as [name], a.productid, displayorder from dbo.ProductCategory a with (nolock) inner join (select distinct a.ProductID from ProductCategory a with (nolock) 
            left join ProductStore b with (nolock) on a.ProductID = b.ProductID where (@filterProduct = 0 or StoreID = @storeID)) b  on a.ProductID = b.ProductID where categoryID = @categoryID 
        END  
        ELSE IF @sortEntity = 2 or @sortEntityName = '
    section' BEGIN  
            INSERT #displayorder select distinct null as [name], a.productid, displayorder from dbo.ProductSection a with (nolock) inner join (select distinct a.ProductID from ProductSection a with (nolock) 
            left join ProductStore b with (nolock) on a.ProductID = b.ProductID where (@filterProduct = 0 or StoreID = @storeID)) b on a.ProductID = B.ProductID where sectionId = @sectionID
        END  
        ELSE IF @sortEntity = 3 or @sortEntityName = '
    manufacturer' BEGIN  
            INSERT #displayorder select distinct null as [name], a.productid, displayorder from dbo.ProductManufacturer a with (nolock) inner join (select distinct a.ProductID from ProductManufacturer a with (nolock) 
            left join ProductStore b with (nolock) on a.ProductID = b.ProductID where (@filterProduct = 0 or StoreID = @storeID)) b on a.ProductID = B.ProductID where ManufacturerID = @manufacturerID
        END  
        ELSE IF @sortEntity = 4 or @sortEntityName = '
    distributor' BEGIN  
            INSERT #displayorder select distinct null as [name], a.productid, displayorder from dbo.ProductDistributor a with (nolock) inner join (select distinct a.ProductID from ProductDistributor a with (nolock) 
            left join ProductStore b with (nolock) on a.ProductID = b.ProductID where (@filterProduct = 0 or StoreID = @storeID)) b on a.ProductID = B.ProductID where DistributorID = @distributorID
        END  
        ELSE IF @sortEntity = 5 or @sortEntityName = '
    genre' BEGIN  
            INSERT #displayorder select distinct null as [name], a.productid, displayorder from dbo.ProductGenre a with (nolock) inner join (select distinct a.ProductID from ProductGenre a with (nolock) 
            left join ProductStore b with (nolock) on a.ProductID = b.ProductID where (@filterProduct = 0 or StoreID = @storeID)) b on a.ProductID = B.ProductID where GenreID = @genreID
        END  
        ELSE IF @sortEntity = 6 or @sortEntityName = '
    vector' BEGIN  
            INSERT #displayorder select distinct null as [name], a.productid, displayorder from dbo.ProductVector a with (nolock) inner join (select distinct a.ProductID from ProductVector a with (nolock) 
            left join ProductStore b with (nolock) on a.ProductID = b.ProductID where (@filterProduct = 0 or StoreID = @storeID)) b on a.ProductID = B.ProductID where VectorID = @vectorID
        END  
        ELSE BEGIN  
            INSERT #displayorder select distinct [name], a.productid, 1 from dbo.Product a with (nolock) inner join (select distinct a.ProductID from Product a with (nolock) 
            left join ProductStore b with (nolock) on a.ProductID = b.ProductID where (@filterProduct = 0 or StoreID = @storeID)) b on a.ProductID = B.ProductID ORDER BY Name  
        END



        --SET @searchstr = '
    %' + rtrim(ltrim(@searchstr)) + '%'
    declare @ftscount int
    CREATE TABLE #fts ([key] int not null, [rank] int not null)
        IF @InventoryFilter <> -1 BEGIN

            IF @ViewType = 1 BEGIN
                INSERT #inventoryfilter
                SELECT p.productid, pv.VariantID, sum(case p.TrackInventoryBySizeAndColor when 1 then isnull(i.quan, 0) else pv.inventory end ) invqty
                FROM product p with (NOLOCK) join #displayorder d on p.ProductID = d.ProductID
                    join ProductVariant pv with (NOLOCK) on p.ProductID = pv.ProductID  and pv.IsDefault = 1
                    left join Inventory i with (NOLOCK) on pv.VariantID = i.VariantID
                GROUP BY p.productid, pv.VariantID
                HAVING sum(case p.TrackInventoryBySizeAndColor when 1 then isnull(i.quan, 0) else pv.inventory end ) >= @InventoryFilter
            END
            ELSE
                INSERT #inventoryfilter
                SELECT p.productid, pv.VariantID, sum(case p.TrackInventoryBySizeAndColor when 1 then isnull(i.quan, 0) else pv.inventory end ) invqty
                FROM product p with (NOLOCK) join #displayorder d on p.ProductID = d.ProductID
                    join ProductVariant pv with (NOLOCK) on p.ProductID = pv.ProductID
                    left join Inventory i with (NOLOCK) on pv.VariantID = i.VariantID
                GROUP BY p.productid, pv.VariantID
                HAVING sum(case p.TrackInventoryBySizeAndColor when 1 then isnull(i.quan, 0) else pv.inventory end ) >= @InventoryFilter
                    IF @searchstr is not null BEGIN                
                    
                    INSERT #fts SELECT [key],[rank] from CONTAINSTABLE (product,*,@searchstr)
                    SELECT @ftscount = (SELECT count(*) from #fts)
                        IF @ftscount  <> 0 BEGIN
                            INSERT @productfilter (productid, VariantID, VariantDisplayOrder, ProductName, VariantName, [rank])
                            SELECT distinct p.productid, pv.VariantID, pv.DisplayOrder, p.Name, pv.Name, ft.rank
                            FROM 
                                product p with (nolock)
                                inner join #fts as ft on p.ProductID=ft.[key]
                                left join ProductVariant pv        with (NOLOCK) ON p.ProductID = pv.ProductID and pv.IsDefault >= @ViewType
                                left join productcategory pc       with (nolock) on p.ProductID = pc.ProductID                             
                                left join ProductCustomerLevel pcl with (nolock) on p.ProductID = pcl.ProductID                             
                                join #inventoryfilter i on pv.VariantID = i.VariantID            
                            WHERE 
                                  (pc.categoryid = @categoryID or @categoryID is null or @categorycount = 0)                                                                          
                              and p.ProductTypeID = coalesce(@ProductTypeID, p.ProductTypeID)
                              and (case 
                                    when @FilterProductsByCustomerLevel = 0 or @custlevelcount = 0 or pcl.CustomerLevelID is null or @CustomerLevelID is null then 1
                                    when @CustomerLevelFilteringIsAscending = 1 and pcl.CustomerLevelID <= @CustomerLevelID then 1 
                                    when pcl.CustomerLevelID = @CustomerLevelID or pcl.CustomerLevelID is null then 1 
                                    else 0
                                   end  = 1
                                  )
                              and case when isnull(pv.saleprice,0) = 0 then 0 else 1 end >= @OnSaleOnly
                              and p.published >= @publishedonly
                              and pv.published >= @publishedonly
                              and isnull(p.IsAPack, 0) <= 1-@ExcludePacks
                              and isnull(p.IsAKit, 0) <= 1-@ExcludeKits
                              and p.IsSystem <= 1-@ExcludeSysProds
                              and p.Deleted = 0
                              and pv.Deleted = 0                          
                              or (
                                     @searchstr2 is null
                                  or patindex(@searchstr2, isnull(convert(nvarchar(20),p.productid), '')) > 0              
                                  )
                            order by ft.rank desc
                        END
                        ELSE BEGIN
                            INSERT @productfilter (productid, VariantID, VariantDisplayOrder, ProductName, VariantName)
                            SELECT distinct p.productid, pv.VariantID, pv.DisplayOrder, p.Name, pv.Name
                            FROM 
                                product p with (nolock)                            
                                left join ProductVariant pv        with (NOLOCK) ON p.ProductID = pv.ProductID and pv.IsDefault >= @ViewType
                                left join productcategory pc       with (nolock) on p.ProductID = pc.ProductID                             
                                left join ProductCustomerLevel pcl with (nolock) on p.ProductID = pcl.ProductID                             
                                join #inventoryfilter i on pv.VariantID = i.VariantID            
                            WHERE 
                                  (pc.categoryid = @categoryID or @categoryID is null or @categorycount = 0)                          
                              and p.ProductTypeID = coalesce(@ProductTypeID, p.ProductTypeID)
                              and (case 
                                    when @FilterProductsByCustomerLevel = 0 or @custlevelcount = 0 or pcl.CustomerLevelID is null or @CustomerLevelID is null then 1
                                    when @CustomerLevelFilteringIsAscending = 1 and pcl.CustomerLevelID <= @CustomerLevelID then 1 
                                    when pcl.CustomerLevelID = @CustomerLevelID or pcl.CustomerLevelID is null then 1 
                                    else 0
                                   end  = 1
                                  )                          
                              and (
                                 @searchstr2 is null
                              or patindex('
    %'+@searchstr2+'%', isnull(p.name, '')) > 0
                              or patindex(@searchstr2, isnull(convert(nvarchar(20),p.productid), '')) > 0 
                              or patindex('
    %'+@searchstr2+'%', isnull(pv.name, '')) > 0
                              or patindex('
    %'+@searchstr2+'%', isnull(p.sku , '')+isnull(pv.skusuffix, '')) > 0
                              or patindex('
    %'+@searchstr2+'%', isnull(p.manufacturerpartnumber, '')) > 0
                              or patindex('
    %'+@searchstr2+'%', isnull(pv.manufacturerpartnumber, '')) > 0                      
                              )   
                              and case when isnull(pv.saleprice,0) = 0 then 0 else 1 end >= @OnSaleOnly
                              and p.published >= @publishedonly
                              and pv.published >= @publishedonly
                              and isnull(p.IsAPack, 0) <= 1-@ExcludePacks
                              and isnull(p.IsAKit, 0) <= 1-@ExcludeKits
                              and p.IsSystem <= 1-@ExcludeSysProds
                              and p.Deleted = 0
                              and pv.Deleted = 0                          
                        END
                    END
                    ELSE BEGIN
                        INSERT @productfilter (productid, displayorder, VariantID, VariantDisplayOrder, ProductName, VariantName)
                        SELECT distinct p.productid, do.displayorder, pv.VariantID, pv.DisplayOrder, p.Name, pv.Name
                        FROM 
                            product p with (nolock)
                            join #displayorder do on p.ProductID = do.ProductID 
                            left join ProductVariant pv        with (NOLOCK) ON p.ProductID = pv.ProductID and pv.IsDefault >= @ViewType
                            left join productcategory pc       with (nolock) on p.ProductID = pc.ProductID                         
                            left join ProductCustomerLevel pcl with (nolock) on p.ProductID = pcl.ProductID                         
                            join #inventoryfilter i on pv.VariantID = i.VariantID
                        WHERE 
                              (pc.categoryid = @categoryID or @categoryID is null or @categorycount = 0)                      
                          and p.ProductTypeID = coalesce(@ProductTypeID, p.ProductTypeID)
                          and (case 
                                when @FilterProductsByCustomerLevel = 0 or @custlevelcount = 0 or pcl.CustomerLevelID is null or @CustomerLevelID is null then 1
                                when @CustomerLevelFilteringIsAscending = 1 and pcl.CustomerLevelID <= @CustomerLevelID then 1 
                                when pcl.CustomerLevelID = @CustomerLevelID or pcl.CustomerLevelID is null then 1 
                                else 0
                               end  = 1
                              )
                          and (
                                 @searchstr2 is null
                              or patindex('
    %'+@searchstr2+'%', isnull(p.name, '')) > 0
                              or patindex(@searchstr2, isnull(convert(nvarchar(20),p.productid), '')) > 0 
                              or patindex('
    %'+@searchstr2+'%', isnull(pv.name, '')) > 0
                              or patindex('
    %'+@searchstr2+'%', isnull(p.sku , '')+isnull(pv.skusuffix, '')) > 0
                              or patindex('
    %'+@searchstr2+'%', isnull(p.manufacturerpartnumber, '')) > 0
                              or patindex('
    %'+@searchstr2+'%', isnull(pv.manufacturerpartnumber, '')) > 0
                              or (patindex('
    %'+@searchstr2+'%', isnull(p.Description, '')) > 0 and @extSearch = 1)
                              or (patindex('
    %'+@searchstr2+'%', isnull(p.Summary, '')) > 0 and @extSearch = 1)
                              )
                          and case when isnull(pv.saleprice,0) = 0 then 0 else 1 end >= @OnSaleOnly
                          and p.published >= @publishedonly
                          and pv.published >= @publishedonly
                          and isnull(p.IsAPack, 0) <= 1-@ExcludePacks
                          and isnull(p.IsAKit, 0) <= 1-@ExcludeKits
                          and p.IsSystem <= 1-@ExcludeSysProds
                          and p.Deleted = 0
                          and pv.Deleted = 0
                          
                        order by do.displayorder, p.Name, pv.DisplayOrder, pv.Name
                    END
        END 
        ELSE BEGIN
                IF @searchstr is not null BEGIN                 
                    
                    INSERT #fts SELECT [key],[rank] from CONTAINSTABLE (product,*,@searchstr)
                    SELECT @ftscount = (SELECT count(*) from #fts)
                    IF @ftscount  <> 0 BEGIN
                        INSERT @productfilter (productid, VariantID, VariantDisplayOrder, ProductName, VariantName, [rank])
                        SELECT distinct p.productid, pv.VariantID, pv.DisplayOrder, p.Name, pv.Name, ft.rank
                        FROM 
                            product p with (nolock)
                            inner join #fts as ft on p.ProductID=ft.[key]                        
                            join ProductVariant pv             with (NOLOCK) on p.ProductID = pv.ProductID and pv.IsDefault >= @ViewType
                            left join productcategory pc       with (nolock) on p.ProductID = pc.ProductID 
                            left join ProductCustomerLevel pcl with (nolock) on p.ProductID = pcl.ProductID                         
                        WHERE 
                              (pc.categoryid = @categoryID or @categoryID is null or @categorycount = 0)                      
                          and p.ProductTypeID = coalesce(@ProductTypeID, p.ProductTypeID)
                          and (case 
                                when @FilterProductsByCustomerLevel = 0 or @custlevelcount = 0 or pcl.CustomerLevelID is null or @CustomerLevelID is null then 1
                                when @CustomerLevelFilteringIsAscending = 1 and pcl.CustomerLevelID <= @CustomerLevelID then 1 
                                when pcl.CustomerLevelID = @CustomerLevelID or pcl.CustomerLevelID is null then 1 
                                else 0
                               end  = 1
                              )                              
                          and case when isnull(pv.saleprice,0) = 0 then 0 else 1 end >= @OnSaleOnly
                          and p.published >= @publishedonly
                          and pv.published >= @publishedonly
                          and isnull(p.IsAPack, 0) <= 1-@ExcludePacks
                          and isnull(p.IsAKit, 0) <= 1-@ExcludeKits
                          and p.IsSystem <= 1-@ExcludeSysProds
                          and p.Deleted = 0
                          and pv.Deleted = 0                      
                          or patindex(@searchstr2, isnull(convert(nvarchar(20),p.productid), '')) > 0 
                        order by ft.rank desc
                    END
                    ELSE BEGIN
                        INSERT @productfilter (productid, VariantID, VariantDisplayOrder, ProductName, VariantName)
                        SELECT distinct p.productid, pv.VariantID, pv.DisplayOrder, p.Name, pv.Name
                        FROM 
                            product p with (nolock)
                            
                            
                            join ProductVariant pv             with (NOLOCK) on p.ProductID = pv.ProductID and pv.IsDefault >= @ViewType
                            left join productcategory pc       with (nolock) on p.ProductID = pc.ProductID                         
                            left join ProductCustomerLevel pcl with (nolock) on p.ProductID = pcl.ProductID 
                            
                        WHERE 
                              (pc.categoryid = @categoryID or @categoryID is null or @categorycount = 0)                      
                          and p.ProductTypeID = coalesce(@ProductTypeID, p.ProductTypeID)
                          and (case 
                                when @FilterProductsByCustomerLevel = 0 or @custlevelcount = 0 or pcl.CustomerLevelID is null or @CustomerLevelID is null then 1
                                when @CustomerLevelFilteringIsAscending = 1 and pcl.CustomerLevelID <= @CustomerLevelID then 1 
                                when pcl.CustomerLevelID = @CustomerLevelID or pcl.CustomerLevelID is null then 1 
                                else 0
                               end  = 1
                              )                      
                          and (
                             @searchstr2 is null
                          or patindex('
    %'+@searchstr2+'%', isnull(p.name, '')) > 0
                          or patindex(@searchstr2, isnull(convert(nvarchar(20),p.productid), '')) > 0 
                          or patindex('
    %'+@searchstr2+'%', isnull(pv.name, '')) > 0
                          or patindex('
    %'+@searchstr2+'%', isnull(p.sku , '')+isnull(pv.skusuffix , '')) > 0
                          or patindex('
    %'+@searchstr2+'%', isnull(p.manufacturerpartnumber, '')) > 0
                          or patindex('
    %'+@searchstr2+'%', isnull(pv.manufacturerpartnumber, '')) > 0
                          or (patindex('
    %'+@searchstr2+'%', isnull(p.Description, '')) > 0 and @extSearch = 1)
                          or (patindex('
    %'+@searchstr2+'%', isnull(p.Summary, '')) > 0 and @extSearch = 1)
                          )                                  
                          and case when isnull(pv.saleprice,0) = 0 then 0 else 1 end >= @OnSaleOnly
                          and p.published >= @publishedonly
                          and pv.published >= @publishedonly
                          and isnull(p.IsAPack, 0) <= 1-@ExcludePacks
                          and isnull(p.IsAKit, 0) <= 1-@ExcludeKits
                          and p.IsSystem <= 1-@ExcludeSysProds
                          and p.Deleted = 0
                          and pv.Deleted = 0                    
                    END
                END
                ELSE BEGIN
                INSERT @productfilter (productid, displayorder, VariantID, VariantDisplayOrder, ProductName, VariantName)
                    SELECT distinct p.productid, do.displayorder, pv.VariantID, pv.DisplayOrder, p.Name, pv.Name
                    FROM 
                        product p with (nolock)
                        join #displayorder do on p.ProductID = do.ProductID 
                        join ProductVariant pv             with (NOLOCK) on p.ProductID = pv.ProductID and pv.IsDefault >= @ViewType
                        left join productcategory pc       with (nolock) on p.ProductID = pc.ProductID                     
                        left join ProductCustomerLevel pcl with (nolock) on p.ProductID = pcl.ProductID 
                    WHERE 
                          (pc.categoryid = @categoryID or @categoryID is null or @categorycount = 0)                  
                      and p.ProductTypeID = coalesce(@ProductTypeID, p.ProductTypeID)
                      and (case 
                            when @FilterProductsByCustomerLevel = 0 or @custlevelcount = 0 or pcl.CustomerLevelID is null or @CustomerLevelID is null then 1
                            when @CustomerLevelFilteringIsAscending = 1 and pcl.CustomerLevelID <= @CustomerLevelID then 1 
                            when pcl.CustomerLevelID = @CustomerLevelID or pcl.CustomerLevelID is null then 1 
                            else 0
                           end  = 1
                          )
                      and (
                             @searchstr2 is null
                          or patindex('
    %'+@searchstr2+'%', isnull(p.name, '')) > 0
                          or patindex(@searchstr2, isnull(convert(nvarchar(20),p.productid), '')) > 0 
                          or patindex('
    %'+@searchstr2+'%', isnull(pv.name, '')) > 0
                          or patindex('
    %'+@searchstr2+'%', isnull(p.sku , '')+isnull(pv.skusuffix , '')) > 0
                          or patindex('
    %'+@searchstr2+'%', isnull(p.manufacturerpartnumber, '')) > 0
                          or patindex('
    %'+@searchstr2+'%', isnull(pv.manufacturerpartnumber, '')) > 0
                          or (patindex('
    %'+@searchstr2+'%', isnull(p.Description, '')) > 0 and @extSearch = 1)
                          or (patindex('
    %'+@searchstr2+'%', isnull(p.Summary, '')) > 0 and @extSearch = 1)
                          )
                      and case when isnull(pv.saleprice,0) = 0 then 0 else 1 end >= @OnSaleOnly
                      and p.published >= @publishedonly
                      and pv.published >= @publishedonly
                      and isnull(p.IsAPack, 0) <= 1-@ExcludePacks
                      and isnull(p.IsAKit, 0) <= 1-@ExcludeKits
                      and p.IsSystem <= 1-@ExcludeSysProds
                      and p.Deleted = 0
                      and pv.Deleted = 0                  
                    order by do.displayorder, p.Name, pv.DisplayOrder, pv.Name
                END            
        END

        SET @rcount = @@rowcount
        IF @StatsFirst = 1
            SELECT cast(ceiling(@rcount*1.0/@pagesize) as int) pages, @rcount ProductCount
    IF @searchstr is not null BEGIN
        SELECT pf.rank,
            p.ProductID,
            p.Name,
            pv.VariantID,
            pv.Name AS VariantName,
            p.ProductGUID,
            p.Summary,
            p.Description,
            p.SEKeywords,
            p.SEDescription,
            p.SpecTitle,
            p.MiscText,
            p.SwatchImageMap,
            p.IsFeaturedTeaser,
            p.FroogleDescription,
            p.SETitle,
            p.SENoScript,
            p.SEAltText,
            p.SizeOptionPrompt,
            p.ColorOptionPrompt,
            p.TextOptionPrompt,
            p.ProductTypeID,
            p.TaxClassID,
            p.SKU,
            p.ManufacturerPartNumber,
            p.SalesPromptID,
            p.SpecCall,
            p.SpecsInline,
            p.IsFeatured,
            p.XmlPackage,
            p.ColWidth,
            p.Published,
            p.RequiresRegistration,
            p.Looks,
            p.Notes,
            p.QuantityDiscountID,
            p.RelatedProducts,
            p.UpsellProducts,
            p.UpsellProductDiscountPercentage,
            p.RelatedDocuments,
            p.TrackInventoryBySizeAndColor,
            p.TrackInventoryBySize,
            p.TrackInventoryByColor,
            p.IsAKit,
            p.ShowInProductBrowser,
            p.IsAPack,
            p.PackSize,
            p.ShowBuyButton,
            p.RequiresProducts,
            p.HidePriceUntilCart,
            p.IsCalltoOrder,
            p.ExcludeFromPriceFeeds,
            p.RequiresTextOption,
            p.TextOptionMaxLength,
            p.SEName,
            p.Deleted,
            p.CreatedOn,
            p.ImageFileNameOverride,
            pv.VariantGUID,
            pv.Description AS VariantDescription,
            pv.SEKeywords AS VariantSEKeywords,
            pv.SEDescription AS VariantSEDescription,
            pv.Colors,
            pv.ColorSKUModifiers,
            pv.Sizes,
            pv.SizeSKUModifiers,
            pv.FroogleDescription AS VariantFroogleDescription,
            pv.SKUSuffix,
            pv.ManufacturerPartNumber AS VariantManufacturerPartNumber,
            pv.Price,
            pv.CustomerEntersPrice, 
            pv.CustomerEntersPricePrompt,
            isnull(pv.SalePrice, 0) SalePrice,
            cast(isnull(pv.Weight,0) as decimal(10,1)) Weight,
            pv.MSRP,
            pv.Cost,
            isnull(pv.Points,0) Points,
            pv.Dimensions,
            case p.TrackInventoryBySizeAndColor when 1 then isnull(i.quan, 0) else pv.inventory end Inventory,
            pv.DisplayOrder as VariantDisplayOrder,
            pv.Notes AS VariantNotes,
            pv.IsTaxable,
            pv.IsShipSeparately,
            pv.IsDownload,
            pv.DownloadLocation,
            pv.Published AS VariantPublished,
            pv.IsSecureAttachment,
            pv.IsRecurring,
            pv.RecurringInterval,
            pv.RecurringIntervalType,
            pv.SubscriptionInterval,
            pv.SEName AS VariantSEName,
            pv.RestrictedQuantities,
            pv.MinimumQuantity,
            pv.Deleted AS VariantDeleted,
            pv.CreatedOn AS VariantCreatedOn,
            d.Name AS DistributorName,
            d.DistributorID,
            d.SEName AS DistributorSEName,
            m.ManufacturerID,
            m.Name AS ManufacturerName,
            m.SEName AS ManufacturerSEName,
            s.Name AS SalesPromptName,
            case when pcl.productid is null then 0 else isnull(ep.Price, 0) end ExtendedPrice,
        p.ExtensionData,
        p.ExtensionData2,
        p.ExtensionData3,
        p.ExtensionData4,
        p.ExtensionData5
        FROM dbo.Product p with (NOLOCK) 
            left join dbo.ProductVariant       pv  with (NOLOCK) on p.ProductID = pv.ProductID and pv.IsDefault >= @ViewType
            join @productfilter                pf                on pv.ProductID = pf.ProductID and pv.VariantID = pf.VariantID 
            left join dbo.SalesPrompt           s  with (NOLOCK) on p.SalesPromptID = s.SalesPromptID 
            left join dbo.ProductManufacturer  pm  with (NOLOCK) on p.ProductID = pm.ProductID 
            left join dbo.Manufacturer          m  with (NOLOCK) on pm.ManufacturerID = m.ManufacturerID 
            left join dbo.ProductDistributor   pd  with (NOLOCK) on p.ProductID = pd.ProductID
            left join dbo.Distributor           d  with (NOLOCK) on pd.DistributorID = d.DistributorID
            left join dbo.ExtendedPrice        ep  with (NOLOCK) on ep.VariantID = pv.VariantID and ep.CustomerLevelID = @CustomerLevelID
            left join dbo.ProductCustomerLevel pcl with (NOLOCK) on p.ProductID = pcl.ProductID and pcl.CustomerLevelID = @CustomerLevelID
            left join (select VariantID, sum(quan) quan from dbo.Inventory with (nolock) group by VariantID) i  on pv.VariantID = i.VariantID
        WHERE pf.rownum >= @pagesize*(@pagenum-1)+1 and pf.rownum <= @pagesize*(@pagenum)
        ORDER BY pf.rank desc
    END
    ELSE BEGIN
        SELECT 
            p.ProductID,
            p.Name,
            pv.VariantID,
            pv.Name AS VariantName,
            p.ProductGUID,
            p.Summary,
            p.Description,
            p.SEKeywords,
            p.SEDescription,
            p.SpecTitle,
            p.MiscText,
            p.SwatchImageMap,
            p.IsFeaturedTeaser,
            p.FroogleDescription,
            p.SETitle,
            p.SENoScript,
            p.SEAltText,
            p.SizeOptionPrompt,
            p.ColorOptionPrompt,
            p.TextOptionPrompt,
            p.ProductTypeID,
            p.TaxClassID,
            p.SKU,
            p.ManufacturerPartNumber,
            p.SalesPromptID,
            p.SpecCall,
            p.SpecsInline,
            p.IsFeatured,
            p.XmlPackage,
            p.ColWidth,
            p.Published,
            p.RequiresRegistration,
            p.Looks,
            p.Notes,
            p.QuantityDiscountID,
            p.RelatedProducts,
            p.UpsellProducts,
            p.UpsellProductDiscountPercentage,
            p.RelatedDocuments,
            p.TrackInventoryBySizeAndColor,
            p.TrackInventoryBySize,
            p.TrackInventoryByColor,
            p.IsAKit,
            p.ShowInProductBrowser,
            p.IsAPack,
            p.PackSize,
            p.ShowBuyButton,
            p.RequiresProducts,
            p.HidePriceUntilCart,
            p.IsCalltoOrder,
            p.ExcludeFromPriceFeeds,
            p.RequiresTextOption,
            p.TextOptionMaxLength,
            p.SEName,
            p.Deleted,
            p.CreatedOn,
            p.ImageFileNameOverride,
            pv.VariantGUID,
            pv.Description AS VariantDescription,
            pv.SEKeywords AS VariantSEKeywords,
            pv.SEDescription AS VariantSEDescription,
            pv.Colors,
            pv.ColorSKUModifiers,
            pv.Sizes,
            pv.SizeSKUModifiers,
            pv.FroogleDescription AS VariantFroogleDescription,
            pv.SKUSuffix,
            pv.ManufacturerPartNumber AS VariantManufacturerPartNumber,
            pv.Price,
            pv.CustomerEntersPrice, 
            pv.CustomerEntersPricePrompt,
            isnull(pv.SalePrice, 0) SalePrice,
            cast(isnull(pv.Weight,0) as decimal(10,1)) Weight,
            pv.MSRP,
            pv.Cost,
            isnull(pv.Points,0) Points,
            pv.Dimensions,
            case p.TrackInventoryBySizeAndColor when 1 then isnull(i.quan, 0) else pv.inventory end Inventory,
            pv.DisplayOrder as VariantDisplayOrder,
            pv.Notes AS VariantNotes,
            pv.IsTaxable,
            pv.IsShipSeparately,
            pv.IsDownload,
            pv.DownloadLocation,
            pv.Published AS VariantPublished,
            pv.IsSecureAttachment,
            pv.IsRecurring,
            pv.RecurringInterval,
            pv.RecurringIntervalType,
            pv.SubscriptionInterval,
            pv.SEName AS VariantSEName,
            pv.RestrictedQuantities,
            pv.MinimumQuantity,
            pv.Deleted AS VariantDeleted,
            pv.CreatedOn AS VariantCreatedOn,
            d.Name AS DistributorName,
            d.DistributorID,
            d.SEName AS DistributorSEName,
            m.ManufacturerID,
            m.Name AS ManufacturerName,
            m.SEName AS ManufacturerSEName,
            s.Name AS SalesPromptName,
            case when pcl.productid is null then 0 else isnull(ep.Price, 0) end ExtendedPrice,
            p.ExtensionData,
            p.ExtensionData2,
            p.ExtensionData3,
            p.ExtensionData4,
            p.ExtensionData5
        FROM Product p with (NOLOCK) 
            left join ProductVariant       pv  with (NOLOCK) on p.ProductID = pv.ProductID and pv.IsDefault >= @ViewType
            join @productfilter            pf                on pv.ProductID = pf.ProductID and pv.VariantID = pf.VariantID 
            left join SalesPrompt           s  with (NOLOCK) on p.SalesPromptID = s.SalesPromptID 
            left join ProductManufacturer  pm  with (NOLOCK) on p.ProductID = pm.ProductID 
            left join Manufacturer          m  with (NOLOCK) on pm.ManufacturerID = m.ManufacturerID 
            left join ProductDistributor   pd  with (NOLOCK) on p.ProductID = pd.ProductID
            left join Distributor           d  with (NOLOCK) on pd.DistributorID = d.DistributorID
            left join ExtendedPrice        ep  with (NOLOCK) on ep.VariantID = pv.VariantID and ep.CustomerLevelID = @CustomerLevelID
            left join ProductCustomerLevel pcl with (NOLOCK) on p.ProductID = pcl.ProductID and pcl.CustomerLevelID = @CustomerLevelID
            left join (select VariantID, sum(quan) quan from Inventory with (nolock) group by VariantID) i  on pv.VariantID = i.VariantID
        WHERE pf.rownum >= @pagesize*(@pagenum-1)+1 and pf.rownum <= @pagesize*(@pagenum)
        ORDER BY pf.rownum
    END
        IF @StatsFirst <> 1
            SELECT cast(ceiling(@rcount*1.0/@pagesize) as int) pages, @rcount ProductCount
        
    END 
    As you may notice there is a there is SQL variable called searchstr2. It is used so I can use both full text search and the regular search. Some times the regular search is better to use when it comes to part numbers for me. This is because many of our part numbers have a "-" in them. Since "-" is considered white text it doesn't return the result I want for that search. For this reason the code behind and search xml package are also edited. The xmlpackage is simply adding SearchTerm2 to the sql statment and runtime. The code behind is a little be more complex. Due also note that my search page uses a aspdnsf:XmlPackage control but is should be easy to port over the code to the litSearch if that is used for output instead. Here is that code in C#:

    C#/VB.NET Code:
    StringBuilder sb = new StringBuilder();
                
    sb.Append(CommonLogic.QueryStringCanBeDangerousContent("SearchTerm"));
                
    Regex excl = new Regex(@"\s\-(\w+)(?: |$)"RegexOptions.IgnorePatternWhitespace);
                
    //Label1.Text = "";
                
    StringBuilder filter = new StringBuilder();
                foreach (
    Match m in excl.Matches(sb.ToString()))
                {
                    
    sb.Replace(" -" m.Groups[1].Value"");
                    
    filter.Append(" and not \"" m.Groups[1].Value "\"");
                }
                
    sb sb.Replace("\"""");
                if (
    sb.Length 0)
                {
                    
    Package1.RuntimeParams "SearchTerm=\"" sb.ToString() + "\"&SearchTerm2=FORMSOF(Thesaurus,\"" sb.ToString() + "\") " filter.ToString();
                    
    //Label1.Text = "SearchTerm=" + sb.ToString() + "&SearchTerm2=FORMSOF(Thesaurus,\"" + sb.ToString() + "\") " + filter.ToString();
                
    }
                else
                {
                    
    Package1.RuntimeParams "SearchTerm=\"" sb.ToString() + "\"";
                    
    //Label1.Text = "SearchTerm=" + sb.ToString() + "&SearchTerm2=FORMSOF(Thesaurus,\"" + sb.ToString() + "\") " + filter.ToString();
                

    Hope this helps.

    This is my get_products Procedure please help me
    can you please help me with the modifications
    C#/VB.NET Code:
    USE [packandseal]
    GO
    /****** Object:  StoredProcedure [dbo].[aspdnsf_GetProducts]    Script Date: 02/15/2011 16:03:31 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO

                ALTER proc 
    [dbo].[aspdnsf_GetProducts
                    @
    categoryID int null
                    @
    sectionID int null
                    @
    manufacturerID int null
                    @
    distributorID int null
                    @
    genreID int null
                    @
    vectorID int null
                    @
    localeID int null
                    @
    CustomerLevelID int null
                    @
    affiliateID int null
                    @
    ProductTypeID int null
                    @
    ViewType bit 1
                    @
    sortEntity int 0
                    @
    pagenum int 1
                    @
    pagesize int null
                    @
    StatsFirst tinyint 1
                    @
    searchstr varchar(1000) = null
                    @
    extSearch tinyint 0
                    @
    publishedonly tinyint 0
                    @
    ExcludePacks tinyint 0
                    @
    ExcludeKits tinyint 0
                    @
    ExcludeSysProds tinyint 0
                    @
    InventoryFilter int 0
                    @
    sortEntityName varchar(20) = ''
                    @
    localeName varchar(20) = ''
                    @
    OnSaleOnly tinyint 0
                    @
    IncludeAll bit 
                    
    AS 
                    
    BEGIN 
                    SET NOCOUNT ON 
                    
    DECLARE @rcount int 
                    
    DECLARE @productfilter table (rownum int not null identity primary keyproductid int not nulldisplayorder int not nullVariantID int not nullVariantDisplayOrder int not nullProductName nvarchar(400nullVariantName nvarchar(400null
                    DECLARE @
    FilterProductsByAffiliate tinyint, @FilterProductsByCustomerLevel tinyint, @HideProductsWithLessThanThisInventoryLevel int 
                    CREATE TABLE 
    #displayorder (productid int not null primary key, displayorder int not null) 
                    
    CREATE TABLE #inventoryfilter (productid int not null, variantid int not null, InvQty int not null) 
                    
    CREATE CLUSTERED INDEX tmp_inventoryfilter ON #inventoryfilter (productid, variantid) 
                    
    DECLARE @custlevelcount int, @sectioncount int, @localecount int, @affiliatecount int, @categorycount int, @CustomerLevelFilteringIsAscending bit, @distributorcount int, @genrecount int, @vectorcount int, @manufacturercount int 
                    SELECT 
    @FilterProductsByAffiliate = case ConfigValue when 'true' then 1 else 0 end FROM dbo.AppConfig WHERE [Name] = 'FilterProductsByAffiliate' 
                    
    SELECT @FilterProductsByCustomerLevel = case ConfigValue when 'true' then 1 else 0 end FROM dbo.AppConfig WHERE [Name] = 'FilterProductsByCustomerLevel' 
                    
    SELECT @HideProductsWithLessThanThisInventoryLevel convert(intConfigValueFROM dbo.AppConfig WHERE [Name] = 'HideProductsWithLessThanThisInventoryLevel' and isnumeric(ConfigValue) = 
                    
    IF @InventoryFilter = -
                    SET 
    @InventoryFilter 
                    
    ELSE IF @HideProductsWithLessThanThisInventoryLevel > @InventoryFilter 
                    SET 
    @InventoryFilter = @HideProductsWithLessThanThisInventoryLevel 
                    SET 
    @categoryID nullif(@categoryID0
                    
    SET @sectionID nullif(@sectionID0
                    
    SET @manufacturerID nullif(@manufacturerID0
                    
    SET @distributorID nullif(@distributorID0
                    
    SET @genreID          nullif(@genreID0
                    
    SET @vectorID nullif(@vectorID0
                    
    SET @affiliateID nullif(@affiliateID0
                    
    SET @ProductTypeID nullif(@ProductTypeID0
                    
    SET @CustomerLevelFilteringIsAscending 
                    SELECT 
    @CustomerLevelFilteringIsAscending = case configvalue when 'true' then 1 else 0 end 
                    FROM appConfig 
                    WHERE name like 
    'CustomerLevelFilteringIsAscending ' 
                    
    IF @localeID is null and ltrim(rtrim(@localeName)) <> '' 
                    
    SELECT @localeID LocaleSettingID FROM LocaleSetting WHERE Name ltrim(rtrim(@localeName)) 
                    
    select @categorycount si.rows from sysobjects so with (nolockjoin sysindexes si with (nolockon so.id si.id where so.id object_id('productcategory') and si.indid and type 'u' 
                    
    select @sectioncount si.rows from sysobjects so with (nolockjoin sysindexes si with (nolockon so.id si.id where so.id object_id('productsection') and si.indid and type 'u' 
                    
    select @localecount si.rows from sysobjects so with (nolockjoin sysindexes si with (nolockon so.id si.id where so.id object_id('ProductLocaleSetting') and si.indid and type 'u' 
                    
    select @custlevelcount si.rows from sysobjects so with (nolockjoin sysindexes si with (nolockon so.id si.id where so.id object_id('ProductCustomerLevel') and si.indid and type 'u' 
                    
    select @affiliatecount si.rows from sysobjects so with (nolockjoin sysindexes si with (nolockon so.id si.id where so.id object_id('ProductAffiliate') and si.indid and type 'u' 
                    
    select @distributorcount si.rows from sysobjects so with (nolockjoin sysindexes si with (nolockon so.id si.id where so.id object_id('ProductDistributor') and si.indid and type 'u' 
                    
    select @genrecount si.rows from sysobjects so with (nolockjoin sysindexes si with (nolockon so.id si.id where so.id object_id('ProductGenre') and si.indid and type 'u' 
                    
    select @vectorcount si.rows from sysobjects so with (nolockjoin sysindexes si with (nolockon so.id si.id where so.id object_id('ProductVector') and si.indid and type 'u' 
                    
    select @manufacturercount si.rows from sysobjects so with (nolockjoin sysindexes si with (nolockon so.id si.id where so.id object_id('ProductManufacturer') and si.indid and type 'u' 
                    
    IF @pagesize is null or @pagesize 0 BEGIN 
                    
    IF @categoryID is not null 
                    SELECT 
    @pagesize PageSize FROM dbo.Category WHERE categoryID = @categoryID 
                    
    ELSE IF @sectionID is not null 
                    SELECT 
    @pagesize PageSize FROM dbo.Section WHERE sectionID = @sectionID 
                    
    ELSE IF @manufacturerID is not null 
                    SELECT 
    @pagesize PageSize FROM dbo.Manufacturer WHERE manufacturerID = @manufacturerID 
                    
    ELSE IF @distributorID is not null 
                    SELECT 
    @pagesize PageSize FROM dbo.Distributor WHERE distributorID = @distributorID 
                    
    ELSE IF @genreID is not null 
                    SELECT 
    @pagesize PageSize FROM dbo.Genre WHERE genreID = @genreID 
                    
    ELSE IF @vectorID is not null 
                    SELECT 
    @pagesize PageSize FROM dbo.Vector WHERE vectorID = @vectorID 
                    
    ELSE 
                    
    SELECT @pagesize convert(intConfigValueFROM dbo.AppConfig WHERE [Name] = 'Default_CategoryPageSize' 
                    
    END 
                    
    IF @pagesize is null or @pagesize 
                    SET 
    @pagesize 20 
                    
    IF @sortEntity or @sortEntityName 'category' BEGIN 
                    INSERT 
    #displayorder select productid, displayorder from ProductCategory where categoryID = @categoryID 
                    
    END 
                    
    ELSE IF @sortEntity or @sortEntityName 'section' BEGIN 
                    INSERT 
    #displayorder select productid, displayorder from ProductSection where sectionId = @sectionID 
                    
    END 
                    
    ELSE IF @sortEntity or @sortEntityName 'manufacturer' BEGIN 
                    INSERT 
    #displayorder select productid, displayorder from ProductManufacturer where ManufacturerID = @manufacturerID 
                    
    END 
                    
    ELSE IF @sortEntity or @sortEntityName 'distributor' BEGIN 
                    INSERT 
    #displayorder select productid, displayorder from ProductDistributor where DistributorID = @distributorID 
                    
    END 
                    
    ELSE IF @sortEntity or @sortEntityName 'genre' BEGIN 
                    INSERT 
    #displayorder select productid, displayorder from ProductGenre where GenreID = @genreID 
                    
    END 
                    
    ELSE IF @sortEntity or @sortEntityName 'vector' BEGIN 
                    INSERT 
    #displayorder select productid, displayorder from ProductVector where VectorID = @vectorID 
                    
    END 
                    
    ELSE BEGIN 
                    INSERT 
    #displayorder select productid, 1 from Product ORDER BY Name 
                    
    END 

                    SET 
    @searchstr Replace(@searchstr,'''','''''')            
                    
    SET @searchstr Replace(@searchstr,'+',' ')
                    
    SET @searchstr Replace(@searchstr,'"','')

                    IF 
    rtrim(isnull(@searchstr'')) <> '' BEGIN 
                    select 
    @searchstr dbo.GetValidSearchString(@searchstr
                    
    DELETE #displayorder from #displayorder d left join dbo.KeyWordSearch(@searchstr) k on d.productid = k.productid where k.productid is null 
                    
    END 
                    
    IF @InventoryFilter 0 BEGIN 
                    
    IF @ViewType 1 BEGIN 
                    INSERT 
    #inventoryfilter 
                    
    SELECT p.productidpv.VariantIDsum(case p.TrackInventoryBySizeAndColor when 1 then isnull(i.quan0) else pv.inventory end invqty 
                    FROM product p with 
    (NOLOCKjoin #displayorder d on p.ProductID = d.ProductID 
                    
    join ProductVariant pv with (NOLOCKon p.ProductID pv.ProductID and pv.IsDefault 
                    left join Inventory i with 
    (NOLOCKon pv.VariantID i.VariantID 
                    GROUP BY p
    .productidpv.VariantID 
                    HAVING sum
    (case p.TrackInventoryBySizeAndColor when 1 then isnull(i.quan0) else pv.inventory end ) >= @InventoryFilter 
                    END 
                    
    ELSE 
                    
    INSERT #inventoryfilter 
                    
    SELECT p.productidpv.VariantIDsum(case p.TrackInventoryBySizeAndColor when 1 then isnull(i.quan0) else pv.inventory end invqty 
                    FROM product p with 
    (NOLOCKjoin #displayorder d on p.ProductID = d.ProductID 
                    
    join ProductVariant pv with (NOLOCKon p.ProductID pv.ProductID 
                    left join Inventory i with 
    (NOLOCKon pv.VariantID i.VariantID 
                    GROUP BY p
    .productidpv.VariantID 
                    HAVING sum
    (case p.TrackInventoryBySizeAndColor when 1 then isnull(i.quan0) else pv.inventory end ) >= @InventoryFilter 
                    INSERT 
    @productfilter (productiddisplayorderVariantIDVariantDisplayOrderProductNameVariantName
                    
    SELECT distinct p.productid, do.displayorderpv.VariantIDpv.DisplayOrderp.Namepv.Name 
                    FROM 
                    product p with 
    (nolock
                    
    join #displayorder do on p.ProductID = do.ProductID 
                    
    left join ProductVariant pv with (NOLOCKON p.ProductID pv.ProductID and pv.IsDefault >= @ViewType 
                    left join productcategory pc with 
    (nolockon p.ProductID pc.ProductID 
                    left join productsection ps with 
    (nolockon p.ProductID ps.ProductID 
                    left join ProductManufacturer pm with 
    (nolockon p.ProductID pm.ProductID 
                    left join ProductDistributor pd with 
    (nolockon p.ProductID pd.ProductID 
                    left join ProductGenre px with 
    (nolockon p.ProductID px.ProductID 
                    left join ProductVector px2 with 
    (nolockon p.ProductID px2.ProductID 
                    left join ProductLocaleSetting pl with 
    (nolockon p.ProductID pl.ProductID 
                    left join ProductCustomerLevel pcl with 
    (nolockon p.ProductID pcl.ProductID 
                    left join ProductAffiliate pa with 
    (nolockon p.ProductID pa.ProductID 
                    join 
    #inventoryfilter i on pv.VariantID = i.VariantID 
                    
    WHERE 
                    
    (pc.categoryid = @categoryID or @categoryID is null or @categorycount 0
                    and (
    ps.sectionid = @sectionID or @sectionID is null or @sectioncount 0
                    and (
    pl.LocaleSettingID = @localeID or @localeID is null or @localecount 0
                    and (
    pa.AffiliateID = @affiliateID or @affiliateID is null or @affiliatecount or @FilterProductsByAffiliate 0
                    and (
    pm.manufacturerid = @manufacturerID or @manufacturerID is null or @manufacturercount 0
                    and (
    pd.DistributorID = @distributorID or @distributorID is null or @distributorcount 0
                    and (
    px.GenreID = @genreID or @genreID is null or @genrecount 0
                    and (
    px2.VectorID = @vectorID or @vectorID is null or @vectorcount 0
                    and 
    p.ProductTypeID coalesce(@ProductTypeIDp.ProductTypeID
                    and (case 
                    
    when @FilterProductsByCustomerLevel 0 then 1 
                    when 
    @CustomerLevelFilteringIsAscending and pcl.CustomerLevelID <= @CustomerLevelID or pcl.CustomerLevelID is null then 1 
                    when 
    @CustomerLevelID=and pcl.CustomerLevelID is null then 1 
                    when 
    @CustomerLevelID is null or @custlevelcount 0 then 1 
                    when pcl
    .CustomerLevelID = @CustomerLevelID or pcl.CustomerLevelID is null then 1 
                    
    else 
                    end 

                    

                    and case 
    when isnull(pv.saleprice,0) = 0 then 0 else 1 end >= @OnSaleOnly 
                    
    and p.published >= @publishedonly 
                    
    and pv.published >= @publishedonly 
                    
    and isnull(p.IsAPack0) <= 1-@ExcludePacks 
                    
    and isnull(p.IsAKit0) <= 1-@ExcludeKits 
                    
    and p.IsSystem <= 1-@ExcludeSysProds 
                    
    and p.Deleted 
                    
    and pv.Deleted 
                    
    and ((@IncludeAll 1) or (getdate() between isnull(p.AvailableStartDate'1/1/1900') and isnull(p.AvailableStopDate'1/1/2999')))
                    
    order by do.displayorderp.Namepv.DisplayOrderpv.Name 
                    END 
                    
    ELSE BEGIN 
                    INSERT 
    @productfilter (productiddisplayorderVariantIDVariantDisplayOrderProductNameVariantName
                    
    SELECT distinct p.productid, do.displayorderpv.VariantIDpv.DisplayOrderp.Namepv.Name 
                    FROM 
                    product p with 
    (nolock
                    
    join #displayorder do on p.ProductID = do.ProductID 
                    
    join ProductVariant pv with (NOLOCKon p.ProductID pv.ProductID and pv.IsDefault >= @ViewType 
                    left join productcategory pc with 
    (nolockon p.ProductID pc.ProductID 
                    left join productsection ps with 
    (nolockon p.ProductID ps.ProductID 
                    left join ProductManufacturer pm with 
    (nolockon p.ProductID pm.ProductID 
                    left join ProductDistributor pd with 
    (nolockon p.ProductID pd.ProductID 
                    left join ProductGenre px with 
    (nolockon p.ProductID px.ProductID 
                    left join ProductVector px2 with 
    (nolockon p.ProductID px2.ProductID 
                    left join ProductLocaleSetting pl with 
    (nolockon p.ProductID pl.ProductID 
                    left join ProductCustomerLevel pcl with 
    (nolockon p.ProductID pcl.ProductID 
                    left join ProductAffiliate pa with 
    (nolockon p.ProductID pa.ProductID 
                    WHERE 
                    
    (pc.categoryid = @categoryID or @categoryID is null or @categorycount 0
                    and (
    ps.sectionid = @sectionID or @sectionID is null or @sectioncount 0
                    and (
    pl.LocaleSettingID = @localeID or @localeID is null or @localecount 0
                    and (
    pa.AffiliateID = @affiliateID or @affiliateID is null or @affiliatecount or @FilterProductsByAffiliate 0
                    and (
    pm.manufacturerid = @manufacturerID or @manufacturerID is null or @manufacturercount 0
                    and (
    pd.DistributorID = @distributorID or @distributorID is null or @distributorcount 0
                    and (
    px.GenreID = @genreID or @genreID is null or @genrecount 0
                    and (
    px2.VectorID = @vectorID or @vectorID is null or @vectorcount 0
                    and 
    p.ProductTypeID coalesce(@ProductTypeIDp.ProductTypeID
                    and (case 
                    
    when @FilterProductsByCustomerLevel 0 then 1 
                    when 
    @CustomerLevelFilteringIsAscending and pcl.CustomerLevelID <= @CustomerLevelID or pcl.CustomerLevelID is null then 1 
                    when 
    @CustomerLevelID=and pcl.CustomerLevelID is null then 1 
                    when 
    @CustomerLevelID is null or @custlevelcount 0 then 1 
                    when pcl
    .CustomerLevelID = @CustomerLevelID or pcl.CustomerLevelID is null then 1 
                    
    else 
                    end 

                    

                    and case 
    when isnull(pv.saleprice,0) = 0 then 0 else 1 end >= @OnSaleOnly 
                    
    and p.published >= @publishedonly 
                    
    and pv.published >= @publishedonly 
                    
    and isnull(p.IsAPack0) <= 1-@ExcludePacks 
                    
    and isnull(p.IsAKit0) <= 1-@ExcludeKits 
                    
    and p.IsSystem <= 1-@ExcludeSysProds 
                    
    and p.Deleted 
                    
    and pv.Deleted 
                    
    and ((@IncludeAll 1) or (getdate() between isnull(p.AvailableStartDate'1/1/1900') and isnull(p.AvailableStopDate'1/1/2999')))
                    
    order by do.displayorderp.Namepv.DisplayOrderpv.Name 
                    END 
                    SET 
    @rcount = @@rowcount 
                    
    IF @StatsFirst 
                    SELECT cast
    (ceiling(@rcount*1.0/@pagesize) as intpages, @rcount ProductCount 
                    SELECT 
                    p
    .ProductID
                    
    p.Name
                    
    pv.VariantID
                    
    pv.Name AS VariantName
                    
    p.ProductGUID
                    
    p.Summary
                    
    p.Description
                    
    p.SEKeywords
                    
    p.SEDescription
                    
    p.SpecTitle
                    
    p.MiscText
                    
    p.SwatchImageMap
                    
    p.IsFeaturedTeaser
                    
    p.FroogleDescription
                    
    p.SETitle
                    
    p.SENoScript
                    
    p.SEAltText
                    
    p.SizeOptionPrompt
                    
    p.ColorOptionPrompt
                    
    p.TextOptionPrompt
                    
    p.ProductTypeID
                    
    p.TaxClassID
                    
    p.SKU
                    
    p.ManufacturerPartNumber
                    
    p.SalesPromptID
                    
    p.SpecCall
                    
    p.SpecsInline
                    
    p.IsFeatured
                    
    p.XmlPackage
                    
    p.ColWidth
                    
    p.Published
                    
    p.RequiresRegistration
                    
    p.Looks
                    
    p.Notes
                    
    p.QuantityDiscountID
                    
    p.RelatedProducts
                    
    p.UpsellProducts
                    
    p.UpsellProductDiscountPercentage
                    
    p.RelatedDocuments
                    
    p.TrackInventoryBySizeAndColor
                    
    p.TrackInventoryBySize
                    
    p.TrackInventoryByColor
                    
    p.IsAKit
                    
    p.ShowInProductBrowser
                    
    p.IsAPack
                    
    p.PackSize
                    
    p.ShowBuyButton
                    
    p.RequiresProducts
                    
    p.HidePriceUntilCart
                    
    p.IsCalltoOrder
                    
    p.ExcludeFromPriceFeeds
                    
    p.RequiresTextOption
                    
    p.TextOptionMaxLength
                    
    p.SEName
                    
    p.Deleted
                    
    p.CreatedOn
                    
    p.ImageFileNameOverride
                    
    pv.VariantGUID
                    
    pv.Description AS VariantDescription
                    
    pv.SEKeywords AS VariantSEKeywords
                    
    pv.SEDescription AS VariantSEDescription
                    
    pv.Colors
                    
    pv.ColorSKUModifiers
                    
    pv.Sizes
                    
    pv.SizeSKUModifiers
                    
    pv.FroogleDescription AS VariantFroogleDescription
                    
    pv.SKUSuffix
                    
    pv.ManufacturerPartNumber AS VariantManufacturerPartNumber
                    
    pv.Price
                    
    pv.CustomerEntersPrice
                    
    pv.CustomerEntersPricePrompt
                    
    isnull(pv.SalePrice0SalePrice
                    
    cast(isnull(pv.Weight,0) as decimal(10,1)) Weight
                    
    pv.MSRP
                    
    pv.Cost
                    
    isnull(pv.Points,0Points
                    
    pv.Dimensions
                    case 
    p.TrackInventoryBySizeAndColor when 1 then isnull(i.quan0) else pv.inventory end Inventory
                    
    pv.DisplayOrder as VariantDisplayOrder
                    
    pv.Notes AS VariantNotes
                    
    pv.IsTaxable
                    
    pv.IsShipSeparately
                    
    pv.IsDownload
                    
    pv.DownloadLocation
                    
    pv.Published AS VariantPublished
                    
    pv.IsSecureAttachment
                    
    pv.IsRecurring
                    
    pv.RecurringInterval
                    
    pv.RecurringIntervalType
                    
    pv.SubscriptionInterval
                    
    pv.SEName AS VariantSEName
                    
    pv.RestrictedQuantities
                    
    pv.MinimumQuantity
                    
    pv.Deleted AS VariantDeleted
                    
    pv.CreatedOn AS VariantCreatedOn
                    
    d.Name AS DistributorName
                    
    d.DistributorID
                    
    d.SEName AS DistributorSEName
                    
    m.ManufacturerID
                    
    m.Name AS ManufacturerName
                    
    m.SEName AS ManufacturerSEName
                    
    s.Name AS SalesPromptName
                    case 
    when pcl.productid is null then 0 else isnull(ep.Price0end ExtendedPrice 
                    FROM Product p with 
    (NOLOCK
                    
    left join ProductVariant pv with (NOLOCKon p.ProductID pv.ProductID and pv.IsDefault >= @ViewType 
                    join 
    @productfilter pf on pv.ProductID pf.ProductID and pv.VariantID pf.VariantID 
                    left join SalesPrompt s with 
    (NOLOCKon p.SalesPromptID s.SalesPromptID 
                    left join ProductManufacturer pm with 
    (NOLOCKon p.ProductID pm.ProductID 
                    left join Manufacturer m with 
    (NOLOCKon pm.ManufacturerID m.ManufacturerID 
                    left join ProductDistributor pd with 
    (NOLOCKon p.ProductID pd.ProductID 
                    left join Distributor d with 
    (NOLOCKon pd.DistributorID d.DistributorID 
                    left join ExtendedPrice ep with 
    (NOLOCKon ep.VariantID pv.VariantID and ep.CustomerLevelID = @CustomerLevelID 
                    left join ProductCustomerLevel pcl with 
    (NOLOCKon p.ProductID pcl.ProductID and pcl.CustomerLevelID = @CustomerLevelID 
                    left join 
    (select VariantIDsum(quanquan from Inventory with (nolockgroup by VariantIDi on pv.VariantID i.VariantID 
                    WHERE pf
    .rownum >= @pagesize*(@pagenum-1)+and pf.rownum <= @pagesize*(@pagenum
                    
    ORDER BY pf.rownum 
                    
    IF @StatsFirst <> 
                    SELECT cast
    (ceiling(@rcount*1.0/@pagesize) as intpages, @rcount ProductCount 
                    END 
    what all the changes i have to do
    rbgx
    AspDotNetStorefront ML
    v8.0.1.4

  17. #17
    mmcgeachy is offline Senior Member
    Join Date
    Sep 2008
    Posts
    174

    Default

    Well here is the modified stored procedure I would suggest trying then. Just to note I'm basing this off version 8.0.1.1 so others will need to tweak things for later versions. For that reason it also took me a bit more time to because I wanted double check things and had some other things holding me up.

    C#/VB.NET Code:
    ALTER proc [dbo].[aspdnsf_GetProducts
                    @
    categoryID int null
                    @
    sectionID int null
                    @
    manufacturerID int null
                    @
    distributorID int null
                    @
    genreID int null
                    @
    vectorID int null
                    @
    localeID int null
                    @
    CustomerLevelID int null
                    @
    affiliateID int null
                    @
    ProductTypeID int null
                    @
    ViewType bit 1
                    @
    sortEntity int 0
                    @
    pagenum int 1
                    @
    pagesize int null
                    @
    StatsFirst tinyint 1
                    @
    searchstr nvarchar(1000) = null
                    @
    extSearch tinyint 0
                    @
    publishedonly tinyint 0
                    @
    ExcludePacks tinyint 0
                    @
    ExcludeKits tinyint 0
                    @
    ExcludeSysProds tinyint 0
                    @
    InventoryFilter int 0
                    @
    sortEntityName varchar(20) = ''
                    @
    localeName varchar(20) = ''
                    @
    OnSaleOnly tinyint 0
                    @
    IncludeAll bit 
                    
    AS 
                    
    BEGIN 
                    SET NOCOUNT ON 
                    
    DECLARE @rcount int 
                    
    DECLARE @productfilter table (rownum int not null identity primary keyproductid int not nulldisplayorder int not nullVariantID int not nullVariantDisplayOrder int not nullProductName nvarchar(400nullVariantName nvarchar(400null, [rankint null
                    DECLARE @
    FilterProductsByAffiliate tinyint, @FilterProductsByCustomerLevel tinyint, @HideProductsWithLessThanThisInventoryLevel int 
                    CREATE TABLE 
    #displayorder (productid int not null primary key, displayorder int not null) 
                    
    CREATE TABLE #inventoryfilter (productid int not null, variantid int not null, InvQty int not null) 
                    
    CREATE CLUSTERED INDEX tmp_inventoryfilter ON #inventoryfilter (productid, variantid) 
                    
    DECLARE @custlevelcount int, @sectioncount int, @localecount int, @affiliatecount int, @categorycount int, @CustomerLevelFilteringIsAscending bit, @distributorcount int, @genrecount int, @vectorcount int, @manufacturercount int 
                    SELECT 
    @FilterProductsByAffiliate = case ConfigValue when 'true' then 1 else 0 end FROM dbo.AppConfig WHERE [Name] = 'FilterProductsByAffiliate' 
                    
    SELECT @FilterProductsByCustomerLevel = case ConfigValue when 'true' then 1 else 0 end FROM dbo.AppConfig WHERE [Name] = 'FilterProductsByCustomerLevel' 
                    
    SELECT @HideProductsWithLessThanThisInventoryLevel convert(intConfigValueFROM dbo.AppConfig WHERE [Name] = 'HideProductsWithLessThanThisInventoryLevel' and isnumeric(ConfigValue) = 
                    
    IF @InventoryFilter = -
                    SET 
    @InventoryFilter 
                    
    ELSE IF @HideProductsWithLessThanThisInventoryLevel > @InventoryFilter 
                    SET 
    @InventoryFilter = @HideProductsWithLessThanThisInventoryLevel 
                    SET 
    @categoryID nullif(@categoryID0
                    
    SET @sectionID nullif(@sectionID0
                    
    SET @manufacturerID nullif(@manufacturerID0
                    
    SET @distributorID nullif(@distributorID0
                    
    SET @genreID          nullif(@genreID0
                    
    SET @vectorID nullif(@vectorID0
                    
    SET @affiliateID nullif(@affiliateID0
                    
    SET @ProductTypeID nullif(@ProductTypeID0
                    
    SET @CustomerLevelFilteringIsAscending 
                    SELECT 
    @CustomerLevelFilteringIsAscending = case configvalue when 'true' then 1 else 0 end 
                    FROM appConfig 
                    WHERE name like 
    'CustomerLevelFilteringIsAscending ' 
                    
    IF @localeID is null and ltrim(rtrim(@localeName)) <> '' 
                    
    SELECT @localeID LocaleSettingID FROM LocaleSetting WHERE Name ltrim(rtrim(@localeName)) 
                    
    select @categorycount si.rows from sysobjects so with (nolockjoin sysindexes si with (nolockon so.id si.id where so.id object_id('productcategory') and si.indid and type 'u' 
                    
    select @sectioncount si.rows from sysobjects so with (nolockjoin sysindexes si with (nolockon so.id si.id where so.id object_id('productsection') and si.indid and type 'u' 
                    
    select @localecount si.rows from sysobjects so with (nolockjoin sysindexes si with (nolockon so.id si.id where so.id object_id('ProductLocaleSetting') and si.indid and type 'u' 
                    
    select @custlevelcount si.rows from sysobjects so with (nolockjoin sysindexes si with (nolockon so.id si.id where so.id object_id('ProductCustomerLevel') and si.indid and type 'u' 
                    
    select @affiliatecount si.rows from sysobjects so with (nolockjoin sysindexes si with (nolockon so.id si.id where so.id object_id('ProductAffiliate') and si.indid and type 'u' 
                    
    select @distributorcount si.rows from sysobjects so with (nolockjoin sysindexes si with (nolockon so.id si.id where so.id object_id('ProductDistributor') and si.indid and type 'u' 
                    
    select @genrecount si.rows from sysobjects so with (nolockjoin sysindexes si with (nolockon so.id si.id where so.id object_id('ProductGenre') and si.indid and type 'u' 
                    
    select @vectorcount si.rows from sysobjects so with (nolockjoin sysindexes si with (nolockon so.id si.id where so.id object_id('ProductVector') and si.indid and type 'u' 
                    
    select @manufacturercount si.rows from sysobjects so with (nolockjoin sysindexes si with (nolockon so.id si.id where so.id object_id('ProductManufacturer') and si.indid and type 'u' 
                    
    IF @pagesize is null or @pagesize 0 BEGIN 
                    
    IF @categoryID is not null 
                    SELECT 
    @pagesize PageSize FROM dbo.Category WHERE categoryID = @categoryID 
                    
    ELSE IF @sectionID is not null 
                    SELECT 
    @pagesize PageSize FROM dbo.Section WHERE sectionID = @sectionID 
                    
    ELSE IF @manufacturerID is not null 
                    SELECT 
    @pagesize PageSize FROM dbo.Manufacturer WHERE manufacturerID = @manufacturerID 
                    
    ELSE IF @distributorID is not null 
                    SELECT 
    @pagesize PageSize FROM dbo.Distributor WHERE distributorID = @distributorID 
                    
    ELSE IF @genreID is not null 
                    SELECT 
    @pagesize PageSize FROM dbo.Genre WHERE genreID = @genreID 
                    
    ELSE IF @vectorID is not null 
                    SELECT 
    @pagesize PageSize FROM dbo.Vector WHERE vectorID = @vectorID 
                    
    ELSE 
                    
    SELECT @pagesize convert(intConfigValueFROM dbo.AppConfig WHERE [Name] = 'Default_CategoryPageSize' 
                    
    END 
                    
    IF @pagesize is null or @pagesize 
                    SET 
    @pagesize 20 
                    
    IF @sortEntity or @sortEntityName 'category' BEGIN 
                    INSERT 
    #displayorder select productid, displayorder from ProductCategory where categoryID = @categoryID 
                    
    END 
                    
    ELSE IF @sortEntity or @sortEntityName 'section' BEGIN 
                    INSERT 
    #displayorder select productid, displayorder from ProductSection where sectionId = @sectionID 
                    
    END 
                    
    ELSE IF @sortEntity or @sortEntityName 'manufacturer' BEGIN 
                    INSERT 
    #displayorder select productid, displayorder from ProductManufacturer where ManufacturerID = @manufacturerID 
                    
    END 
                    
    ELSE IF @sortEntity or @sortEntityName 'distributor' BEGIN 
                    INSERT 
    #displayorder select productid, displayorder from ProductDistributor where DistributorID = @distributorID 
                    
    END 
                    
    ELSE IF @sortEntity or @sortEntityName 'genre' BEGIN 
                    INSERT 
    #displayorder select productid, displayorder from ProductGenre where GenreID = @genreID 
                    
    END 
                    
    ELSE IF @sortEntity or @sortEntityName 'vector' BEGIN 
                    INSERT 
    #displayorder select productid, displayorder from ProductVector where VectorID = @vectorID 
                    
    END 
                    
    ELSE BEGIN 
                    INSERT 
    #displayorder select productid, 1 from Product ORDER BY Name 
                    
    END 

                    

                    
                    
    IF @InventoryFilter 0 BEGIN 
                    
    IF @ViewType 1 BEGIN 
                    INSERT 
    #inventoryfilter 
                    
    SELECT p.productidpv.VariantIDsum(case p.TrackInventoryBySizeAndColor when 1 then isnull(i.quan0) else pv.inventory end invqty 
                    FROM product p with 
    (NOLOCKjoin #displayorder d on p.ProductID = d.ProductID 
                    
    join ProductVariant pv with (NOLOCKon p.ProductID pv.ProductID and pv.IsDefault 
                    left join Inventory i with 
    (NOLOCKon pv.VariantID i.VariantID 
                    GROUP BY p
    .productidpv.VariantID 
                    HAVING sum
    (case p.TrackInventoryBySizeAndColor when 1 then isnull(i.quan0) else pv.inventory end ) >= @InventoryFilter 
                    END 
                    
    ELSE 
                    
    INSERT #inventoryfilter 
                    
    SELECT p.productidpv.VariantIDsum(case p.TrackInventoryBySizeAndColor when 1 then isnull(i.quan0) else pv.inventory end invqty 
                    FROM product p with 
    (NOLOCKjoin #displayorder d on p.ProductID = d.ProductID 
                    
    join ProductVariant pv with (NOLOCKon p.ProductID pv.ProductID 
                    left join Inventory i with 
    (NOLOCKon pv.VariantID i.VariantID 
                    GROUP BY p
    .productidpv.VariantID 
                    HAVING sum
    (case p.TrackInventoryBySizeAndColor when 1 then isnull(i.quan0) else pv.inventory end ) >= @InventoryFilter 
                    INSERT 
    @productfilter (productiddisplayorderVariantIDVariantDisplayOrderProductNameVariantName, [rank]) 
                    
    SELECT distinct p.productid, do.displayorderpv.VariantIDpv.DisplayOrderp.Namepv.Name ,ft.rank
                    FROM 
                    product p with 
    (nolock
                    
    join #displayorder do on p.ProductID = do.ProductID
                    
    inner join FREETEXTTABLE (product,(*),@searchstr) as ft on p.ProductGUID=ft.[key]                 
                    
    left join ProductVariant pv with (NOLOCKON p.ProductID pv.ProductID and pv.IsDefault >= @ViewType 
                    left join productcategory pc with 
    (nolockon p.ProductID pc.ProductID 
                    left join productsection ps with 
    (nolockon p.ProductID ps.ProductID 
                    left join ProductManufacturer pm with 
    (nolockon p.ProductID pm.ProductID 
                    left join ProductDistributor pd with 
    (nolockon p.ProductID pd.ProductID 
                    left join ProductGenre px with 
    (nolockon p.ProductID px.ProductID 
                    left join ProductVector px2 with 
    (nolockon p.ProductID px2.ProductID 
                    left join ProductLocaleSetting pl with 
    (nolockon p.ProductID pl.ProductID 
                    left join ProductCustomerLevel pcl with 
    (nolockon p.ProductID pcl.ProductID 
                    left join ProductAffiliate pa with 
    (nolockon p.ProductID pa.ProductID 
                    join 
    #inventoryfilter i on pv.VariantID = i.VariantID 
                    
    WHERE 
                    
    (pc.categoryid = @categoryID or @categoryID is null or @categorycount 0
                    and (
    ps.sectionid = @sectionID or @sectionID is null or @sectioncount 0
                    and (
    pl.LocaleSettingID = @localeID or @localeID is null or @localecount 0
                    and (
    pa.AffiliateID = @affiliateID or @affiliateID is null or @affiliatecount or @FilterProductsByAffiliate 0
                    and (
    pm.manufacturerid = @manufacturerID or @manufacturerID is null or @manufacturercount 0
                    and (
    pd.DistributorID = @distributorID or @distributorID is null or @distributorcount 0
                    and (
    px.GenreID = @genreID or @genreID is null or @genrecount 0
                    and (
    px2.VectorID = @vectorID or @vectorID is null or @vectorcount 0
                    and 
    p.ProductTypeID coalesce(@ProductTypeIDp.ProductTypeID
                    and (case 
                    
    when @FilterProductsByCustomerLevel 0 then 1 
                    when 
    @CustomerLevelFilteringIsAscending and pcl.CustomerLevelID <= @CustomerLevelID or pcl.CustomerLevelID is null then 1 
                    when 
    @CustomerLevelID=and pcl.CustomerLevelID is null then 1 
                    when 
    @CustomerLevelID is null or @custlevelcount 0 then 1 
                    when pcl
    .CustomerLevelID = @CustomerLevelID or pcl.CustomerLevelID is null then 1 
                    
    else 
                    end 

                    

                    and case 
    when isnull(pv.saleprice,0) = 0 then 0 else 1 end >= @OnSaleOnly 
                    
    and p.published >= @publishedonly 
                    
    and pv.published >= @publishedonly 
                    
    and isnull(p.IsAPack0) <= 1-@ExcludePacks 
                    
    and isnull(p.IsAKit0) <= 1-@ExcludeKits 
                    
    and p.IsSystem <= 1-@ExcludeSysProds 
                    
    and p.Deleted 
                    
    and pv.Deleted 
                    
    and ((@IncludeAll 1) or (getdate() between isnull(p.AvailableStartDate'1/1/1900') and isnull(p.AvailableStopDate'1/1/2999')))
                    
    order by do.displayorderp.Namepv.DisplayOrderpv.Name 
                    END 
                    
    ELSE BEGIN 
                    INSERT 
    @productfilter (productiddisplayorderVariantIDVariantDisplayOrderProductNameVariantName, [rank]) 
                    
    SELECT distinct p.productid, do.displayorderpv.VariantIDpv.DisplayOrderp.Namepv.Name ,ft.rank
                    FROM 
                    product p with 
    (nolock
                    
    join #displayorder do on p.ProductID = do.ProductID 
                    
    inner join FREETEXTTABLE (product,(*),@searchstr) as ft on p.ProductGUID=ft.[key
                    
    join ProductVariant pv with (NOLOCKon p.ProductID pv.ProductID and pv.IsDefault >= @ViewType 
                    left join productcategory pc with 
    (nolockon p.ProductID pc.ProductID 
                    left join productsection ps with 
    (nolockon p.ProductID ps.ProductID 
                    left join ProductManufacturer pm with 
    (nolockon p.ProductID pm.ProductID 
                    left join ProductDistributor pd with 
    (nolockon p.ProductID pd.ProductID 
                    left join ProductGenre px with 
    (nolockon p.ProductID px.ProductID 
                    left join ProductVector px2 with 
    (nolockon p.ProductID px2.ProductID 
                    left join ProductLocaleSetting pl with 
    (nolockon p.ProductID pl.ProductID 
                    left join ProductCustomerLevel pcl with 
    (nolockon p.ProductID pcl.ProductID 
                    left join ProductAffiliate pa with 
    (nolockon p.ProductID pa.ProductID 
                    WHERE 
                    
    (pc.categoryid = @categoryID or @categoryID is null or @categorycount 0
                    and (
    ps.sectionid = @sectionID or @sectionID is null or @sectioncount 0
                    and (
    pl.LocaleSettingID = @localeID or @localeID is null or @localecount 0
                    and (
    pa.AffiliateID = @affiliateID or @affiliateID is null or @affiliatecount or @FilterProductsByAffiliate 0
                    and (
    pm.manufacturerid = @manufacturerID or @manufacturerID is null or @manufacturercount 0
                    and (
    pd.DistributorID = @distributorID or @distributorID is null or @distributorcount 0
                    and (
    px.GenreID = @genreID or @genreID is null or @genrecount 0
                    and (
    px2.VectorID = @vectorID or @vectorID is null or @vectorcount 0
                    and 
    p.ProductTypeID coalesce(@ProductTypeIDp.ProductTypeID
                    and (case 
                    
    when @FilterProductsByCustomerLevel 0 then 1 
                    when 
    @CustomerLevelFilteringIsAscending and pcl.CustomerLevelID <= @CustomerLevelID or pcl.CustomerLevelID is null then 1 
                    when 
    @CustomerLevelID=and pcl.CustomerLevelID is null then 1 
                    when 
    @CustomerLevelID is null or @custlevelcount 0 then 1 
                    when pcl
    .CustomerLevelID = @CustomerLevelID or pcl.CustomerLevelID is null then 1 
                    
    else 
                    end 

                    

                    and case 
    when isnull(pv.saleprice,0) = 0 then 0 else 1 end >= @OnSaleOnly 
                    
    and p.published >= @publishedonly 
                    
    and pv.published >= @publishedonly 
                    
    and isnull(p.IsAPack0) <= 1-@ExcludePacks 
                    
    and isnull(p.IsAKit0) <= 1-@ExcludeKits 
                    
    and p.IsSystem <= 1-@ExcludeSysProds 
                    
    and p.Deleted 
                    
    and pv.Deleted 
                    
    and ((@IncludeAll 1) or (getdate() between isnull(p.AvailableStartDate'1/1/1900') and isnull(p.AvailableStopDate'1/1/2999')))
                    
    order by ft.rank desc,do.displayorderp.Namepv.DisplayOrderpv.Name 
                    END 
                    
                    SET 
    @rcount = @@rowcount 
                    
    IF @StatsFirst 
                    SELECT cast
    (ceiling(@rcount*1.0/@pagesize) as intpages, @rcount ProductCount 
                    
                    SELECT 
                    p
    .ProductID
                    
    p.Name
                    
    pv.VariantID
                    
    pv.Name AS VariantName
                    
    p.ProductGUID
                    
    p.Summary
                    
    p.Description
                    
    p.SEKeywords
                    
    p.SEDescription
                    
    p.SpecTitle
                    
    p.MiscText
                    
    p.SwatchImageMap
                    
    p.IsFeaturedTeaser
                    
    p.FroogleDescription
                    
    p.SETitle
                    
    p.SENoScript
                    
    p.SEAltText
                    
    p.SizeOptionPrompt
                    
    p.ColorOptionPrompt
                    
    p.TextOptionPrompt
                    
    p.ProductTypeID
                    
    p.TaxClassID
                    
    p.SKU
                    
    p.ManufacturerPartNumber
                    
    p.SalesPromptID
                    
    p.SpecCall
                    
    p.SpecsInline
                    
    p.IsFeatured
                    
    p.XmlPackage
                    
    p.ColWidth
                    
    p.Published
                    
    p.RequiresRegistration
                    
    p.Looks
                    
    p.Notes
                    
    p.QuantityDiscountID
                    
    p.RelatedProducts
                    
    p.UpsellProducts
                    
    p.UpsellProductDiscountPercentage
                    
    p.RelatedDocuments
                    
    p.TrackInventoryBySizeAndColor
                    
    p.TrackInventoryBySize
                    
    p.TrackInventoryByColor
                    
    p.IsAKit
                    
    p.ShowInProductBrowser
                    
    p.IsAPack
                    
    p.PackSize
                    
    p.ShowBuyButton
                    
    p.RequiresProducts
                    
    p.HidePriceUntilCart
                    
    p.IsCalltoOrder
                    
    p.ExcludeFromPriceFeeds
                    
    p.RequiresTextOption
                    
    p.TextOptionMaxLength
                    
    p.SEName
                    
    p.Deleted
                    
    p.CreatedOn
                    
    p.ImageFileNameOverride
                    
    pv.VariantGUID
                    
    pv.Description AS VariantDescription
                    
    pv.SEKeywords AS VariantSEKeywords
                    
    pv.SEDescription AS VariantSEDescription
                    
    pv.Colors
                    
    pv.ColorSKUModifiers
                    
    pv.Sizes
                    
    pv.SizeSKUModifiers
                    
    pv.FroogleDescription AS VariantFroogleDescription
                    
    pv.SKUSuffix
                    
    pv.ManufacturerPartNumber AS VariantManufacturerPartNumber
                    
    pv.Price
                    
    pv.CustomerEntersPrice
                    
    pv.CustomerEntersPricePrompt
                    
    isnull(pv.SalePrice0SalePrice
                    
    cast(isnull(pv.Weight,0) as decimal(10,1)) Weight
                    
    pv.MSRP
                    
    pv.Cost
                    
    isnull(pv.Points,0Points
                    
    pv.Dimensions
                    case 
    p.TrackInventoryBySizeAndColor when 1 then isnull(i.quan0) else pv.inventory end Inventory
                    
    pv.DisplayOrder as VariantDisplayOrder
                    
    pv.Notes AS VariantNotes
                    
    pv.IsTaxable
                    
    pv.IsShipSeparately
                    
    pv.IsDownload
                    
    pv.DownloadLocation
                    
    pv.Published AS VariantPublished
                    
    pv.IsSecureAttachment
                    
    pv.IsRecurring
                    
    pv.RecurringInterval
                    
    pv.RecurringIntervalType
                    
    pv.SubscriptionInterval
                    
    pv.SEName AS VariantSEName
                    
    pv.RestrictedQuantities
                    
    pv.MinimumQuantity
                    
    pv.Deleted AS VariantDeleted
                    
    pv.CreatedOn AS VariantCreatedOn
                    
    d.Name AS DistributorName
                    
    d.DistributorID
                    
    d.SEName AS DistributorSEName
                    
    m.ManufacturerID
                    
    m.Name AS ManufacturerName
                    
    m.SEName AS ManufacturerSEName
                    
    s.Name AS SalesPromptName
                    case 
    when pcl.productid is null then 0 else isnull(ep.Price0end ExtendedPrice 
                    FROM Product p with 
    (NOLOCK
                    
    left join ProductVariant pv with (NOLOCKon p.ProductID pv.ProductID and pv.IsDefault >= @ViewType 
                    join 
    @productfilter pf on pv.ProductID pf.ProductID and pv.VariantID pf.VariantID 
                    left join SalesPrompt s with 
    (NOLOCKon p.SalesPromptID s.SalesPromptID 
                    left join ProductManufacturer pm with 
    (NOLOCKon p.ProductID pm.ProductID 
                    left join Manufacturer m with 
    (NOLOCKon pm.ManufacturerID m.ManufacturerID 
                    left join ProductDistributor pd with 
    (NOLOCKon p.ProductID pd.ProductID 
                    left join Distributor d with 
    (NOLOCKon pd.DistributorID d.DistributorID 
                    left join ExtendedPrice ep with 
    (NOLOCKon ep.VariantID pv.VariantID and ep.CustomerLevelID = @CustomerLevelID 
                    left join ProductCustomerLevel pcl with 
    (NOLOCKon p.ProductID pcl.ProductID and pcl.CustomerLevelID = @CustomerLevelID 
                    left join 
    (select VariantIDsum(quanquan from Inventory with (nolockgroup by VariantIDi on pv.VariantID i.VariantID 
                    WHERE pf
    .rownum >= @pagesize*(@pagenum-1)+and pf.rownum <= @pagesize*(@pagenum
                    
    ORDER BY pf.rownum 
                    
    IF @StatsFirst <> 
                    SELECT cast
    (ceiling(@rcount*1.0/@pagesize) as intpages, @rcount ProductCount 
                    END 
    I would also suggest creating a copy of your current aspdnsf_GetProducts so you can compare the results. You can use this sql statment to see results of aspdnsf_GetProducts in sql management studio.

    C#/VB.NET Code:
    declare @locale VarChar
    declare @CustLevelID Int
    declare @AffID Int
    declare @ProdTypeID Int
    declare @SearchTerm nvarchar(1000)

    declare @
    pgnum Int

    set 
    @locale 'en-US'
    set @CustLevelID 0
    set 
    @AffID 0
    set 
    @ProdTypeID null
    set 
    @SearchTerm 'Silver'

    set @pgnum 1


    exec aspdnsf_GetProducts 
                        
    @localeName = @locale,
                        @
    CustomerLevelID = @CustLevelID,
                        @
    affiliateID = @AffID,
                        @
    ProductTypeID = @ProdTypeID
                        @
    ViewType 0,
                        @
    pagenum = @pgnum,
                        @
    pagesize 20,
                        @
    StatsFirst 0,
                        @
    searchstr = @SearchTerm,                    
                        @
    publishedonly 1,
                        @
    ExcludePacks 0,
                        @
    ExcludeKits 0,
                        @
    ExcludeSysProds 
    Please do remember to do testing non live sever 1st. Also do note there are still options that can be done to tweak full text search in other ways. So it should not be taken as a one size fits all type of situation.

    Hope this helps

  18. #18
    harsha.gus is offline Senior Member
    Join Date
    Mar 2009
    Posts
    301

    Exclamation thank you very much

    Thank you very much for taking time and helping me.

    when i update the Procedure,
    search works perfect, But Regular Categories troughs error

    when i click any category it gives error.
    rbgx
    AspDotNetStorefront ML
    v8.0.1.4

  19. #19
    mmcgeachy is offline Senior Member
    Join Date
    Sep 2008
    Posts
    174

    Default

    Try this instead

    C#/VB.NET Code:
    ALTER proc [dbo].[aspdnsf_GetProducts
                    @
    categoryID int null
                    @
    sectionID int null
                    @
    manufacturerID int null
                    @
    distributorID int null
                    @
    genreID int null
                    @
    vectorID int null
                    @
    localeID int null
                    @
    CustomerLevelID int null
                    @
    affiliateID int null
                    @
    ProductTypeID int null
                    @
    ViewType bit 1
                    @
    sortEntity int 0
                    @
    pagenum int 1
                    @
    pagesize int null
                    @
    StatsFirst tinyint 1
                    @
    searchstr nvarchar(1000) = null
                    @
    extSearch tinyint 0
                    @
    publishedonly tinyint 0
                    @
    ExcludePacks tinyint 0
                    @
    ExcludeKits tinyint 0
                    @
    ExcludeSysProds tinyint 0
                    @
    InventoryFilter int 0
                    @
    sortEntityName varchar(20) = ''
                    @
    localeName varchar(20) = ''
                    @
    OnSaleOnly tinyint 0
                    @
    IncludeAll bit 
                    
    AS 
                    
    BEGIN 
                    SET NOCOUNT ON 
                    
    DECLARE @rcount int 
                    
    DECLARE @productfilter table (rownum int not null identity primary keyproductid int not nulldisplayorder int not nullVariantID int not nullVariantDisplayOrder int not nullProductName nvarchar(400nullVariantName nvarchar(400null, [rankint null
                    DECLARE @
    FilterProductsByAffiliate tinyint, @FilterProductsByCustomerLevel tinyint, @HideProductsWithLessThanThisInventoryLevel int 
                    CREATE TABLE 
    #displayorder (productid int not null primary key, displayorder int not null) 
                    
    CREATE TABLE #displayorder2 (productid int not null primary key, displayorder int not null, [rank] int null)
                    
    CREATE TABLE #inventoryfilter (productid int not null, variantid int not null, InvQty int not null) 
                    
    CREATE CLUSTERED INDEX tmp_inventoryfilter ON #inventoryfilter (productid, variantid) 
                    
    DECLARE @custlevelcount int, @sectioncount int, @localecount int, @affiliatecount int, @categorycount int, @CustomerLevelFilteringIsAscending bit, @distributorcount int, @genrecount int, @vectorcount int, @manufacturercount int 
                    SELECT 
    @FilterProductsByAffiliate = case ConfigValue when 'true' then 1 else 0 end FROM dbo.AppConfig WHERE [Name] = 'FilterProductsByAffiliate' 
                    
    SELECT @FilterProductsByCustomerLevel = case ConfigValue when 'true' then 1 else 0 end FROM dbo.AppConfig WHERE [Name] = 'FilterProductsByCustomerLevel' 
                    
    SELECT @HideProductsWithLessThanThisInventoryLevel convert(intConfigValueFROM dbo.AppConfig WHERE [Name] = 'HideProductsWithLessThanThisInventoryLevel' and isnumeric(ConfigValue) = 
                    
    IF @InventoryFilter = -
                    SET 
    @InventoryFilter 
                    
    ELSE IF @HideProductsWithLessThanThisInventoryLevel > @InventoryFilter 
                    SET 
    @InventoryFilter = @HideProductsWithLessThanThisInventoryLevel 
                    SET 
    @categoryID nullif(@categoryID0
                    
    SET @sectionID nullif(@sectionID0
                    
    SET @manufacturerID nullif(@manufacturerID0
                    
    SET @distributorID nullif(@distributorID0
                    
    SET @genreID          nullif(@genreID0
                    
    SET @vectorID nullif(@vectorID0
                    
    SET @affiliateID nullif(@affiliateID0
                    
    SET @ProductTypeID nullif(@ProductTypeID0
                    
    SET @CustomerLevelFilteringIsAscending 
                    SELECT 
    @CustomerLevelFilteringIsAscending = case configvalue when 'true' then 1 else 0 end 
                    FROM appConfig 
                    WHERE name like 
    'CustomerLevelFilteringIsAscending ' 
                    
    IF @localeID is null and ltrim(rtrim(@localeName)) <> '' 
                    
    SELECT @localeID LocaleSettingID FROM LocaleSetting WHERE Name ltrim(rtrim(@localeName)) 
                    
    select @categorycount si.rows from sysobjects so with (nolockjoin sysindexes si with (nolockon so.id si.id where so.id object_id('productcategory') and si.indid and type 'u' 
                    
    select @sectioncount si.rows from sysobjects so with (nolockjoin sysindexes si with (nolockon so.id si.id where so.id object_id('productsection') and si.indid and type 'u' 
                    
    select @localecount si.rows from sysobjects so with (nolockjoin sysindexes si with (nolockon so.id si.id where so.id object_id('ProductLocaleSetting') and si.indid and type 'u' 
                    
    select @custlevelcount si.rows from sysobjects so with (nolockjoin sysindexes si with (nolockon so.id si.id where so.id object_id('ProductCustomerLevel') and si.indid and type 'u' 
                    
    select @affiliatecount si.rows from sysobjects so with (nolockjoin sysindexes si with (nolockon so.id si.id where so.id object_id('ProductAffiliate') and si.indid and type 'u' 
                    
    select @distributorcount si.rows from sysobjects so with (nolockjoin sysindexes si with (nolockon so.id si.id where so.id object_id('ProductDistributor') and si.indid and type 'u' 
                    
    select @genrecount si.rows from sysobjects so with (nolockjoin sysindexes si with (nolockon so.id si.id where so.id object_id('ProductGenre') and si.indid and type 'u' 
                    
    select @vectorcount si.rows from sysobjects so with (nolockjoin sysindexes si with (nolockon so.id si.id where so.id object_id('ProductVector') and si.indid and type 'u' 
                    
    select @manufacturercount si.rows from sysobjects so with (nolockjoin sysindexes si with (nolockon so.id si.id where so.id object_id('ProductManufacturer') and si.indid and type 'u' 
                    
    IF @pagesize is null or @pagesize 0 BEGIN 
                    
    IF @categoryID is not null 
                    SELECT 
    @pagesize PageSize FROM dbo.Category WHERE categoryID = @categoryID 
                    
    ELSE IF @sectionID is not null 
                    SELECT 
    @pagesize PageSize FROM dbo.Section WHERE sectionID = @sectionID 
                    
    ELSE IF @manufacturerID is not null 
                    SELECT 
    @pagesize PageSize FROM dbo.Manufacturer WHERE manufacturerID = @manufacturerID 
                    
    ELSE IF @distributorID is not null 
                    SELECT 
    @pagesize PageSize FROM dbo.Distributor WHERE distributorID = @distributorID 
                    
    ELSE IF @genreID is not null 
                    SELECT 
    @pagesize PageSize FROM dbo.Genre WHERE genreID = @genreID 
                    
    ELSE IF @vectorID is not null 
                    SELECT 
    @pagesize PageSize FROM dbo.Vector WHERE vectorID = @vectorID 
                    
    ELSE 
                    
    SELECT @pagesize convert(intConfigValueFROM dbo.AppConfig WHERE [Name] = 'Default_CategoryPageSize' 
                    
    END 
                    
    IF @pagesize is null or @pagesize 
                    SET 
    @pagesize 20 
                    
    IF @sortEntity or @sortEntityName 'category' BEGIN 
                    INSERT 
    #displayorder select productid, displayorder from ProductCategory where categoryID = @categoryID 
                    
    END 
                    
    ELSE IF @sortEntity or @sortEntityName 'section' BEGIN 
                    INSERT 
    #displayorder select productid, displayorder from ProductSection where sectionId = @sectionID 
                    
    END 
                    
    ELSE IF @sortEntity or @sortEntityName 'manufacturer' BEGIN 
                    INSERT 
    #displayorder select productid, displayorder from ProductManufacturer where ManufacturerID = @manufacturerID 
                    
    END 
                    
    ELSE IF @sortEntity or @sortEntityName 'distributor' BEGIN 
                    INSERT 
    #displayorder select productid, displayorder from ProductDistributor where DistributorID = @distributorID 
                    
    END 
                    
    ELSE IF @sortEntity or @sortEntityName 'genre' BEGIN 
                    INSERT 
    #displayorder select productid, displayorder from ProductGenre where GenreID = @genreID 
                    
    END 
                    
    ELSE IF @sortEntity or @sortEntityName 'vector' BEGIN 
                    INSERT 
    #displayorder select productid, displayorder from ProductVector where VectorID = @vectorID 
                    
    END 
                    
    ELSE BEGIN 
                    INSERT 
    #displayorder select productid, 1 from Product ORDER BY Name 
                    
    END 
                    
                    SET 
    @searchstr Replace(@searchstr,'''','''''')            
                    
    SET @searchstr Replace(@searchstr,'+',' ')
                    
    SET @searchstr Replace(@searchstr,'"','')

                    IF 
    rtrim(isnull(@searchstr'')) <> '' BEGIN 
                    select 
    @searchstr dbo.GetValidSearchString(@searchstr)
                    
    INSERT #displayorder2 select p.productid, do.displayorder, ft.rank
                    
    FROM product p with (nolock)
                    
    join #displayorder do on p.ProductID = do.ProductID 
                    
    inner join FREETEXTTABLE (product,(*),@searchstr) as ft on p.ProductGUID=ft.[key
                    
    END
                    
    ELSE BEGIN 
                    INSERT 
    #displayorder2 select productid, displayorder, null from #displayorder
                    
    END

                    
    IF @InventoryFilter 0 BEGIN 
                    
    IF @ViewType 1 BEGIN 
                    INSERT 
    #inventoryfilter 
                    
    SELECT p.productidpv.VariantIDsum(case p.TrackInventoryBySizeAndColor when 1 then isnull(i.quan0) else pv.inventory end invqty 
                    FROM product p with 
    (NOLOCKjoin #displayorder d on p.ProductID = d.ProductID 
                    
    join ProductVariant pv with (NOLOCKon p.ProductID pv.ProductID and pv.IsDefault 
                    left join Inventory i with 
    (NOLOCKon pv.VariantID i.VariantID 
                    GROUP BY p
    .productidpv.VariantID 
                    HAVING sum
    (case p.TrackInventoryBySizeAndColor when 1 then isnull(i.quan0) else pv.inventory end ) >= @InventoryFilter 
                    END 
                    
    ELSE 
                    
    INSERT #inventoryfilter 
                    
    SELECT p.productidpv.VariantIDsum(case p.TrackInventoryBySizeAndColor when 1 then isnull(i.quan0) else pv.inventory end invqty 
                    FROM product p with 
    (NOLOCKjoin #displayorder d on p.ProductID = d.ProductID 
                    
    join ProductVariant pv with (NOLOCKon p.ProductID pv.ProductID 
                    left join Inventory i with 
    (NOLOCKon pv.VariantID i.VariantID 
                    GROUP BY p
    .productidpv.VariantID 
                    HAVING sum
    (case p.TrackInventoryBySizeAndColor when 1 then isnull(i.quan0) else pv.inventory end ) >= @InventoryFilter 
                    INSERT 
    @productfilter (productiddisplayorderVariantIDVariantDisplayOrderProductNameVariantName, [rank]) 
                    
    SELECT distinct p.productid, do.displayorderpv.VariantIDpv.DisplayOrderp.Namepv.Name ,do.rank
                    FROM 
                    product p with 
    (nolock
                    
    join #displayorder2 do on p.ProductID = do.ProductID                                 
                    
    left join ProductVariant pv with (NOLOCKON p.ProductID pv.ProductID and pv.IsDefault >= @ViewType 
                    left join productcategory pc with 
    (nolockon p.ProductID pc.ProductID 
                    left join productsection ps with 
    (nolockon p.ProductID ps.ProductID 
                    left join ProductManufacturer pm with 
    (nolockon p.ProductID pm.ProductID 
                    left join ProductDistributor pd with 
    (nolockon p.ProductID pd.ProductID 
                    left join ProductGenre px with 
    (nolockon p.ProductID px.ProductID 
                    left join ProductVector px2 with 
    (nolockon p.ProductID px2.ProductID 
                    left join ProductLocaleSetting pl with 
    (nolockon p.ProductID pl.ProductID 
                    left join ProductCustomerLevel pcl with 
    (nolockon p.ProductID pcl.ProductID 
                    left join ProductAffiliate pa with 
    (nolockon p.ProductID pa.ProductID 
                    join 
    #inventoryfilter i on pv.VariantID = i.VariantID 
                    
    WHERE 
                    
    (pc.categoryid = @categoryID or @categoryID is null or @categorycount 0
                    and (
    ps.sectionid = @sectionID or @sectionID is null or @sectioncount 0
                    and (
    pl.LocaleSettingID = @localeID or @localeID is null or @localecount 0
                    and (
    pa.AffiliateID = @affiliateID or @affiliateID is null or @affiliatecount or @FilterProductsByAffiliate 0
                    and (
    pm.manufacturerid = @manufacturerID or @manufacturerID is null or @manufacturercount 0
                    and (
    pd.DistributorID = @distributorID or @distributorID is null or @distributorcount 0
                    and (
    px.GenreID = @genreID or @genreID is null or @genrecount 0
                    and (
    px2.VectorID = @vectorID or @vectorID is null or @vectorcount 0
                    and 
    p.ProductTypeID coalesce(@ProductTypeIDp.ProductTypeID
                    and (case 
                    
    when @FilterProductsByCustomerLevel 0 then 1 
                    when 
    @CustomerLevelFilteringIsAscending and pcl.CustomerLevelID <= @CustomerLevelID or pcl.CustomerLevelID is null then 1 
                    when 
    @CustomerLevelID=and pcl.CustomerLevelID is null then 1 
                    when 
    @CustomerLevelID is null or @custlevelcount 0 then 1 
                    when pcl
    .CustomerLevelID = @CustomerLevelID or pcl.CustomerLevelID is null then 1 
                    
    else 
                    end 

                    

                    and case 
    when isnull(pv.saleprice,0) = 0 then 0 else 1 end >= @OnSaleOnly 
                    
    and p.published >= @publishedonly 
                    
    and pv.published >= @publishedonly 
                    
    and isnull(p.IsAPack0) <= 1-@ExcludePacks 
                    
    and isnull(p.IsAKit0) <= 1-@ExcludeKits 
                    
    and p.IsSystem <= 1-@ExcludeSysProds 
                    
    and p.Deleted 
                    
    and pv.Deleted 
                    
    and ((@IncludeAll 1) or (getdate() between isnull(p.AvailableStartDate'1/1/1900') and isnull(p.AvailableStopDate'1/1/2999')))
                    
    order by do.displayorderp.Namepv.DisplayOrderpv.Name 
                    END 
                    
    ELSE BEGIN 
                    INSERT 
    @productfilter (productiddisplayorderVariantIDVariantDisplayOrderProductNameVariantName, [rank]) 
                    
    SELECT distinct p.productid, do.displayorderpv.VariantIDpv.DisplayOrderp.Namepv.Name ,do.rank
                    FROM 
                    product p with 
    (nolock
                    
    join #displayorder2 do on p.ProductID = do.ProductID                 
                    
    join ProductVariant pv with (NOLOCKon p.ProductID pv.ProductID and pv.IsDefault >= @ViewType 
                    left join productcategory pc with 
    (nolockon p.ProductID pc.ProductID 
                    left join productsection ps with 
    (nolockon p.ProductID ps.ProductID 
                    left join ProductManufacturer pm with 
    (nolockon p.ProductID pm.ProductID 
                    left join ProductDistributor pd with 
    (nolockon p.ProductID pd.ProductID 
                    left join ProductGenre px with 
    (nolockon p.ProductID px.ProductID 
                    left join ProductVector px2 with 
    (nolockon p.ProductID px2.ProductID 
                    left join ProductLocaleSetting pl with 
    (nolockon p.ProductID pl.ProductID 
                    left join ProductCustomerLevel pcl with 
    (nolockon p.ProductID pcl.ProductID 
                    left join ProductAffiliate pa with 
    (nolockon p.ProductID pa.ProductID 
                    WHERE 
                    
    (pc.categoryid = @categoryID or @categoryID is null or @categorycount 0
                    and (
    ps.sectionid = @sectionID or @sectionID is null or @sectioncount 0
                    and (
    pl.LocaleSettingID = @localeID or @localeID is null or @localecount 0
                    and (
    pa.AffiliateID = @affiliateID or @affiliateID is null or @affiliatecount or @FilterProductsByAffiliate 0
                    and (
    pm.manufacturerid = @manufacturerID or @manufacturerID is null or @manufacturercount 0
                    and (
    pd.DistributorID = @distributorID or @distributorID is null or @distributorcount 0
                    and (
    px.GenreID = @genreID or @genreID is null or @genrecount 0
                    and (
    px2.VectorID = @vectorID or @vectorID is null or @vectorcount 0
                    and 
    p.ProductTypeID coalesce(@ProductTypeIDp.ProductTypeID
                    and (case 
                    
    when @FilterProductsByCustomerLevel 0 then 1 
                    when 
    @CustomerLevelFilteringIsAscending and pcl.CustomerLevelID <= @CustomerLevelID or pcl.CustomerLevelID is null then 1 
                    when 
    @CustomerLevelID=and pcl.CustomerLevelID is null then 1 
                    when 
    @CustomerLevelID is null or @custlevelcount 0 then 1 
                    when pcl
    .CustomerLevelID = @CustomerLevelID or pcl.CustomerLevelID is null then 1 
                    
    else 
                    end 

                    

                    and case 
    when isnull(pv.saleprice,0) = 0 then 0 else 1 end >= @OnSaleOnly 
                    
    and p.published >= @publishedonly 
                    
    and pv.published >= @publishedonly 
                    
    and isnull(p.IsAPack0) <= 1-@ExcludePacks 
                    
    and isnull(p.IsAKit0) <= 1-@ExcludeKits 
                    
    and p.IsSystem <= 1-@ExcludeSysProds 
                    
    and p.Deleted 
                    
    and pv.Deleted 
                    
    and ((@IncludeAll 1) or (getdate() between isnull(p.AvailableStartDate'1/1/1900') and isnull(p.AvailableStopDate'1/1/2999')))
                    
    order by do.rank desc,do.displayorderp.Namepv.DisplayOrderpv.Name 
                    END 
                    
                    SET 
    @rcount = @@rowcount 
                    
    IF @StatsFirst 
                    SELECT cast
    (ceiling(@rcount*1.0/@pagesize) as intpages, @rcount ProductCount 
                    
                    SELECT 
                    p
    .ProductID
                    
    p.Name
                    
    pv.VariantID
                    
    pv.Name AS VariantName
                    
    p.ProductGUID
                    
    p.Summary
                    
    p.Description
                    
    p.SEKeywords
                    
    p.SEDescription
                    
    p.SpecTitle
                    
    p.MiscText
                    
    p.SwatchImageMap
                    
    p.IsFeaturedTeaser
                    
    p.FroogleDescription
                    
    p.SETitle
                    
    p.SENoScript
                    
    p.SEAltText
                    
    p.SizeOptionPrompt
                    
    p.ColorOptionPrompt
                    
    p.TextOptionPrompt
                    
    p.ProductTypeID
                    
    p.TaxClassID
                    
    p.SKU
                    
    p.ManufacturerPartNumber
                    
    p.SalesPromptID
                    
    p.SpecCall
                    
    p.SpecsInline
                    
    p.IsFeatured
                    
    p.XmlPackage
                    
    p.ColWidth
                    
    p.Published
                    
    p.RequiresRegistration
                    
    p.Looks
                    
    p.Notes
                    
    p.QuantityDiscountID
                    
    p.RelatedProducts
                    
    p.UpsellProducts
                    
    p.UpsellProductDiscountPercentage
                    
    p.RelatedDocuments
                    
    p.TrackInventoryBySizeAndColor
                    
    p.TrackInventoryBySize
                    
    p.TrackInventoryByColor
                    
    p.IsAKit
                    
    p.ShowInProductBrowser
                    
    p.IsAPack
                    
    p.PackSize
                    
    p.ShowBuyButton
                    
    p.RequiresProducts
                    
    p.HidePriceUntilCart
                    
    p.IsCalltoOrder
                    
    p.ExcludeFromPriceFeeds
                    
    p.RequiresTextOption
                    
    p.TextOptionMaxLength
                    
    p.SEName
                    
    p.Deleted
                    
    p.CreatedOn
                    
    p.ImageFileNameOverride
                    
    pv.VariantGUID
                    
    pv.Description AS VariantDescription
                    
    pv.SEKeywords AS VariantSEKeywords
                    
    pv.SEDescription AS VariantSEDescription
                    
    pv.Colors
                    
    pv.ColorSKUModifiers
                    
    pv.Sizes
                    
    pv.SizeSKUModifiers
                    
    pv.FroogleDescription AS VariantFroogleDescription
                    
    pv.SKUSuffix
                    
    pv.ManufacturerPartNumber AS VariantManufacturerPartNumber
                    
    pv.Price
                    
    pv.CustomerEntersPrice
                    
    pv.CustomerEntersPricePrompt
                    
    isnull(pv.SalePrice0SalePrice
                    
    cast(isnull(pv.Weight,0) as decimal(10,1)) Weight
                    
    pv.MSRP
                    
    pv.Cost
                    
    isnull(pv.Points,0Points
                    
    pv.Dimensions
                    case 
    p.TrackInventoryBySizeAndColor when 1 then isnull(i.quan0) else pv.inventory end Inventory
                    
    pv.DisplayOrder as VariantDisplayOrder
                    
    pv.Notes AS VariantNotes
                    
    pv.IsTaxable
                    
    pv.IsShipSeparately
                    
    pv.IsDownload
                    
    pv.DownloadLocation
                    
    pv.Published AS VariantPublished
                    
    pv.IsSecureAttachment
                    
    pv.IsRecurring
                    
    pv.RecurringInterval
                    
    pv.RecurringIntervalType
                    
    pv.SubscriptionInterval
                    
    pv.SEName AS VariantSEName
                    
    pv.RestrictedQuantities
                    
    pv.MinimumQuantity
                    
    pv.Deleted AS VariantDeleted
                    
    pv.CreatedOn AS VariantCreatedOn
                    
    d.Name AS DistributorName
                    
    d.DistributorID
                    
    d.SEName AS DistributorSEName
                    
    m.ManufacturerID
                    
    m.Name AS ManufacturerName
                    
    m.SEName AS ManufacturerSEName
                    
    s.Name AS SalesPromptName
                    case 
    when pcl.productid is null then 0 else isnull(ep.Price0end ExtendedPrice 
                    FROM Product p with 
    (NOLOCK
                    
    left join ProductVariant pv with (NOLOCKon p.ProductID pv.ProductID and pv.IsDefault >= @ViewType 
                    join 
    @productfilter pf on pv.ProductID pf.ProductID and pv.VariantID pf.VariantID 
                    left join SalesPrompt s with 
    (NOLOCKon p.SalesPromptID s.SalesPromptID 
                    left join ProductManufacturer pm with 
    (NOLOCKon p.ProductID pm.ProductID 
                    left join Manufacturer m with 
    (NOLOCKon pm.ManufacturerID m.ManufacturerID 
                    left join ProductDistributor pd with 
    (NOLOCKon p.ProductID pd.ProductID 
                    left join Distributor d with 
    (NOLOCKon pd.DistributorID d.DistributorID 
                    left join ExtendedPrice ep with 
    (NOLOCKon ep.VariantID pv.VariantID and ep.CustomerLevelID = @CustomerLevelID 
                    left join ProductCustomerLevel pcl with 
    (NOLOCKon p.ProductID pcl.ProductID and pcl.CustomerLevelID = @CustomerLevelID 
                    left join 
    (select VariantIDsum(quanquan from Inventory with (nolockgroup by VariantIDi on pv.VariantID i.VariantID 
                    WHERE pf
    .rownum >= @pagesize*(@pagenum-1)+and pf.rownum <= @pagesize*(@pagenum
                    
    ORDER BY pf.rownum 
                    
    IF @StatsFirst <> 
                    SELECT cast
    (ceiling(@rcount*1.0/@pagesize) as intpages, @rcount ProductCount 
                    END 

  20. #20
    harsha.gus is offline Senior Member
    Join Date
    Mar 2009
    Posts
    301

    Exclamation only categories

    Now Search is returning only categories not products.

    for example

    i have a product name as 10X10 - 1 Mil - Lay Flat Poly Bags-1000/CTN
    when i type 10x10 it give all products with 10x10

    but when i search for 10X10 - 1 Mil - Lay Flat Poly Bags-1000/CTN
    nothing comes up
    Last edited by harsha.gus; 02-24-2011 at 08:26 AM.
    rbgx
    AspDotNetStorefront ML
    v8.0.1.4

  21. #21
    mmcgeachy is offline Senior Member
    Join Date
    Sep 2008
    Posts
    174

    Default

    This due to the fact that GetValidSearchString function makes the search string show up as
    Code:
    "10X10" or "-" or "1" or "Mil" or "-" or "Lay" or "Flat" or "Poly" or "Bags-1000/CTN"
    There are two solutions I can think of implementing in this case. One would be too take out GetValidSearchString from getproducts and the second would be to alter it to take out the or statements.

    The taking out of the or statement would look something like this
    C#/VB.NET Code:
    ALTER FUNCTION [dbo].[GetValidSearchString] (@searchterm nvarchar(4000)) RETURNS nvarchar(4000) AS BEGIN DECLARE 
    @
    s nvarchar(4000SET @'' 
    SELECT @= @s.items ' '
    FROM dbo.Split(@searchterm' 's left join dbo.NoiseWords n on s.items n.word 
    WHERE n
    .word is null IF len(@s) > RETURN left(@slen(@s)-3) ELSE SET @'a' RETURN @s END 
    Making the search string return as
    Code:
    10X10 - 1 Mil - Lay Flat Poly Bags-1000/
    The disadvantage to taking out GetValidSearchString is you are no longer able to use the noise words function in the store admin. You can still have noise words but it would have to be set for a the database level.

    This link and this link give some good information about noise words at the database level.

  22. #22
    harsha.gus is offline Senior Member
    Join Date
    Mar 2009
    Posts
    301

    Exclamation thank you very much

    Thank you very much for taking out time for helping me.

    on the other note, did you try to implement UPS negotiated rates on storefront?
    rbgx
    AspDotNetStorefront ML
    v8.0.1.4