You are here:  » New text search filter within search results


New text search filter within search results

Submitted by Nic0904 on Sun, 2016-04-03 08:45 in

Hi David,

I wondered how difficult it would be to add a new search filter, to allow a text search within a search to narrow the items selected.

At the moment I have brand/category/price filters and sort order change

As I am using search to generate categories using a filter to allow a user to home in on a product(s) would be a great addition. Is this possible, if so is it complicated to do?

Thanks
Dave

Submitted by support on Mon, 2016-04-04 09:10

Hi Dave,

That's straight forward to implement - in search.php look for the following code at line 18:

  $brandFilter = (isset($_GET["brandFilter"])?$_GET["brandFilter"]:"");

...and REPLACE with:

  $brandFilter = (isset($_GET["brandFilter"])?$_GET["brandFilter"]:"");
  $textFilter = (isset($_GET["textFilter"])?$_GET["textFilter"]:"");

And then the following code at line 72:

  if ($brandFilter)
  {
    $priceWhere .= " AND brand = '".database_safe($brandFilter)."' ";
  }

...and REPLACE with:

  if ($brandFilter)
  {
    $priceWhere .= " AND brand = '".database_safe($brandFilter)."' ";
  }
  if ($textFilter)
  {
    $priceWhere .= " AND name LIKE '%".database_safe($textFilter)."%' ";
  }

And then the following code at line 439:

      if ($brandFilter)
      {
        $sortHREF .= "brandFilter=".urlencode($brandFilter)."&";
      }

...and REPLACE with:

      if ($brandFilter)
      {
        $sortHREF .= "brandFilter=".urlencode($brandFilter)."&";
      }
      if ($textFilter)
      {
        $sortHREF .= "textFilter=".urlencode($textFilter)."&";
      }

And finally the following code at line 561:

    if ($brandFilter)
    {
      $sort .= "&brandFilter=".urlencode($brandFilter);
    }

...and REPLACE with:

    if ($brandFilter)
    {
      $sort .= "&brandFilter=".urlencode($brandFilter);
    }
    if ($textFilter)
    {
      $sort .= "&textFilter=".urlencode($textFilter);
    }

Then in html/searchfilters.php look for the following code at line 183:

  print "</div>";

...and REPLACE with:

  print "</div>";
  print "<div class='small-12 medium-3 columns'>";
  print "<label>Containing Text:<br />";
  print "<input name='textFilter' value='".htmlspecialchars($textFilter,ENT_QUOTES,$config_charset)."' />";
  print "</div>";

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by Nic0904 on Wed, 2016-04-13 15:26

Hi David,

I finally got time to implement this, and with the vast number of products it really helps to have the ability to search within existing search results to narrow down the selection.

Your changes worked perfectly, I had to modify the html a little to fit with the template I am using but that looks good too.

Thank you for the help on this, maybe an idea for a core feature I have found it makes the site much more user friendly.

Thanks
Dave