mfonte/php82-search 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mfonte/php82-search

Composer 安装命令:

composer require mfonte/php82-search

包简介

A Lucene-inspired PHP Search engine library

README 文档

README

A Lucene-inspired PHP Search engine library.

Original Package: https://github.com/VincentFoulon80/php-search.

Internally uses Wamania PHP Snowball Stemmer https://github.com/wamania/php-stemmer

This package was forked to allow PHP 8.2 compatibility.

Installation

install this library via Composer :

composer require mfonte/php82-search

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 for a more complete listing

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 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

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 :

<?php

use MFonte\Search\AdminPanel;

// include the composer autoload file, modify the path if needed
require "vendor/autoload.php";

// securize your file access or directly here
// if($_SERVER['REMOTE_ADDR'] != "127.0.0.1") exit('unauthorized');

// instantiate the panel and then run it
$admin = new AdminPanel();
echo $admin->run();

the AdminPanel's constructor accept as first parameter the same config array as you may use to instanciate the Engine, and you'll want to pass it if you have customized schemas. (or else the panel will not work properly)

More informations in the Admin Panel Manual

License

This library is under the MIT license. See the complete license

mfonte/php82-search 适用场景与选型建议

mfonte/php82-search 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 15 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 02 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「search」 「search engine」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 mfonte/php82-search 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mfonte/php82-search 我们能提供哪些服务?
定制开发 / 二次开发

基于 mfonte/php82-search 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 15
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 14
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-02-20