Download the PHP package macfja/redisearch-integration without Composer
On this page you can find all versions of the php package macfja/redisearch-integration. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download macfja/redisearch-integration
More information about macfja/redisearch-integration
Files in macfja/redisearch-integration
Package redisearch-integration
Short Description Helper tools to integrate RediSearch in PHP project
License MIT
Informations about the package redisearch-integration
PHP RediSearch Integration
MacFJA/redisearch-integration is a small library to ease usage of MacFJA/redisearch which is a RediSearch client.
Installation
Usage
You will mainly use ObjectManager
(\MacFJA\RediSearch\Integration\ObjectManager
) and ObjectRepository
(\MacFJA\RediSearch\Integration\ObjectRepository
).
This 2 interfaces are bundle into the ObjectWorker
(\MacFJA\RediSearch\Integration\ObkectWorker
) class, to ease usage.
(If you are using a good Injection dependency, you will only need the interface)
Entity Mapping
There are 5 ways to map a PHP class to RediSearch object.
- With annotations (similar to Doctrine ORM)
- With PHP 8 attributes
- With JSON definition
- With XML definition
- By implementing an interface
Annotation and Attribute Mapping
A class is considered as valid if it had at least one field mapping
Annotation | PHP 8 Attribute | Scope | Default |
---|---|---|---|
@Index |
#[Index] |
Class | Class name (with namespace) |
@DocumentId |
#[DocumentId] |
Property or Method | Randomly generate value |
@TextField |
#[TextField] |
Property or Method | None |
@NumericField |
#[NumericField] |
Property or Method | None |
@TagField |
#[TagField] |
Property or Method | None |
@GeoField |
#[GeoField] |
Property or Method | None |
@Suggestion |
#[Suggestion] |
Property or Method | None |
Annotation and PHP 8 attribute mapping are parsed by respectively \MacFJA\RediSearch\Integration\Annotation\AnnotationProvider
and \MacFJA\RediSearch\Integration\Attribute\AttributeProvider
.
The Index
mapping
The @Index(name, [prefix], [stopsWords])
(or #[Index(name, [prefix], [stopsWords])]
for PHP 8 attribute) allow you to specify the index where the class will be put.
If the mapping is missing, the Full Class Qualifier Name (namespace + classname) will be used as index name, not prefix will be used and default StopsWorlds will be used.
The DocumentId
mapping
The @DocumentId
(or #[DocumentId]
for PHP 8 attribute) allow you to specify which hash should be used to identify the document in Redis.
The mapping can be set on a property, or on a method that can be call without any parameter.
If the mapping is missing, a random hash will be generated.
The TextField
mapping
The @TextField([name], [noStem], [weight], [phonetic], [sortable], [noIndex], [unNormalized])
(or #[TextField([name], [noStem], [weight], [phonetic], [sortable], [noIndex], [unNormalized])]
for PHP 8 attribute) allow you to add a text in the search engine.
The mapping can be set on a property, or on a method that can be call without any parameter.
- The
name
parameter is used to specify the name of the data in RediSearch. If missing the property name will be used, or the name of the method base on getter rule (get
/is
). - The
noStem
parameter is a boolean used to indicate if the data should use stemming or not. - The
weight
parameter is a float used to indicate if the weight the data have in result ordering. - The
phonetic
parameter is a string used to indicate the language to use for phonetic search. - The
sortable
parameter is a boolean used to indicate if the data can be used to sort result. - The
noIndex
parameter is a boolean used to indicate if the data should be searchable or not. - The
unNormalized
parameter is a boolean used to indicate if the data should be searchable or not.
The NumericField
mapping
The @NumericField([name], [sortable], [noIndex], [unNormalized])
(or #[NumericField([name], [sortable], [noIndex], [unNormalized])]
for PHP 8 attribute) allow you to add a number in the search engine.
The mapping can be set on a property, or on a method that can be call without any parameter.
- The
name
parameter is used to specify the name of the data in RediSearch. If missing the property name will be used, or the name of the method base on getter rule (get
/is
). - The
sortable
parameter is a boolean used to indicate if the data can be used to sort result. - The
noIndex
parameter is a boolean used to indicate if the data should be searchable or not. - The
unNormalized
parameter is a boolean used to indicate if the data should be searchable or not.
The TagField
mapping
The @TagField([name], [separator], [sortable], [noIndex], [unNormalized])
(or #[TagField([name], [separator], [sortable], [noIndex], [unNormalized])]
for PHP 8 attribute) allow you to add a text in the search engine.
The mapping can be set on a property, or on a method that can be call without any parameter.
- The
name
parameter is used to specify the name of the data in RediSearch. If missing the property name will be used, or the name of the method base on getter rule (get
/is
). - The
separator
parameter is a string used to indicate char to use to separate values. - The
sortable
parameter is a boolean used to indicate if the data can be used to sort result. - The
noIndex
parameter is a boolean used to indicate if the data should be searchable or not. - The
unNormalized
parameter is a boolean used to indicate if the data should be searchable or not.
The data link to TagField
can be a scalar data, or a simple array (one dimension) of scalar
The GeoField
mapping
The @GeoField([name], [noIndex], [sortable], [unNormalized])
(or #[GeoField([name], [noIndex], [sortable], [unNormalized])]
for PHP 8 attribute) allow you to add a geographic (coordinate) in the search engine.
The mapping can be set on a property, or on a method that can be call without any parameter.
- The
name
parameter is used to specify the name of the data in RediSearch. If missing the property name will be used, or the name of the method base on getter rule (get
/is
). - The
noIndex
parameter is a boolean used to indicate if the data should be searchable or not. - The
unNormalized
parameter is a boolean used to indicate if the data should be searchable or not.
The Suggestion
mapping
The @Suggestion([group], [score], [increment], [payload])
(or #[GeoField([group], [score], [increment], [payload])]
for PHP 8 attribute) allow you to add a geographic (coordinate) in the search engine.
The mapping can be set on a property, or on a method that can be call without any parameter.
- The
group
parameter is used to specify the name of the suggestion registry in RediSearch. If missing the name is'suggestion'
. - The
score
parameter is a float used to indicate priority of the value in the suggestion. If missing the score is set to1.0
. - The
increment
parameter is a boolean used to indicate is the score of the current suggestion should be added to an already existing suggestion with the same value. If missing, score are not added. - The
payload
parameter is a string used to add additional data to the suggestion (not used in the suggestion engine). If missing no payload is attach to the suggestion.
JSON Mapping
A JSON mapping file can contain several class mapping. The JSON should respect the Schema.
To enable JSON mapping you must use a \MacFJA\RediSearch\Integration\Json\JsonProvider
.
The JSON PHP extension must also be installed.
The JSON file must be given to the \MacFJA\RediSearch\Integration\Json\JsonProvider::addJson
method.
(The JsonProvider
can be added to a CompositeProvider
)
XML Mapping
A XML mapping file can contain several class mapping. The JSON should respect the XSD Schema.
To enable XML mapping you must use a \MacFJA\RediSearch\Integration\Xml\XmlProvider
.
The SimpleXML PHP extension must also be installed.
The XML file must be given to the \MacFJA\RediSearch\Integration\Xml\XmlProvider::addXml
method.
(The XmlProvider
can be added to a CompositeProvider
)
The interface mapping
You can create your own mapping by implementing the \MacFJA\RediSearch\Integration\Mapping
interface, and add the class to the SimpleProvider
.
(The SimpleProvider
can be added to a CompositeProvider
)
Events
The ObjectWorker
emit several events to allow you to alter its behavior.
Event have separate into two main group: Before and After group. With the Before group you can change configurations before interacting with Redis. The After allow you to do more action with results.
The Before
group
In bold parameters that can be changed.
Event name | ObjectWorker method (Associated Interface) |
Available parameters |
---|---|---|
AddingDocumentToSearchEvent |
persist and persistSearch (ObjectManager ) |
data , documentId , instance (r/o) |
AddingSuggestionEvent |
persist and persistSuggestions (ObjectManager ) |
suggestionMapping , instance (r/o) |
CreatingIndexEvent |
createIndex (ObjectManager ) |
builder , classname (r/o) |
GettingSuggestionsEvent |
getSuggestions (ObjectRepository ) |
classname (r/o), prefix , fuzzy , withScores , withPayloads , max , inGroup |
GettingFacetsEvent |
getFacets (ObjectRepository ) |
classname (r/o), query , fields |
RemovingDocumentFromSearchEvent |
remove (ObjectManager ) |
instance (r/o), documentId |
The After
group
In bold parameters that can be changed.
Event name | ObjectWork method (Associated Interface) |
Available parameters |
---|---|---|
AddingDocumentToSearchEvent |
persist and persistSearch (ObjectManager ) |
data (r/o), documentId (r/o), instance (r/o), update (r/o) |
AddingSuggestionEvent |
persist and persistSuggestions (ObjectManager ) |
group (r/o), suggestion (r/o), score (r/o), increment (r/o), payload (r/o), instance (r/o) |
CreatingIndexEvent |
createIndex (ObjectManager ) |
succeed (r/o), classname (r/o) |
GettingAggregateEvent |
getAggregateCommand (ObjectRepository ) |
aggregate , classname (r/o) |
GettingFacetsEvent |
getFacets (ObjectRepository ) |
classname (r/o), query (r/o), fields (r/o), facets |
GettingSearchEvent |
getSearchCommand (ObjectRepository ) |
search , classname (r/o) |
GettingSuggestionsEvent |
getSuggestions (ObjectRepository ) |
classname (r/o), prefix (r/o), fuzzy (r/o), withScores (r/o), withPayloads (r/o), max (r/o), inGroup (r/o), suggestions |
RemovingDocumentFromSearchEvent |
remove (ObjectManager ) |
instance (r/o), documentId (r/o), succeed (r/o) |
Contributing
You can contribute to the library. To do so, you have Github issues to:
- ask your questions
- suggest new mapping provider
- request any change (typo, bad code, etc.)
- and much more...
You also have PR to:
- add a new mapping provider
- suggest a correction
- and much more...
See CONTRIBUTING for more information.
License
The MIT License (MIT). Please see License File for more information.
All versions of redisearch-integration with dependencies
macfja/redisearch Version ^2.0.0
psr/event-dispatcher Version ^1.0