PHPackages                             mfonte/php82-search - 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. mfonte/php82-search

ActiveLibrary[Search &amp; Filtering](/categories/search)

mfonte/php82-search
===================

A Lucene-inspired PHP Search engine library

v1.0.5(3y ago)115MITPHPPHP &gt;=7.3

Since Feb 21Pushed 3y agoCompare

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

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

Demo
====

[](#demo)

A Lucene-inspired PHP Search engine library.

Original Package: .

Internally uses Wamania PHP Snowball Stemmer

This package was forked to allow **PHP 8.2** compatibility.

Installation
------------

[](#installation)

install this library via Composer :

```
composer require mfonte/php82-search
```

What can it do ?
----------------

[](#what-can-it-do-)

in short :

- indexing and searching documents (with score, fuzzy search and tokenization)
- Stemming and stop-words of 12 supported languages
- Faceting
- Autocompletion
- Connex Search

Take a look at the [Feature Page](https://github.com/VincentFoulon80/php-search/wiki/Features) for a more complete listing

Quick start
-----------

[](#quick-start)

The search engine is packaged with an example schema that allow you to take hand quickly on the library.

at first you need to load the search engine.

```
use MFonte\Search\Engine;

$engine = new Engine();
```

You can give an array in parameter of the class constructor, see [the wiki's configuration page](https://github.com/VincentFoulon80/php-search/wiki/Configuration) for more informations.

By constructing the engine, there'll be some directory that appeared next to your index file :

- var/engine/index
- var/engine/documents
- var/engine/cache

(All these directories can be changed with the configuration array)

At first, you have to give to the engine something to search for. We'll create some documents and ask the engine to index them.

```
$doc = [
    "id" => 1,
    "type" => "example-post",
    "title" => "this is my first blog post !",
    "content" => "I am very happy to post this first post in my blog !",
    "categories" => [
        "party",
        "misc."
    ],
    "date" => "2018/01/01",
    "comments" => [
        [
            "author" => "vincent",
            "date" => "2018/01/01",
            "message" => "Hello world!"
        ],
        [
            "author" => "someone",
            "date" => "2018/01/02",
            "message" => "Welcome !"
        ]
    ]
];
$engine->update($doc);
$doc = [
    "id" => 2,
    "type" => "example-post",
    "title" => "This is the second blog post",
    "content" => "a second one for fun",
    "date" => "2018/01/05",
    "categories" => [
        "misc."
    ],
    "comments" => [
        [
            "author" => "someone",
            "date" => "2018/01/05",
            "message" => "Another one ?!"
        ]
    ]
];
$engine->update($doc);
```

Note : you can also put these two documents in one array and use the updateMultiple() function for indexing multiple documents at once.

Now that you documents are indexed, you can use the search function and fetch results :

```
$response = $engine->search('second post');
var_dump($response);

$response = $engine->search('post');
var_dump($response);
```

For more informations about this library, like using more advanced features, go to [the wiki page of this repository](https://github.com/VincentFoulon80/php-search/wiki)

Admin Panel
-----------

[](#admin-panel)

⚠️ **Warning : This panel does not handle any security by itself. If you use it, it's up to you to prevent the public from accessing it !**

The Admin panel is a class that need to be instantiated and then run. It's not a callable file so you'll need to call it via a regular php file :

```
