Faceted Search (solr) vs Good old filtering via PHP?

Faceted Search (solr) vs Good old filtering via PHP?

July 4, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Faceted Search (solr) vs Good old filtering via PHP?

Layered Navigation vs Faceted Search: A Comparative Analysis

In the realm of e-commerce platforms, navigation systems like Magento’s or PrestaShop’s layered navigation are commonplace for filtering products. However, as your store’s product catalog grows and complexity increases, you might be wondering if these traditional methods are enough, or whether advanced solutions like Apache Solr or Lucene faceted search could provide better performance and user experience.

Understanding Layered Navigation

Layered navigation is a straightforward approach where filters are applied directly via PHP and MySQL queries. It’s easy to implement and doesn’t require any additional infrastructure beyond your existing database setup.

For example, in a typical layered navigation system:

$filters = [
  'price' => [
    'min' => $min_price,
    'max' => $max_price,
  ],
  'category_id' => [
    'value' => [1, 2, 3],
  ],
];

$query = "SELECT * FROM products WHERE price BETWEEN {$min_price} AND {$max_price} AND category_id IN ({$categories})";

$products = DB::select($query);

The database is queried directly based on the given filter parameters. This works fine for small to medium-sized catalogs but can become slow and inefficient as your product count increases.

Introducing Faceted Search with Apache Solr

Solr is a popular open-source search platform built upon Apache Lucene. It’s designed from the ground up to handle large-scale indexing and searching, providing features like faceting, replication, and distributed indexing.

With Solr faceted navigation:

  1. Products are indexed in Solr instead of MySQL.
  2. Filters are applied using Solr’s faceting feature.
  3. Results are returned with facet information pre-calculated.

Here’s a simplified example of how you might set up a Solr query with facets:

{
  "query": {
    "match_all": {}
  },
  "facet": {
    "price_facet": {
      "range": {
        "field": "price",
        "start": 0,
        "end": 1000,
        "gap": 50
      }
    },
    "category_facet": {
      "terms": {
        "field": "category"
      }
    }
  }
}

Solr returns results alongside the count of matching documents for each facet range or term, allowing you to generate filters without running additional queries.

PHP and MySQL Limitations

While it’s technically possible to emulate facets using just PHP and MySQL (for example, by running separate COUNT queries for each filter), this approach quickly becomes impractical as your catalog grows. Each extra query adds latency, and the number of required queries can increase exponentially with the number of filters.

Moreover, layered navigation doesn’t support complex faceting logic out-of-the-box, such as nested facets or multi-value facets. Implementing these features would require significant manual effort and could lead to performance degradation.

Faceted search provides several advantages over traditional layered navigation:

  • Improved Performance: By pre-computing facet information during indexing, Solr reduces the number of queries needed for filtering.
  • Scalability: Faceted search can handle larger product catalogs more efficiently than PHP and MySQL alone.
  • Enhanced User Experience: Facets allow users to filter and narrow down results interactively without waiting for long database queries.

Trade-offs to Consider

While faceted search offers compelling benefits, it’s not without trade-offs:

  • Infrastructure Requirements: Solr requires additional server resources beyond your primary e-commerce platform.
  • Setup Complexity: Integrating Solr with your existing system can be more complex than a simple PHP and MySQL setup.
  • Learning Curve: If your development team isn’t familiar with Solr, there will be an initial learning period.

When to Choose Each Approach

For small to medium-sized e-commerce stores (under ~10,000 products), layered navigation using PHP and MySQL is likely sufficient. It’s simpler to implement and manage.

However, as your product catalog grows (especially if you’re a larger retailer with tens or hundreds of thousands of SKUs) or if you need complex faceting logic, Solr becomes a more attractive option for its improved performance and scalability.

Conclusion

In the battle between layered navigation and faceted search, there’s no one-size-fits-all answer. The choice depends on your specific needs, catalog size, and technical constraints.

For most small to medium businesses, a simple PHP and MySQL layered navigation system is adequate. It’s easy to set up, maintain, and doesn’t require additional infrastructure.

However, for larger retailers with extensive product catalogs or complex filtering requirements, faceted search using Apache Solr can provide significant performance benefits and enhance the user experience.

Regardless of your choice, remember that efficient filtering is crucial for a successful e-commerce platform. Both approaches have their merits, so consider your specific use case when deciding which to implement.

For more in-depth information on Laravel integration with external search engines like Solr, check out our detailed guides at LaravelCompany.com.

Catalog Indexing Database Performance

Our network