承接 nourayman/search-json 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

nourayman/search-json

最新稳定版本:v1.0.0

Composer 安装命令:

composer require nourayman/search-json

包简介

Search JSON columns with Arabic character normalization

README 文档

README

Overview

The SearchJson package provides robust search functionality for JSON fields within a Laravel application. It allows you to search for terms in multiple languages across different JSON fields, while also supporting flexible regex patterns to handle Arabic character variations.

Features

  • Search within JSON fields across multiple languages (e.g., ar, en).
  • Supports character normalization for Arabic, so variations of characters like ا, أ, إ, and آ are all matched.

Installation

To install the SearchJson package, simply run the following command:

composer require nourayman/search-json

Usage

  1. Add Searchable Trait to your Model

In your Model, Add traitSearhable to Article Model:

use Nourayman\SearchJson\Searchable;
class Article {
    use Searchable;
    // Your Model Code
}

In your Controller, use the function searchJson directly:

$field = 'title';
$langs = ['ar', 'en'];
$text = 'ألنفسيه';

$results = Article::searchJson($field, $text, $langs);
  1. Customizing Character Variations

The package automatically handles Arabic character normalization. You can further customize this by modifying the buildRegexPattern method in the service class to add new character variations or optional prefixes as needed.

Methods

searchJson($field, $term, array $langs)

  • Description: Searches through specified JSON fields in multiple languages, handling variations in Arabic characters.
  • Parameters:
    • $field: THe JSON field to search within (e.g., title).
    • $term: The search term, which can include any form of Arabic characters.
    • $langs: Languages to search within the JSON fields (e.g., ['ar', 'en']).
  • Returns: Collection of matched results.

Example Query

For a given term like 'ألنفسيه', the package will match:

  • النفسية
  • ألنفسية
  • إلنفسية
  • النفسيه
  • ألنفسيه
  • إلنفسية

This search flexibility is ideal for applications needing robust multi-language support in JSON fields.

Contributing

Contributions are welcome! If you have any bug reports, feature requests, or pull requests, please submit them to the GitHub repository.

License

This package is open-sourced software licensed under the MIT license.

统计信息

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

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-10-15