Limiting Search Results

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
Brewhaus
Vice Admiral (VADM)
Vice Admiral (VADM)
Posts: 878
Joined: Sat Jan 19, 2008 4:30 pm

Limiting Search Results

Post by Brewhaus » Sat Feb 21, 2009 10:29 am

Is there a way to limit search results to a specific category? I would assume that this would be controlled through the ConLib/SearchPage.ascx.cs file, but do not know how this would be written in.
Rick Morris
Brewhaus (America) Inc.
Hot Sauce Depot

User avatar
nickc
Captain (CAPT)
Captain (CAPT)
Posts: 276
Joined: Thu Nov 29, 2007 3:48 pm

Re: Limiting Search Results

Post by nickc » Sat Feb 21, 2009 11:54 am

Check out the Products.ProductDataSource class in the API docs. Both AdvanchedSearch() and NarrowSearch() methods accept a CategoryId argument.

Brewhaus
Vice Admiral (VADM)
Vice Admiral (VADM)
Posts: 878
Joined: Sat Jan 19, 2008 4:30 pm

Re: Limiting Search Results

Post by Brewhaus » Sat Feb 21, 2009 3:25 pm

What we need to do is limit the entire search to a single (head) category. Any item that belongs to a different category should not be returned. I assume that there must be an arguement in the SearchPage.ascx.cs file that will allow for this, but I cannot seem to nail it down.
Rick Morris
Brewhaus (America) Inc.
Hot Sauce Depot

User avatar
nickc
Captain (CAPT)
Captain (CAPT)
Posts: 276
Joined: Thu Nov 29, 2007 3:48 pm

Re: Limiting Search Results

Post by nickc » Mon Feb 23, 2009 11:30 am

Code: Select all

    public int CategoryId
    {
        get
        {
            if (ViewState["CategoryId"] == null)
                ViewState["CategoryId"] = PageHelper.GetCategoryId();
            return (int)ViewState["CategoryId"];
        }
Instead of initializing to PageHelper.GetCategoryId(), which probably returns 0 on the first page view (and therefore everything in the catalog), add your "head" category id (or method to derive it).

Brewhaus
Vice Admiral (VADM)
Vice Admiral (VADM)
Posts: 878
Joined: Sat Jan 19, 2008 4:30 pm

Re: Limiting Search Results

Post by Brewhaus » Mon Feb 23, 2009 11:52 am

That worked perfectly- thank you! The only issue was that moving to page 2 of the results expanded to include all categories in the 'Narrow Search' section, so we just bumped the number of results per page to 36 in order to avoid this issue for most cases.
Rick Morris
Brewhaus (America) Inc.
Hot Sauce Depot

Brewhaus
Vice Admiral (VADM)
Vice Admiral (VADM)
Posts: 878
Joined: Sat Jan 19, 2008 4:30 pm

Re: Limiting Search Results

Post by Brewhaus » Wed Feb 25, 2009 7:53 pm

Although items from categories not selected by using the code above do not show on the original search, they do show up when clicking on the 'expand' options, it does include other categories. Is there another spot in the file where we need to make the same stipulation on the category to ensure that other categories do not show up?
Rick Morris
Brewhaus (America) Inc.
Hot Sauce Depot

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Limiting Search Results

Post by mazhar » Thu Feb 26, 2009 6:07 am

Check the admin search module, It defines a Search method that take a Boolean parameter to specify you want to search subcategories or not.

Brewhaus
Vice Admiral (VADM)
Vice Admiral (VADM)
Posts: 878
Joined: Sat Jan 19, 2008 4:30 pm

Re: Limiting Search Results

Post by Brewhaus » Thu Feb 26, 2009 6:33 pm

Actually, when expanding the search it opens up to categories at the same level. Because we will be operating two stores on the db, we have placed all of the 'store 1' categories and products into one category, and the 'store 2' categories and products into a different category. This keeps things neat and tidy in the catalog. Because one store carries all items from both stores, there is no need to limit the search for that store. But the other store carries only the products in 'store 1'. By limiting the search as discussed earlier in this thread, a basic search returns only the items inside of the 'store 1' category / sub-categories. But, if a customer clicks on the 'expand' option on the search results page, the 'store 2' main category shows up if the search term matches any products in that category.

I do not know if there is any way to limit what category will be returned in the search results, regardless of whether a person tries to narrow or expand the results, but that is what we are hoping to do.
Rick Morris
Brewhaus (America) Inc.
Hot Sauce Depot

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Limiting Search Results

Post by mazhar » Fri Feb 27, 2009 5:55 am

You may try to customize the CateogrySearchSidebar control to take care of your requirements.

Post Reply