Download the PHP package nqxcode/laravel-lucene-search without Composer
On this page you can find all versions of the php package nqxcode/laravel-lucene-search. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nqxcode/laravel-lucene-search
More information about nqxcode/laravel-lucene-search
Files in nqxcode/laravel-lucene-search
Package laravel-lucene-search
Short Description Laravel 4.2 package for full-text search over Eloquent models based on ZendSearch Lucene.
License
Informations about the package laravel-lucene-search
Laravel 5.5 Lucene search
Laravel 5.5 package for full-text search over Eloquent models based on ZendSearch Lucene.
Installation
Require this package in your composer.json and run composer update:
After updating composer, add the ServiceProvider to the providers array in config/app.php
If you want to use the facade to search, add this to your facades in config/app.php
:
Configuration
Publish the config file into your project by running:
Basic
In published config file add descriptions for models which need to be indexed, for example:
Indexing of dynamic fields
You can also index values of optional fields (dynamic fields). For enable indexing for optional fields:
-
In config for each necessary model add following option:
- In model add special accessor, that returns list of
field-name => field-value
. By defaultgetOptionalAttributesAttribute
accessor will be used. In case accessor name specified in configgetCustomNameAttribute
accessor will be used.
Example:
In config file:
In model add following accessor:
Score Boosting
See details on Apache Lucene - Scoring.
Model level boosting
This is Document level boosting in terminology of Apache Lucene. By default all models have boost value equal to 1. For change of this behavior customize boost for necessary models as in the following examples.
- In config for each necessary model add following option:
In model add following accessor:
- In model add special accessor, that returns boost value.
By default
getBoostAttribute
accessor will be used. In case accessor name specified in configgetCustomNameAttribute
accessor will be used.
Example:
In config file:
In model add following accessor:
Model's field level boosting
This is Document's Field level boosting in terminology of Apache Lucene. By default boost is set in 1 for each field. For change of this behavior set boost for necessary fields as in the following examples.
In config file:
Or/and in model accessor:
Stemming and stopwords
By default the following filters are used in search:
- Stemming filter for english/russian words (for reducing words to their root form),
- Stopword filters for english/russian words (for exclude some words from search index).
This filters can be deleted or replaced with others.
Usage
Artisan commands
Initialize or rebuild search index
For building of search index run:
Clear search index
For clearing of search index run:
Filtering of models in search results
For filtering of models in search results each model's class can implements SearchableInterface
.
For example:
Partial updating of search index
For register of necessary events (save/update/delete) use Nqxcode\LuceneSearch\Model\SearchTrait
in target model:
Perform operations without indexing
If you want to avoid triggering the indexing, wrap necessary operations in the withoutSyncingToSearch()
method on your model:
Query building
Build query in several ways:
Using constructor:
By default, queries which will execute search in the phrase entirely are created.
Simple queries
Advanced queries
For query
and where
methods it is possible to set the following options:
- phrase - phrase match (boolean, true by default)
- proximity - value of distance between words (unsigned integer)
- fuzzy - value of fuzzy (float, 0 ... 1)
- required - should match (boolean, true by default)
- prohibited - should not match (boolean, false by default)
Examples:
Find all models in which any field contains phrase like 'composite one two phrase':
Search by each word in query:
Using Lucene raw queries:
Getting of results
For built query are available following actions:
Get all found models
Get count of results
Get limit results with offset
Paginate the found models
Highlighting of matches
Highlighting of matches is available for any html fragment encoded in utf-8 and is executed only for the last executed request.
License
Package licenced under the MIT license.
All versions of laravel-lucene-search with dependencies
illuminate/support Version 4.2.*
nqxcode/zendsearch Version 2.*
nqxcode/lucene-stemmer-en-ru Version 1.*