PageRenderTime 51ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/README.MD

https://gitlab.com/mehdi-zarrin/Stretchy
Markdown | 179 lines | 151 code | 28 blank | 0 comment | 0 complexity | 782ed0c0ed4dc513a3fa83f47bf82e7f MD5 | raw file
  1. Stretchy
  2. =========
  3. [![Build Status](https://travis-ci.org/ErickTamayo/Stretchy.svg?branch=master)](https://travis-ci.org/ErickTamayo/Stretchy)
  4. Stretchy in an [Elasticsearch] integration for Laravel.
  5. Heavily Inspired by Query Builder and Schema of laravel.
  6. Description on going.
  7. ### Version
  8. 0.0.1 (Alpha)
  9. ### Documentation
  10. The current documentation is at [stretchy.readthedocs.org](http://stretchy.readthedocs.org/).
  11. #Installation
  12. ###Requirements
  13. - PHP 5.4+
  14. ### Installing with Composer
  15. 1. In your **composer.json**, add the dependency: `"tamayo/stretchy": "dev-master"`
  16. 2. Add the Stretchy service provider in your app.config:
  17. ```php
  18. 'Tamayo\Stretchy\StretchyServiceProvider'
  19. ```
  20. 3. Add the following aliases:
  21. ```php
  22. 'Index' => 'Tamayo\Stretchy\Facades\Index',
  23. 'Document' => 'Tamayo\Stretchy\Facades\Document',
  24. 'Stretchy' => 'Tamayo\Stretchy\Facades\Stretchy'
  25. ```
  26. 4. (Optional) If you want to override the default configuration:
  27. ```sh
  28. php artisan config:publish tamayo/stretchy
  29. ```
  30. Located in your laravel config directory: **packages/tamayo/stretchy/config.php**
  31. ##Quick Examples
  32. ####Create Index
  33. To create a basic index just do the following:
  34. ```php
  35. Index::create('foo');
  36. ```
  37. If you want to specify shards and replicas:
  38. ```php
  39. Index::create('foo', function($index)
  40. {
  41. $index->shards(5);
  42. $index->replicas(1);
  43. });
  44. ```
  45. ####Delete Index
  46. ```php
  47. Index::delete('foo');
  48. ```
  49. ####Document indexing
  50. ```php
  51. Document::index('foo')
  52. ->type('tweet')
  53. ->id(13) // Optional (if not specified elastic will generate an unique id)
  54. ->insert([
  55. 'username' => '@ericktamayo',
  56. 'tweet' => 'Hello world!'
  57. ]);
  58. ```
  59. ####Update a document
  60. ```php
  61. Document::index('foo')
  62. ->type('tweet')
  63. ->id(13)
  64. ->update(['tweet' => 'Hello world!!!']);
  65. ```
  66. ####Get a document
  67. ```php
  68. Document::index('foo')->type('tweet')->Id(13)->get();
  69. ```
  70. ####Delete a document
  71. ```php
  72. Document::index('foo')->type('tweet')->Id(13)->delete();
  73. ```
  74. ###Searching
  75. #####Match Query
  76. ```php
  77. Stretchy::search('foo')->match('bar', 'Stretchy')->get();
  78. ```
  79. To provide additional parameters:
  80. ```php
  81. Stretchy::search('foo')
  82. ->match('bar', 'baz', ['operator' => 'and', 'zero_terms_query' => 'all'])
  83. ->get();
  84. ```
  85. or
  86. ```php
  87. Stretchy::search('foo')
  88. ->match('bar', 'Stretchy', function($match)
  89. {
  90. $match->operator('and');
  91. $match->zeroTermsQuery('all');
  92. $match->cutoffFrequency(0.001);
  93. })
  94. ->get();
  95. ```
  96. #####Term Query
  97. ```php
  98. Stretchy::search('foo')->term('bar', 'baz')->get();
  99. ```
  100. To provide additional parameters:
  101. ```php
  102. Stretchy::search('foo')->term('bar', 'baz', ['boost' => 2])->get();
  103. ```
  104. or
  105. ```php
  106. Stretchy::search('foo')
  107. ->term('bar', 'baz', function($term)
  108. {
  109. $term->boost(2);
  110. })
  111. ->get();
  112. ```
  113. #####Bool Query
  114. ```php
  115. Stretchy::search('foo')
  116. ->bool(function($query)
  117. {
  118. $query->must(function($must)
  119. {
  120. $must->match('bar', 'baz');
  121. });
  122. $query->mustNot(function($mustNot)
  123. {
  124. $mustNot->match('bar', 'qux');
  125. });
  126. $query->should(function($should)
  127. {
  128. $should->match('bar', 'bah');
  129. });
  130. $query->minimumShouldMatch(1);
  131. })
  132. ->get();
  133. ```
  134. More examples can be found in the [documentation](http://stretchy.readthedocs.org/).
  135. ### Roadmap
  136. - **Documentation**
  137. - **Index API I(Basic)**
  138. - **Elastic Query Builder (Search API)**
  139. - **Leverage Models**
  140. - Model traits
  141. - **PutMapping Wrapper**
  142. - **Leverage Laravel Migrations**
  143. - Migrations with PutMaping
  144. - **Advanced models and relations**
  145. - Search and rebuild model from results and it's relationships
  146. - **Index API II (Advanced)**
  147. ###Author
  148. Erick Tamayo - [ericktamayo@gmail.com](mailto:ericktamayo@gmail.com) - [@ericktamayo](http://twitter.com/ericktamayo)
  149. ### License
  150. MIT
  151. [ElasticSearch]:http://www.elasticsearch.org/