Download the PHP package webikevn/laravel-fulltext-search without Composer
On this page you can find all versions of the php package webikevn/laravel-fulltext-search. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download webikevn/laravel-fulltext-search
More information about webikevn/laravel-fulltext-search
Files in webikevn/laravel-fulltext-search
Package laravel-fulltext-search
Short Description Full-text search and reusable queries in laravel.
License MIT
Informations about the package laravel-fulltext-search
Searchable
Full-text search and reusable queries in laravel.
- Currently supports MySQL only.
- Helpful for complex table queries with multiple joins and derived columns.
- Reusable queries and column definitions.
Overview
Full-text search on eloquent models
Simple setup for searchable model and can search on derived columns.
Imagine we have an api for a table or list that has full-text searching and column sorting and pagination. This is a usual setup for a table or list. The internal explanations will be available on the documentation below. Our api call may look like this:
http://awesome-app.com/api/posts?per_page=10&page=1&sort_by=title&descending=true&search=SomePostTitle
Your code can look like this:
Documentation
Installation
Searchable Model
This will addSelect field sort_index
which will used to order or sort by relevance.
If you want to disable sort by relevance, call method sortByRelevance(false)
before search()
method.
Example:
Set searchable configurations on runtime.
Easy Sortable Columns
You can define columns to be only sortable but not be part of search query constraint.
Just put it under sortable_columns
as shown below .
This column can be easily access to put in orderBy
of query builder. All searchable columns are also sortable columns.
Custom Search Query - Exact Search Example
You can extend the class Webike\Searchable\Search\SublimeSearch
a.k.a fuzzy-search implementation.
then use it in the model:
You may also check the build query by dd-ing it:
which may output to
Using derived columns for order by and where conditions
Usually we have queries that has a derived columns like our example for Post
's author_full_name
.
Sometimes we need to sort our query results by this column.
Helper methods available on model
isColumnValid [static]
- Identifies if the column is a valid column, either a regular table column or derived column.
- Useful for checking valid columns to avoid sql injection especially in
orderBy
query.
getTableColumns [static]
- Get the table columns.
enableSearchable
- Enable the searchable behavior.
disableSearchable
- Disable the searchable behavior.
- Calling
search()
method will not perform a search.
setSearchable
- Set or override the model's
$searchable
property. - Useful for building searchable config on runtime.
addSearchable
- Add columns or joins in the model's
$searchable
property. - Useful for building searchable config on runtime.
Warning
Calling select()
after search()
will overwrite sort_index
field, so it is recommended to call select()
before search()
.
Credits
- Ray Anthony Madrona @raymadrona, for the tips on using MySQL
LOCATE()
for sort relevance. - nicolaslopezj/searchable, for the
$searchable
property declaration style.