Download the PHP package nourayman/search-json without Composer
On this page you can find all versions of the php package nourayman/search-json. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nourayman/search-json
More information about nourayman/search-json
Files in nourayman/search-json
Package search-json
Short Description Search JSON columns with Arabic character normalization
License MIT
Informations about the package search-json
SearchJson Laravel Package
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:
Usage
- Add Searchable Trait to your Model
In your Model, Add traitSearhable
to Article Model:
In your Controller, use the function searchJson
directly:
- 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.