Download the PHP package shabushabu/laravel-paradedb-search without Composer
On this page you can find all versions of the php package shabushabu/laravel-paradedb-search. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download shabushabu/laravel-paradedb-search
More information about shabushabu/laravel-paradedb-search
Files in shabushabu/laravel-paradedb-search
Package laravel-paradedb-search
Short Description Integrates the pg_search extension by ParadeDB into Laravel
License MIT
Homepage https://github.com/ShabuShabu/laravel-paradedb-search
Informations about the package laravel-paradedb-search
ParadeDB Search for Laravel
Integrates the pg_search
Postgres extension by ParadeDB into Laravel
Supported minimum versions
PHP | Laravel | PostgreSQL | pg_search |
---|---|---|---|
8.2 | 11.0 | 16 | 0.7.5 |
Installation
[!CAUTION] Please note that this is a new package and, even though it is well tested, it should be considered pre-release software
Before installing the package you should install and enable the pg_search extension.
You can then install the package via composer:
You can also publish the config file:
These are the contents of the published config file:
Usage
Add a bm25 index
Each model that you want to be searchable needs a corresponding bm25
index. These can be generated within a migration like so:
Preparing your model
Just add the Searchable
trait to your model to enable search:
ParadeQL
ParadeDB Search for Laravel comes with a fluent builder for ParadeQL, a simple query language.
This builder can be passed as a condition to a search where
method or used within the various ParadeDB expressions.
Basic query
Add an IN condition
Add an AND NOT condition
Boost a condition
Apply the slop operator
More complex example with a sub condition
Apply a simple filter
Apply a boolean filter
Apply a basic range filter
Apply an inclusive range filter
Apply an exclusive range filter
ParadeDB functions
For more complex operations, it will be necessary to use some of the provided ParadeDB functions, all of which have corresponding query expressions:
Get all the records
Get none of the records
Boost a query
Add a constant score
Perform a disjunction max query
The DisjunctionMax
constructor also accepts an array of queries, so using the fluid interface might be more convenient for multiple queries:
This also allows you to conditionally add queries:
Search for a fuzzy term
Highlight search terms
Search for a phrase
Perform a phrase prefix query
Search within a given range
Here are the supported range types (all within the ShabuShabu\ParadeDB\Query\Expressions\Ranges
namespace), plus their corresponding Postgres type:
Int4::class;
orint4range
Int8::class;
orint8range
Numeric::class;
ornumrange
Date::class;
ordaterange
Timestamp::class;
ortsrange
TimestampTz::class;
ortstzrange
Perform a regex query
Search for a term
Search for a set of terms
The above query can also be written in a fluid manner:
The term
method allows you to conditionally add terms:
Perform a complex boolean query
Boolean queries can also be constructed in a fluid manner:
The two queries above are identical. The fluent methods allow you to conditionally add queries, though:
Sort by rank
Pagination
It's also possible to paginate the results. Both the paginate
and simplePaginate
methods use the underlying limit
& offset
functionality, so will be more performant:
Search parameters
The ParadeDB search
function allows you to set a variety of parameters to fine-tune your search. All of these can be set here as well:
Hybrid search
Whenever a similarity query is provided, the package will automatically perform a hybrid search. Please note that a ParadeDB query is still required!
Search parameters
Similarly to the full-text search, there are also parameters you can set for a hybrid search:
Modifying the underlying query
Occasionally, it will be necessary to modify the base query, for example to eager-load some relationships. This can be accomplished like so:
A word of caution
While it is possible to combine ParadeDB queries with regular Eloquent queries, you will incur some performance penalties.
For optimal performance it is recommended to let the bm25
index do as much work as possible, so wherever possible you should use the built-in filters as well as limit & offset!
Getting help
If your issue has something to do with this package, then please use the issues and discussions!
If your issue is related to pg_search
, tho, then please create a discussion in the ParadeDB repo.
To make this a bit easier, you can use the paradedb:help
command that ships with this package:
Please note that this command is just an implementation of the paradedb.help()
function. Please use this command wisely!
Testing
The tests require a PostgreSQL database, which can easily be set up by running the following script:
[!WARNING] Please note that both pg_search and pgvector extensions need to be available already.
Then run the tests:
Or with test coverage:
Or with type coverage:
Or run PHPStan:
ParadeDB test table
There is also a command that allows you to create and drop the built-in test table
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Taylor Otwell for creating Laravel
- ParadeDB for creating
pg_search
- ShabuShabu
- All Contributors
Disclaimer
This is a 3rd party package and ShabuShabu is not affiliated with either Laravel or ParadeDB.
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-paradedb-search with dependencies
spatie/laravel-package-tools Version ^1.16
illuminate/contracts Version ^11.0