PHPackages                             sadovojav/yii2-search-lucene - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Search &amp; Filtering](/categories/search)
4. /
5. sadovojav/yii2-search-lucene

ActiveYii2-extension[Search &amp; Filtering](/categories/search)

sadovojav/yii2-search-lucene
============================

Yii2 search lucene

12013[2 issues](https://github.com/sadovojav/yii2-search-lucene/issues)PHP

Since Aug 31Pushed 5y ago2 watchersCompare

[ Source](https://github.com/sadovojav/yii2-search-lucene)[ Packagist](https://packagist.org/packages/sadovojav/yii2-search-lucene)[ RSS](/packages/sadovojav-yii2-search-lucene/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Yii2 Zend Lucene Search
=======================

[](#yii2-zend-lucene-search)

#### Features:

[](#features)

- Easy to use
- Search in models
- MutliTerm
- Search by numbers
- Search in documents (xlsx, docx, pptx)
- Relation value
- Interactive add/update/delete index

### Composer

[](#composer)

The preferred way to install this extension is through [Composer](http://getcomposer.org/).

Either run `php composer.phar require sadovojav/yii2-search-lucene "dev-master"`

or add `"sadovojav/yii2-search-lucene": "dev-master"` to the require section of your `composer.json`

### Config

[](#config)

- If need implemented in the model class interface sadovojav\\search\\PageLink

```
use yii\helpers\Url;
use sadovojav\search\PageLink;

class News extends \yii\db\ActiveRecord implements PageLink {
    public function getUrl()
    {
        return Url::to(['/news/news/view', 'id' => $this->id]);
    }
}
```

#### If you want use interactive add/update/delete index

[](#if-you-want-use-interactive-addupdatedelete-index)

- Attach component in your config file:

```
'components' => [
    'search' => [
        'class' => 'sadovojav\search\components\SearchLucene',
        'indexDirectory' => '@console/runtime/search'
    ]
]
```

- Attach behavior to your model

```
use sadovojav\search\behaviors\SearchBehavior;

class News extends \yii\db\ActiveRecord
{
    public function behaviors()
    {
        return [
        	'search' => [
                'class' => SearchBehavior::className(),
                'attributes' => [
                    'name' => [
                        'name' => SearchLucene::FIELD_TEXT
                    ],
                    'text_intro' => [
                        'text_intro' => SearchLucene::FIELD_UN_STORED
                    ],
                    'text_full' => [
                        'text_full' => SearchLucene::FIELD_UN_STORED
                    ],
                ],
                'conditions' => [
                    'status_id' => self::STATUS_ACTIVE
                ],
                'urlManagerRule' => [
                    'news/' => '/news/news/view'
                ]
            ]
        ];
    }
}
```

#### Parameters

[](#parameters)

- array `attributes` required - attributes to index
- array `conditions` - Conditions for creating search index
- string `baseUrl` = `''` - Base url
- array `urlManagerRule` - Pretty url rules

#### Attention

[](#attention)

```
SearchBehavior can work correctly only with one language website. Otherwise, it will be indexed only one language.

```

#### If you want use console indexing

[](#if-you-want-use-console-indexing)

- Attach component in your config file:

```
'components' => [
    'search' => [
        'class' => 'sadovojav\search\components\SearchLucene',
        'indexDirectory' => '@console/runtime/search',
        'models' => [
            [
                'dataProviderOptions' => [
                    'query' => common\modules\news\models\News::find()
                        ->localized('en')
                        ->active()
                ],
                'attributes' => [
                    'lang' => 'en', // Custom fild to search
                    'name' => [
                        'name' => SearchLucene::FIELD_TEXT
                    ],
                    'text_intro' => [
                        'text_intro' => SearchLucene::FIELD_UN_STORED
                    ],
                    'text_full' => [
                        'text_full' => SearchLucene::FIELD_UN_STORED
                    ],
                ],
            ]
        ]
    ]
]
```

- Attach the module in your console config file:

```
    'modules' => [
        'search' => 'sadovojav\search\Module'
    ]
```

- Add rules for your urlManager if you need
- Create search index

In console:

`php yii search/search/index`

- Optimize search index

In console:

`php yii search/search/optimyze`

### Use

[](#use)

#### Search controller

[](#search-controller)

```
use Yii;
use yii\data\ArrayDataProvider;

class SearchController extends \yii\web\Controller
{
    const ITEMS_PER_PAGE = 24;

    public function actionIndex($q)
    {
        $query = html_entity_decode(trim($q));

        // Search documents without custom conditions
        // $results = Yii::$app->search->search($query);

        // Search documents with custom conditions (lang)
        $results = Yii::$app->search->search($query, [
            'lang' => Yii::$app->language
        ]);

        $dataProvider = new ArrayDataProvider([
            'allModels' => $results,
            'pagination' => [
                'defaultPageSize' => self::ITEMS_PER_PAGE,
                'forcePageParam' => false
            ]
        ]);

        return $this->render('index', [
            'query' => $query,
            'dataProvider' => $dataProvider
        ]);
    }
}
```

#### Attention

[](#attention-1)

Search component now use default fields

- `class` - model class name with namespase
- `pk` - model primary key

### TODO

[](#todo)

- Create multilanguage behavior for this

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity32

Early-stage or recently created project

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/0c17a869a6d802f11218035a8936a1feb52479d8695584a3a8531442d5ec81bf?d=identicon)[sadovojav](/maintainers/sadovojav)

### Embed Badge

![Health badge](/badges/sadovojav-yii2-search-lucene/health.svg)

```
[![Health](https://phpackages.com/badges/sadovojav-yii2-search-lucene/health.svg)](https://phpackages.com/packages/sadovojav-yii2-search-lucene)
```

###  Alternatives

[ruflin/elastica

Elasticsearch Client

2.3k50.4M203](/packages/ruflin-elastica)[opensearch-project/opensearch-php

PHP Client for OpenSearch

15224.3M65](/packages/opensearch-project-opensearch-php)[mailerlite/laravel-elasticsearch

An easy way to use the official PHP ElasticSearch client in your Laravel applications.

934529.3k2](/packages/mailerlite-laravel-elasticsearch)[massive/search-bundle

Massive Search Bundle

721.4M13](/packages/massive-search-bundle)[shyim/opensearch-php-dsl

OpenSearch/Elasticsearch DSL library

175.9M9](/packages/shyim-opensearch-php-dsl)[outl1ne/nova-multiselect-filter

Multiselect filter for Laravel Nova.

45802.7k3](/packages/outl1ne-nova-multiselect-filter)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
