Download the PHP package jdkweb/search without Composer
On this page you can find all versions of the php package jdkweb/search. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jdkweb/search
More information about jdkweb/search
Files in jdkweb/search
Informations about the package search
laravel Search
Laravel-Search is a search-engine using the models. Search easily, flexible add intelligent on your Laravel website or application.
Table of contents
- Installation
- Usage
- Configuration with config-file
- Search engine configuration
- Searchable model configuration
- Example
- Rename query strings parameters
- Preset search words
- Search Result items per page
- Example Config
- Configuration directly embed settings in script
- Using the search engine
- Filters (search groups)
- Operators for conditions
- Filter specific words from the search
- Methods and Closures
- Compare configuration settings
Installation
Requires PHP 8.1 and Laravel 10 or higher
Install the package via composer:
Config
For configuration settings you need to publish the config
In the config is needed for:
- To setup reusable independent search-engine setting.
- Change the list of words to filter from search
- Change cache settings
Usage
Configuration with config file
Publish the config first.
- Define the models that need to be used in search engine
- set default search conditions
- define the output variables.
Search engine configuration
Base configuration for the search engine in the config-file
Searchable model configuration
Example
The example below shows the configuration of a search engine named 'global'.
In short, one can defining multiple search engines. This makes it possible to create multiple specific search sets that behave different. You can create a global search engine or one for a specific page/model.
See example of large configuration file with methods an closures
Rename query strings parameters
Renaming the GET variables that appear in the URL
Preset search words
It is possible to fire a searchQuery by default.
In config file
Search Result items per page
Change search result items per page
Example config
A setup for three different search engine configurations, each in a other situation with more specific search results
- Global website search
- Book / Chapter search
- Article searching
Configuration directly embed settings in script
Without using a config file
Using the search engine
Laravel-search is working with GET variables (query strings parameters can be renamed)
By default, if defined, the search engine configuration called 'default' is used.
You can use a custom configuration by calling the settings()
methode
Result:
ordered by relevance
Filters (search groups)
The searchable models we defined earlier can be used to create filters (or search groups). As shown in the example above.
Use specific model or group of models for searching
Operators for conditions
In the search conditions is it possible to use operators
Operator | Type | Example | Query Builder |
---|---|---|---|
=, |
Equal | 'id' => 10 (default) | ->where('id',10) |
'id:=' => 10 | |||
!=, |
Unequal | 'id:!=' => 10 | ->where('id','!=', 10) |
'id:neq' => 10 | |||
>, |
Greater than | 'age:>' => 35 | |
>=, |
Greater than or equal | 'age:gte' => 35 | ->where('age', '>=', 35) |
\<, |
Less than | 'age:<' => 12 | ->where('age', '<', 12) |
\<=, |
Less than or equal | 'age:lte' => 12 | ->where('age', '<=', 12) |
in | In | 'id:in' => [10,11,12] | ->whereIn('id',[10,11,12]) |
!in, |
Not in | 'id:!in' => [2,4] | ->whereNotIn('id',[2,4]) |
like | Like | 'title:like' => '%Linux%' | ->where('title', 'LIKE', '%linux%') |
!like, |
Not like | 'title:notlike' => '%linux%' | ->where('title', 'NOT LIKE', '%linux%') |
or | Or | 'or:published' => 1 | ->orWhere('published', 1) |
Or | 'or:id:in' => [10,11] | ->orWhereIn('id', [10,11]]) |
Filter specific words from the search
Language related list of words that are filtered from the search
Removing Linking words (the, and, ...) makes it possible to keep the search results cleaner.
Methods and Closures
The configurations above provide several examples of using methods and Closures.
This makes it possible to relate the models to Closure functions, and methods form (other) models or controllers.
Methods
In config file
Directly into the script
Method in model (\App\Models\Articles)
Closures
Compare configuration settings
Config-file
Directly embed settings into the script