PHPackages                             icanboogie/facets - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Search &amp; Filtering](/categories/search)
4. /
5. icanboogie/facets

ActiveLibrary[Search &amp; Filtering](/categories/search)

icanboogie/facets
=================

Makes it easy to implement faceted search.

v0.8.0(5y ago)11.2k2BSD-3-ClausePHPPHP &gt;=7.2CI failing

Since Nov 21Pushed 4y ago2 watchersCompare

[ Source](https://github.com/ICanBoogie/Facets)[ Packagist](https://packagist.org/packages/icanboogie/facets)[ Docs](https://icanboogie.org/)[ RSS](/packages/icanboogie-facets/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (1)Dependencies (3)Versions (9)Used By (2)

Facets
======

[](#facets)

[![Release](https://camo.githubusercontent.com/fefc8cf5fefbc260a113a6d5090c664a7e03ac1faa12ad45eec2998bad59942a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6963616e626f6f6769652f6661636574732e737667)](https://github.com/ICanBoogie/Facets/releases)[![Build Status](https://camo.githubusercontent.com/3d3c67e36b5fd5370851f7af7719e23f6c183c0d964bb3a4b2e9dae0aec50be0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f4943616e426f6f6769652f4661636574732f74657374)](https://github.com/ICanBoogie/Facets/actions?query=workflow%3Atest)[![Code Quality](https://camo.githubusercontent.com/8dad212a3649b0cb7cb10fe2c6e08e84575db51e0fda0bfed2e537976165d437/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f4943616e426f6f6769652f4661636574732e737667)](https://scrutinizer-ci.com/g/ICanBoogie/Facets)[![Code Coverage](https://camo.githubusercontent.com/96fe7c43deca883113ed5a108ba4c03478b8411c3ca23e08eb534421f0b4a5a2/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f4943616e426f6f6769652f4661636574732e737667)](https://coveralls.io/r/ICanBoogie/Facets)[![Packagist](https://camo.githubusercontent.com/edd5be1e6e7a09291bc0542448d083a187a7f07dd638a0d7911b86c03a4aa2c5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6963616e626f6f6769652f6661636574732e737667)](https://packagist.org/packages/icanboogie/facets)

Together with the [icanboogie/activerecord](https://github.com/ICanBoogie/ActiveRecord) package, this library makes it easy to implement [faceted search](http://en.wikipedia.org/wiki/Faceted_search). The library makes it especially easy to parse query strings (bag of words), use serialized criterion values such as sets (e.g. "1|2|3") or intervals (.e.g. "1990..2010"), and fetch records matching an array of conditions.

Fetching records matching conditions
------------------------------------

[](#fetching-records-matching-conditions)

A [BasicFetcher](https://icanboogie.org/api/facets/0.7/class-ICanBoogie.Facets.BasicFetcher.html) instance can be used to fetch records matching a set of conditions. The *fetcher* takes care of the various steps required to build the query and fetch the matching records. These steps can be summarized as follows:

1. Parse the specified modifiers and extract conditions, offset, limit, order and query string.
2. Build the initial query.
3. Invoke criteria to alter the query.
4. Alter the query with the conditions.
5. Count the total number of records that match the query.
6. Alter the query with the order.
7. Alter the query with the offset and limit.
8. Fetch the records matching the query.
9. Invoke criteria to alter the records.
10. Return a [RecordCollection](https://icanboogie.org/api/facets/0.7/class-ICanBoogie.Facets.RecordCollection.html) instance containing the records.

The following example demonstrates how a [BasicFetcher](https://icanboogie.org/api/facets/0.7/class-ICanBoogie.Facets.BasicFetcher.html) instance can be used to fetch online articles that are classified in the "music" category, and were published between 2010 and 2014. A maximum of 10 articles can be fetched, and they are ordered starting with the most recent:

```
