In part 1, we briefly covered the installation and basic syntax of PINQ, a PHP LINQ port. In this article, we will see how to use PINQ to mimic a faceted search feature with MySQL.
We are not going to cover the full aspect of faceted search in this series. Interested parties can refer to relevant articles published on Sitepoint and other Internet publications.
A typical faceted search works like this in a website:
- A user provides a keyword or a few keywords to search for. For example, “router” to search for products which contain “router” in the description, keyword, category, tags, etc.
- The site will return the products matching the criteria.
- The site will provide some links to fine tune the search. For example, it may prompt that there are different brands for a router, and there may be different price ranges and different features.
- The user can further screen the results by clicking the different links provided and eventually gets a more customized result set.
Faceted search is so popular and powerful and you can experience it in almost every e-Commerce site.
Unfortunately, faceted search is not a built-in feature provided by MySQL yet. What can we do if we are using MySQL but also want to provide our users with such a feature?
With PINQ, we’ll see there is an equally powerful and straightforward approach to achieving this as when we are using other DB engines - at least in a way.
Extending Part 1 Demo
NOTE: All code in this part and the part 1 demo can be found in the repo.
In this article, we will extend the demo we have shown in Part 1 and add in some essential faceted search features.
Let’s start with index.php by adding the following few lines:
$app->get('demo2', function () use ($app)
{
global $demo;
$test2 = new pinqDemo\Demo($app);
return $test2->test2($app, $demo->test1($app));
}
);
$app->get('demo2/facet/{key}/{value}', function ($key, $value) use ($app)
{
global $demo;
$test3 = new pinqDemo\Demo($app);
return $test3->test3($app, $demo->test1($app), $key, $value);
Truncated by Planet PHP, read more at the original (another 1415 bytes)
more
{ 0 comments... » PINQ – Querify Your Datasets – Faceted Search read them below or add one }
Post a Comment