Download the PHP package vaened/php-search-engine without Composer
On this page you can find all versions of the php package vaened/php-search-engine. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download vaened/php-search-engine
More information about vaened/php-search-engine
Files in vaened/php-search-engine
Package php-search-engine
Short Description A flexible PHP search library that provides essential features for implementing search engines. It includes capabilities for filtering, indexing, and search functionalities. Designed to be easily extensible, it integrates seamlessly with different ORM frameworks to enhance search operations and manage complex queries.
License MIT
Informations about the package php-search-engine
PHP Search Engine
The Search Library provides a fundamental and flexible foundation for building search engines in applications. This library is not tied to any specific ORM implementation; rather, it serves as the core upon which more complex search solutions can be built in other libraries that integrate with specific ORMs.
It offers a robust structure for handling common search functionalities, such as custom filters, text searches, and range management. Its modular design ensures efficient integration and the ability to extend to cover more sophisticated search needs as project requirements evolve.
Installation
PHP Search Engine requires PHP 8.1. To get the latest version, simply require the project using Composer:
Usage
This library provides a foundational framework for creating search engines. It includes the AbstractSearchEngine
class as a base for
custom search implementations and two key traits: Flaggable
for filtering based on flags, and Indexable
for search operations using
indices. These components work together to offer a flexible and extensible solution for managing search criteria.
Search Engine
The library provides a base class called AbstractSearchEngine
which offers fundamental functionality typically extended by other libraries
for specific implementations. However, it's not mandatory to extend this class—custom implementations of SearchEngine
can be created from
scratch.
The key feature of AbstractSearchEngine
is the apply
method:
This method progressively builds search criteria based on applied filters, ultimately constructing the Criteria object.
Criteria
The criteria method is responsible for creating a Criteria instance that encapsulates all the search criteria:
This method calculates the pagination offset and initializes the Criteria object with the accumulated search criteria, order, and pagination details.
Flaggable Trait
The Flaggable trait adds the filter
method to the SearchEngine, allowing you to apply filters based on specific flags. This method takes a
FlagBag containing a set of flags and applies the corresponding filters. Each flag becomes a search criterion that is added to the engine.
Indexable Trait
The Indexable trait provides the search
method, which allows you to perform searches based on a specific index. It uses an index defined
by
the BackedEnum and a queryString to search for the associated criterion in the index repository. If a valid criterion is found, it is
applied to the search engine.
Concepts
Filters
Filters represent conditions applied during the search process. These filters are crucial for defining and refining search criteria according to specific requirements. Filters can be simple, such as a direct value check, or more complex, combining multiple conditions to restrict results in detail.
Example of internal definition
Flags
Flags are represented by classes that define binary filters, meaning they do not require additional parameters to determine whether a condition is met or not. These filters act as boolean indicators that apply predefined conditions without needing extra input values. Flags return a collection of filters based on the flag parameter provided.
Example of internal implementation
Indexes
Indexes are represented by classes that manage specific search indices. Each index is associated with a search criterion that is applied to a given value. The primary function of an Index is to return a single filter based on the provided index and value. This structure allows for optimized and precise searches using predefined indices.
Example of internal implementation
Usage
Design Principles
In the Search Library, each filter is treated as a separate PHP class with its own specific logic. This approach promotes order and cohesion in the design of the search system. By encapsulating filtering logic in separate classes, the code becomes easier to maintain and extend.
For instance, instead of having scattered filtering functions, classes like PersonId
and PersonName
are defined, each containing methods
such as equals(value)
or startsWith(value)
. This not only enhances code clarity but also enables more efficient reuse of filters in
different contexts. By keeping filtering logic within dedicated classes, each filter has a single, well-defined responsibility, contributing
to a cleaner and more organized design.
License
This library is licensed under the MIT License. For more information, please see the license
file.