<commit_before>#ElasticSearch Mapper (es-mapper)
This is a simple ORM mapper for ElasticSearch on PHP.

##How to use?
That is simple:

### Per index query:
 1. Create a class extending the main query class (for general index use) .
 1. Fill in the abstract methods. They are self-descriptive.
 1. Use the created class ::find($type, $id), ::query($type, array $query =[]), and ::all($type)
    You will get a list of Model objects where you can object-property access to get all the info.
    i.e. $model->name to get the name property, ...

### Per type query
 1. Create a class extending the type query class.
    OR create a class extending the main query class and implement the TypeQueryInterface interface and use the TypeQueryTrait trait
 1. Fill in the abstract methods. They are self-descriptive.
 1. Use the methods: ::find($id), ::all(), and ::query(array $query=[]).
    You will get a list of Model objects the same way described above.

## Adding extra methods
You may need to add extra custom methods like top($numOfDocs) or anything else.
To do so, you need to create the method name you wish as protected in the query sub-class. The name should be prefixed with _ (i.e. `_top`) then, you can either
 * Call it prefixed with `get`, so to call the `_top(500)` method, just call `getTop(500)` and it will be mapped as public static and as public. 
 * Override the _allowPublicAccess static protected method to add extra methods to expose. 
    Please note that when overriding, don't forget to merge with the parent results not to lose the old ones:
    ```PHP
    protected _allowPublicAccess(){
        return array_merge(parent::_allowPublicAccess(), ['top','any',...]);
    }
    ```

    This way you will save the allowed methods from the parent.

### Extending the Model class
You can extend the Model class easily. Just extend it!
In case you were using the namespaces, you can set the models namespace in the query class by overriding the modelNamespace public method. This method should return a string ending with \

##Examples
Please check [tests/](/tests) folder. Basically, the case1.php is the main file.

```
\
|
+-- TestsIndexQuery (TestsIndexQuery.php)   Main index query class.
|   |                                       Maps results to \Models\ namespace.
|   |
|   +-- \FooTypeQuery (FooTypeQuery.php)    Type index query class.<commit_msg>Update the readme<commit_after>#ElasticSearch Mapper (es-mapper)
This is a simple ORM mapper for ElasticSearch on PHP.

##How to use?
That is simple:

### Per index query:
 1. Create a class extending the main query class (for general index use) .
 1. Fill in the abstract methods. They are self-descriptive.
 1. Use the created class ::find($type, $id), ::query($type, array $query =[]), and ::all($type)
    You will get a list of Model objects where you can object-property access to get all the info.
    i.e. $model->name to get the name property, ...

### Per type query
 1. Create a class extending the type query class.
    OR create a class extending the main query class and implement the TypeQueryInterface interface and use the TypeQueryTrait trait
 1. Fill in the abstract methods. They are self-descriptive.
 1. Use the methods: ::find($id), ::all(), and ::query(array $query=[]).
    You will get a list of Model objects the same way described above.

#### Please note
Methods' parameters are mapped to original elasticsearch methods and parameters as follows:
 * ::find(scalar) and ::find(array) methods are mapped to [get](https://github.com/elastic/elasticsearch-php/blob/master/src/Elasticsearch/Client.php#L167) and [mget](https://github.com/elastic/elasticsearch-php/blob/master/src/Elasticsearch/Client.php#L671) methods respectively.
 * ::query method is mapped to the [search](https://github.com/elastic/elasticsearch-php/blob/master/src/Elasticsearch/Client.php#L1002) method, and the $query param will be passed as is after appending the index and type parameters to it.

## Adding extra methods
You may need to add extra custom methods like top($numOfDocs) or anything else.
To do so, you need to create the method name you wish as protected in the query sub-class. The name should be prefixed with _ (i.e. `_top`) then, you can either
 * Call it prefixed with `get`, so to call the `_top(500)` method, just call `getTop(500)` and it will be mapped as public static and as public. 
 * Override the _allowPublicAccess static protected method to add extra methods to expose. 
    Please note that when overriding, don't forget to merge with the parent results not to lose the old ones:
    ```PHP
    protected _allowPublicAccess(){
        return array_merge(parent::_allowPublicAccess(), ['top','any',...]);
    }
    ```

    This way you will save the allowed methods from the parent.

### Extending the Model class
You can extend the Model class easily. Just extend it!
In case you were using the namespaces, you can set the models namespace in the query class by overriding the modelNamespace public method. This method should return a string ending with \

##Examples
Please check [tests/](/tests) folder. Basically, the case1.php is the main file.

```
\
|
+-- TestsIndexQuery (TestsIndexQuery.php)   Main index query class.
|   |                                       Maps results to \Models\ namespace.
|   |
|   +-- \FooTypeQuery (FooTypeQuery.php)    Type index query class.
{'fraction_non_alphanumeric': 0.09021718953035085, 'fraction_numerical': 0.006682754780025988, 'mean_word_length': 3.640826873385013, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1229962', 'n_tokens_mistral': 1487, 'n_tokens_neox': 1426, 'n_words': 725}