├── .gitignore ├── LICENSE ├── README.md ├── composer.json ├── composer.lock ├── docs ├── ElasticSearchClient.html ├── ElasticSearchClient │ ├── ElasticSearchClient.html │ └── Mapping.html ├── MySQLWithElasticsearchExceptions.html ├── MySQLWithElasticsearchExceptions │ ├── SearchException.html │ └── SyncMySqlExceptions.html ├── PROJECT_VERSION ├── SAMI_VERSION ├── SearchElastic.html ├── SearchElastic │ ├── Search.html │ ├── SearchAbstract.html │ └── SearchAbstract │ │ └── SearchAbstract.html ├── SyncMySql.html ├── SyncMySql │ ├── Connection.html │ ├── Connection │ │ ├── Connection.html │ │ ├── MySQLiConnection.html │ │ └── PDOConnection.html │ └── SyncMySql.html ├── classes.html ├── css │ ├── bootstrap-theme.min.css │ ├── bootstrap.min.css │ └── sami.css ├── doc-index.html ├── fonts │ ├── glyphicons-halflings-regular.eot │ ├── glyphicons-halflings-regular.svg │ ├── glyphicons-halflings-regular.ttf │ └── glyphicons-halflings-regular.woff ├── index.html ├── interfaces.html ├── js │ ├── bootstrap.min.js │ ├── jquery-1.11.1.min.js │ └── typeahead.min.js ├── namespaces.html ├── opensearch.xml ├── renderer.index ├── sami.js ├── search.html └── traits.html ├── index.php ├── phpunit.xml ├── src ├── ElasticSearchClient │ ├── ElasticSearchClient.php │ └── Mapping.php ├── MySQLWithElasticsearchExceptions │ ├── SearchException.php │ └── SyncMySqlExceptions.php ├── SearchElastic │ ├── Search.php │ └── SearchAbstract │ │ └── SearchAbstract.php └── SyncMySql │ ├── Connection │ ├── Connection.php │ ├── MySQLiConnection.php │ ├── PDOConnection.php │ └── YiiConnection.php │ ├── SyncMySql.php │ └── SyncMySqlYii.php └── tests ├── ElasticSearchClientTest.php ├── MappingTest.php ├── SearchTest.php └── SyncMySqlTest.php /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor/ 2 | index2.php 3 | /.vscode/ 4 | composer.lock 5 | config.php 6 | .php_cs.cache 7 | build 8 | cache 9 | config.php 10 | sami.phar 11 | /.vs/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Ahmed Khan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Connect MySQL With Elasticsearch using PHP 2 | 3 | A small library to connect MySQL with Elasticsearch. Use it to sync data and do full text search. 4 | 5 | Click here to find the [API documentation for v2](https://ahmedkhan847.github.io/mysqlwithelasticsearch) 6 | # Downloading the latest release 7 | 8 | Clone the library 9 | 10 | `git clone -b release2 https://github.com/ahmedkhan847/mysqlwithelasticsearch` 11 | 12 | Now, run `composer install` to install the required dependencies. 13 | 14 | Or use composer to install complete package. 15 | 16 | `composer require ahmedkhan847/mysqlwithelasticsearch:2.*` 17 | 18 | ## What's in release2? 19 | 20 | In release2 package is fully redesign. Now you don't need to pass $config file to constructor. You can set index, type, sql query, sql connection dyamically. Even now you can create your own function for searching in Elasticsearch. Let's see how you can achieve the following: 21 | 22 | * [Mapping in Elasticsearch](https://github.com/ahmedkhan847/mysqlwithelasticsearch/tree/master#mapping-in-elasticsearch) 23 | * [Indexing All MySQL data in Elasticsearch](https://github.com/ahmedkhan847/mysqlwithelasticsearch/tree/master#indexing-all-mysql-data-in-elasticsearch) 24 | * [Indexing All MySQL data in Elasticsearch using MySqli Connection](https://github.com/ahmedkhan847/mysqlwithelasticsearch/tree/master#indexing-all-mysql-data-in-elasticsearch-using-mysqli-connection) 25 | * [Indexing Single Data in Elasticsearch](https://github.com/ahmedkhan847/mysqlwithelasticsearch/tree/master#indexing-single-data-in-elasticsearch) 26 | * [Updating in Elasticsearch](https://github.com/ahmedkhan847/mysqlwithelasticsearch/tree/master#updating-in-elasticsearch) 27 | * [Deleting in Elasticsearch](https://github.com/ahmedkhan847/mysqlwithelasticsearch/tree/master#deleting-data-from-elasticsearch) 28 | * [Searching in Elasticsearch](https://github.com/ahmedkhan847/mysqlwithelasticsearch/tree/master#searching-in-elasticsearch) 29 | * [Creating your own search class for Elasticsearch](https://github.com/ahmedkhan847/mysqlwithelasticsearch/tree/master#creating-your-own-search-class-for-elasticsearch) 30 | 31 | ## Mapping in Elasticsearch 32 | 33 | ```php 34 | 'blog', 40 | 'body' => [ 41 | 'mappings' => [ 42 | 'article' => [ 43 | 'properties' => [ 44 | 'id' => [ 45 | 'type' => 'integer' 46 | ], 47 | 'article_name' => [ 48 | 'type' => 'string' 49 | ], 50 | 'article_content' => [ 51 | 'type' => 'string' 52 | ], 53 | 'article_url' => [ 54 | 'type' => 'string' 55 | ], 56 | 'category_name' => [ 57 | 'type' => 'string' 58 | ], 59 | 'username' => [ 60 | 'type' => 'string' 61 | ], 62 | 'date' => [ 63 | 'type' => 'date', 64 | 'format' => 'dd-MM-yyyy' 65 | ], 66 | 'article_img' => [ 67 | 'type' => 'string' 68 | ], 69 | ] 70 | ] 71 | ] 72 | ] 73 | ]; 74 | $mapping->createMapping($map); 75 | ``` 76 | 77 | ## Indexing All MySQL data in Elasticsearch 78 | ```php 79 | setIndex("blog"); 86 | $sync->setType("users"); 87 | //Where 1st param is the database connection and 2nd param is tableName 88 | $sync->insertAllData($connection, "users"); 89 | echo '
';
 90 | print_r($result);
 91 | echo '
'; 92 | ``` 93 | By default it is using **"SELECT * FROM tablename"**, use **'id'** as a default id column for table and elasticsearch. It is using PDO connection to fetch the data by default. If you want elasticsearch to fetch data using mysqli connection you can also use that you just need to set the connection to `SyncMySql\Connection\MySQLiConnection` or write your own by implementing `SyncMySql\Connection`. Also you can change the select query but don't forget to define an id column in it. Let's see how you can do it. 94 | 95 | ## Indexing All MySQL data in Elasticsearch using MySqli Connection 96 | 97 | ```php 98 | setIndex("blog"); 106 | $sync->setType("article"); 107 | $sync->setConnection(new MySQLiConnection()); 108 | $sync->setSqlQuery("SELECT id,title,body FROM posts"); 109 | //Now you don't need to pass the tablename' 110 | $sync->insertAllData($connection); 111 | echo '
';
112 | print_r($result);
113 | echo '
'; 114 | ``` 115 | ## Indexing Single Data in Elasticsearch 116 | ```php 117 | setIndex("blog"); 125 | $sync->setType("article"); 126 | $sync->setConnection(new MySQLiConnection()); 127 | $result = $sync->insertNode($connection,21,"users"); 128 | echo '
';
129 | print_r($result);
130 | echo '
'; 131 | ``` 132 | If you have want to define you own query then: 133 | 134 | ```php 135 | setIndex("blog"); 143 | $sync->setType("article"); 144 | $sync->setSqlQuery("SELECT id,title,body FROM posts"); 145 | //Now you don't need to pass the tablename' 146 | $result = $sync->insertNode($connection,21); 147 | echo '
';
148 | print_r($result);
149 | echo '
'; 150 | ``` 151 | ## Updating in Elasticsearch 152 | ```php 153 | setIndex("blog"); 161 | $sync->setType("article"); 162 | $result = $sync->updateNode($connection,21,"users"); 163 | echo '
';
164 | print_r($result);
165 | echo '
'; 166 | ``` 167 | Using same technique as we do for insert you can add your own select query using `setSqlQuery()`. 168 | 169 | ## Deleting data from Elasticsearch 170 | ```php 171 | setIndex("blog"); 178 | $sync->setType("article"); 179 | $result = $sync->deleteNode(21); 180 | echo '
';
181 | print_r($result);
182 | echo '
'; 183 | ``` 184 | 185 | ## Searching in Elasticsearch 186 | ```php 187 | setIndex("blog"); 194 | $search->setType("user"); 195 | $search->setSearchColumn("name"); 196 | $result = $search->search("ahmed khan"); 197 | echo '
';
198 | print_r($result);
199 | echo '
'; 200 | ``` 201 | ## Creating your own search class for Elasticsearch 202 | 203 | In order to write your own search you should extends it from `SearchAbstract` class and complete the `public function search($query)` in it. 204 | ```php 205 | validate($query); 222 | //get the elasticsearch client from the base class 223 | $client = $this->client->getClient(); 224 | $result = array(); 225 | /* Write your own query*/ 226 | $params = [ 227 | //you can add your index directly here or use this function if you are planning to set it on runtime $search->setIndex("blog") and then use $this->client->getIndex() to get index 228 | 'index' => "blog", 229 | //you can add your type directly here or use this function if you are planning to set it on runtime using $search->setType("post") and then use $this->client->getIndex() 230 | 'type' => "post", 231 | 'body' => [ 232 | 'query' => [ 233 | 'match' => [ "post" => $query], 234 | ], 235 | ], 236 | ]; 237 | $query = $client->search($params); 238 | // you can use the base method to extract result from the search or return the result directly 239 | return $this->extractResult($query); 240 | } 241 | } 242 | ``` 243 | If you want contribute, fork **master** branch. 244 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ahmedkhan847/mysqlwithelasticsearch", 3 | "description": "A small package to connect MySQL with Elasticsearch", 4 | "keywords": ["mysql with elasticsearch","search in mysql with elasticsearch","connect mysql with elasticsearch"], 5 | "type": "library", 6 | "require": { 7 | "elasticsearch/elasticsearch": ">=2", 8 | "phpunit/phpunit": "5.*" 9 | }, 10 | "license": "MIT", 11 | "authors": [ 12 | { 13 | "name": "Ahmed Khan", 14 | "email": "ahmedkhan_847@hotmail.com" 15 | } 16 | ], 17 | "autoload": { 18 | "psr-4": { 19 | "SearchElastic\\" : "src/SearchElastic/", 20 | "ElasticSearchClient\\" : "src/ElasticSearchClient/", 21 | "SyncMySql\\" : "src/SyncMySql/", 22 | "MySQLWithElasticsearchExceptions\\" : "src/MySQLWithElasticsearchExceptions/" 23 | } 24 | }, 25 | "version": "2.0.0", 26 | "minimum-stability" : "dev" 27 | } 28 | -------------------------------------------------------------------------------- /docs/ElasticSearchClient.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | ElasticSearchClient | API 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 |
25 |
26 | 29 |
30 | 31 | 35 |
36 |
37 | 38 |
39 | 40 |
41 |
42 | 65 | 66 |
67 | 72 |
73 |
74 | 75 | 78 | 79 | 80 |

Classes

81 | 82 |
83 |
84 |
85 | ElasticSearchClient 86 | 87 |
88 |
89 | Class to get Elasticsearch connection. Also used to set and get "index" 90 | and "type" in Elasticsearch 91 |
92 |
93 |
94 |
95 | Mapping 96 | 97 |
98 |
99 | Class to create Maps on Elasticsearch 100 |
101 |
102 |
103 | 104 | 105 | 106 |
107 | 110 | 111 |
112 |
113 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /docs/ElasticSearchClient/ElasticSearchClient.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | ElasticSearchClient\ElasticSearchClient | API 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 |
25 |
26 | 29 |
30 | 31 | 35 |
36 |
37 | 38 |
39 | 40 |
41 |
42 | 65 | 66 |
67 | 73 |
74 |
75 | 76 | 82 | 83 |

class 84 | ElasticSearchClient 85 |

86 | 87 | 88 | 89 | 90 |
91 |

Class to get Elasticsearch connection. Also used to set and get "index" 92 | and "type" in Elasticsearch

93 | 94 | 95 | 96 | 97 |

Methods

98 | 99 |
100 |
101 |
102 | void 103 |
104 |
105 | setIndex(string $index) 106 | 107 |

Set Index to Use in Elasticsearch.

108 |
109 |
110 |
111 |
112 | void 113 |
114 |
115 | setType(string $type) 116 | 117 |

Set Type to use in Elasticsearch

118 |
119 |
120 |
121 |
122 | index 123 |
124 |
125 | getIndex() 126 | 127 |

Get Index to use in Elasticsearch.

128 |
129 |
130 |
131 |
132 | type 133 |
134 |
135 | getType() 136 | 137 |

Get Type to use in Elasticsearch.

138 |
139 |
140 |
141 |
142 | ClientBuilder 143 |
144 |
145 | getClient() 146 | 147 |

Get Elasticsearch Client.

148 |
149 |
150 |
151 | 152 | 153 |

Details

154 | 155 |
156 |
157 |

158 |
at line 23
159 | void 160 | setIndex(string $index) 161 | 162 |

163 |
164 | 165 | 166 | 167 |
168 |

Set Index to Use in Elasticsearch.

169 |
170 |

Parameters

171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 |
string$index
179 | 180 | 181 |

Return Value

182 | 183 | 184 | 185 | 186 | 187 | 188 |
void
189 | 190 | 191 | 192 |
193 |
194 | 195 |
196 |
197 |

198 |
at line 34
199 | void 200 | setType(string $type) 201 | 202 |

203 |
204 | 205 | 206 | 207 |
208 |

Set Type to use in Elasticsearch

209 |
210 |

Parameters

211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 |
string$type
219 | 220 | 221 |

Return Value

222 | 223 | 224 | 225 | 226 | 227 | 228 |
void
229 | 230 | 231 | 232 |
233 |
234 | 235 |
236 |
237 |

238 |
at line 44
239 | index 240 | getIndex() 241 | 242 |

243 |
244 | 245 | 246 | 247 |
248 |

Get Index to use in Elasticsearch.

249 |
250 | 251 |

Return Value

252 | 253 | 254 | 255 | 256 | 257 | 258 |
index
259 | 260 | 261 | 262 |
263 |
264 | 265 |
266 |
267 |

268 |
at line 54
269 | type 270 | getType() 271 | 272 |

273 |
274 | 275 | 276 | 277 |
278 |

Get Type to use in Elasticsearch.

279 |
280 | 281 |

Return Value

282 | 283 | 284 | 285 | 286 | 287 | 288 |
type
289 | 290 | 291 | 292 |
293 |
294 | 295 |
296 |
297 |

298 |
at line 64
299 | ClientBuilder 300 | getClient() 301 | 302 |

303 |
304 | 305 | 306 | 307 |
308 |

Get Elasticsearch Client.

309 |
310 | 311 |

Return Value

312 | 313 | 314 | 315 | 316 | 317 | 318 |
ClientBuilder
319 | 320 | 321 | 322 |
323 |
324 | 325 |
326 |
327 | 328 | 329 |
330 | 333 | 334 |
335 |
336 | 337 | 338 | 339 | -------------------------------------------------------------------------------- /docs/ElasticSearchClient/Mapping.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | ElasticSearchClient\Mapping | API 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 |
25 |
26 | 29 |
30 | 31 | 35 |
36 |
37 | 38 |
39 | 40 |
41 |
42 | 65 | 66 |
67 | 73 |
74 |
75 | 76 | 82 | 83 |

class 84 | Mapping 85 |

86 | 87 | 88 | 89 | 90 |
91 |

Class to create Maps on Elasticsearch

92 | 93 | 94 | 95 | 96 |

Methods

97 | 98 |
99 |
100 |
101 | void 102 |
103 |
104 | __construct() 105 | 106 |

Creating $client for Elasticsearch.

107 |
108 |
109 |
110 |
111 | ElasticSearchClient 112 |
113 |
114 | createMapping(array $map) 115 | 116 |

Create mapping for Elasticsearch.

117 |
118 |
119 |
120 |
121 | ElasticSearchClient 122 |
123 |
124 | deleteMapping($index) 125 | 126 |

Delete the previous mapping by passing its name

127 |
128 |
129 |
130 | 131 | 132 |

Details

133 | 134 |
135 |
136 |

137 |
at line 19
138 | void 139 | __construct() 140 | 141 |

142 |
143 | 144 | 145 | 146 |
147 |

Creating $client for Elasticsearch.

148 |
149 | 150 |

Return Value

151 | 152 | 153 | 154 | 155 | 156 | 157 |
void
158 | 159 | 160 | 161 |
162 |
163 | 164 |
165 |
166 |

167 |
at line 29
168 | ElasticSearchClient 169 | createMapping(array $map) 170 | 171 |

172 |
173 | 174 | 175 | 176 |
177 |

Create mapping for Elasticsearch.

178 |
179 |

Parameters

180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 |
array$mapAn array of elasticsearch mapping
188 | 189 | 190 |

Return Value

191 | 192 | 193 | 194 | 195 | 196 | 197 |
ElasticSearchClient
198 | 199 | 200 | 201 |
202 |
203 | 204 |
205 |
206 |

207 |
at line 46
208 | ElasticSearchClient 209 | deleteMapping($index) 210 | 211 |

212 |
213 | 214 | 215 | 216 |
217 |

Delete the previous mapping by passing its name

218 |
219 |

Parameters

220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 |
$indexName of an exisiting index to delete
228 | 229 | 230 |

Return Value

231 | 232 | 233 | 234 | 235 | 236 | 237 |
ElasticSearchClient
238 | 239 | 240 | 241 |
242 |
243 | 244 |
245 |
246 | 247 | 248 |
249 | 252 | 253 |
254 |
255 | 256 | 257 | 258 | -------------------------------------------------------------------------------- /docs/MySQLWithElasticsearchExceptions.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | MySQLWithElasticsearchExceptions | API 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 |
25 |
26 | 29 |
30 | 31 | 35 |
36 |
37 | 38 |
39 | 40 |
41 |
42 | 65 | 66 |
67 | 72 |
73 |
74 | 75 | 78 | 79 | 80 | 81 | 82 |

Exceptions

83 | 84 |
85 |
86 |
87 | SearchException 88 | 89 |
90 |
91 | Handle exception thrown by Search Elastic 92 |
93 |
94 |
95 |
96 | SyncMySqlExceptions 97 | 98 |
99 |
100 | Handle Exception thrown by SynMySql class 101 |
102 |
103 |
104 | 105 |
106 | 109 | 110 |
111 |
112 | 113 | 114 | 115 | -------------------------------------------------------------------------------- /docs/MySQLWithElasticsearchExceptions/SearchException.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | MySQLWithElasticsearchExceptions\SearchException | API 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 |
25 |
26 | 29 |
30 | 31 | 35 |
36 |
37 | 38 |
39 | 40 |
41 |
42 | 65 | 66 |
67 | 73 |
74 |
75 | 76 | 82 | 83 |

class 84 | SearchException extends Exception 85 |

86 | 87 | 88 | 89 | 90 |
91 |

Handle exception thrown by Search Elastic

92 | 93 | 94 | 95 | 96 |

Methods

97 | 98 |
99 |
100 |
101 | 102 |
103 |
104 | __construct($message, $code, $previous = null) 105 | 106 |

No description

107 |
108 |
109 |
110 |
111 | 112 | 113 |

Details

114 | 115 |
116 |
117 |

118 |
at line 9
119 | 120 | __construct($message, $code, $previous = null) 121 | 122 |

123 |
124 | 125 | 126 | 127 |
128 |

Parameters

129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 |
$message
$code
$previous
147 | 148 | 149 | 150 | 151 |
152 |
153 | 154 |
155 |
156 | 157 | 158 |
159 | 162 | 163 |
164 |
165 | 166 | 167 | 168 | -------------------------------------------------------------------------------- /docs/MySQLWithElasticsearchExceptions/SyncMySqlExceptions.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | MySQLWithElasticsearchExceptions\SyncMySqlExceptions | API 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 |
25 |
26 | 29 |
30 | 31 | 35 |
36 |
37 | 38 |
39 | 40 |
41 |
42 | 65 | 66 |
67 | 73 |
74 |
75 | 76 | 82 | 83 |

class 84 | SyncMySqlExceptions extends Exception 85 |

86 | 87 | 88 | 89 | 90 |
91 |

Handle Exception thrown by SynMySql class

92 | 93 | 94 | 95 | 96 |

Methods

97 | 98 |
99 |
100 |
101 | 102 |
103 |
104 | __construct($message, $code, $previous = null) 105 | 106 |

No description

107 |
108 |
109 |
110 |
111 | 112 | 113 |

Details

114 | 115 |
116 |
117 |

118 |
at line 9
119 | 120 | __construct($message, $code, $previous = null) 121 | 122 |

123 |
124 | 125 | 126 | 127 |
128 |

Parameters

129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 |
$message
$code
$previous
147 | 148 | 149 | 150 | 151 |
152 |
153 | 154 |
155 |
156 | 157 | 158 |
159 | 162 | 163 |
164 |
165 | 166 | 167 | 168 | -------------------------------------------------------------------------------- /docs/PROJECT_VERSION: -------------------------------------------------------------------------------- 1 | master -------------------------------------------------------------------------------- /docs/SAMI_VERSION: -------------------------------------------------------------------------------- 1 | 4.0.1-DEV -------------------------------------------------------------------------------- /docs/SearchElastic.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | SearchElastic | API 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 |
25 |
26 | 29 |
30 | 31 | 35 |
36 |
37 | 38 |
39 | 40 |
41 |
42 | 65 | 66 |
67 | 72 |
73 |
74 | 75 | 78 | 79 |

Namespaces

80 | 82 | 83 |

Classes

84 | 85 |
86 |
87 |
88 | Search 89 | 90 |
91 |
92 | Class to perform basic search extends from SearchElastic\SearchAbstract\SearchAbstract 93 |
94 |
95 |
96 | 97 | 98 | 99 |
100 | 103 | 104 |
105 |
106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /docs/SearchElastic/Search.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | SearchElastic\Search | API 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 |
25 |
26 | 29 |
30 | 31 | 35 |
36 |
37 | 38 |
39 | 40 |
41 |
42 | 65 | 66 |
67 | 73 |
74 |
75 | 76 | 82 | 83 |

class 84 | Search extends SearchAbstract 85 |

86 | 87 | 88 | 89 | 90 |
91 |

Class to perform basic search extends from SearchElastic\SearchAbstract\SearchAbstract

92 | 93 | 94 | 95 |

Properties

96 | 97 | 98 | 99 | 102 | 103 | 104 | 105 | 106 | 107 | 110 | 111 | 112 | 113 | 114 |
100 | protected string|null 101 | $clientfrom SearchAbstract
108 | protected string|null 109 | $searchColumnfrom SearchAbstract
115 | 116 | 117 |

Methods

118 | 119 |
120 |
121 |
122 | 123 |
124 |
125 | __construct() 126 | 127 |

No description

128 |
129 | 130 |
131 |
132 |
133 | void 134 |
135 |
136 | setIndex(string $index) 137 | 138 |

Set Index to Use in Elasticsearch.

139 | 140 |
141 |
142 |
143 | void 144 |
145 |
146 | setType(string $type) 147 | 148 |

Set Type to use in Elasticsearch

149 | 150 |
151 |
152 |
153 | void 154 |
155 |
156 | setSearchColumn(string $value) 157 | 158 |

Set Search Column to use for search in Elasticsearch

159 | 160 |
161 |
162 |
163 | void 164 |
165 |
166 | extractResult($query) 167 | 168 |

Function to extract Search Result From ElasticSearch

169 | 170 |
171 |
172 |
173 | void 174 |
175 |
176 | validate(string $query) 177 | 178 |

Function to validate Search

179 | 180 |
181 |
182 |
183 | search 184 |
185 |
186 | search(string $query) 187 | 188 |

Search in Elasticsearch.

189 |
190 |
191 |
192 | 193 | 194 |

Details

195 | 196 |
197 |
198 |

199 |
in SearchAbstract at line 18
200 | 201 | __construct() 202 | 203 |

204 |
205 | 206 | 207 | 208 |
209 | 210 | 211 | 212 |
213 |
214 | 215 |
216 |
217 |

218 |
in SearchAbstract at line 29
219 | void 220 | setIndex(string $index) 221 | 222 |

223 |
224 | 225 | 226 | 227 |
228 |

Set Index to Use in Elasticsearch.

229 |
230 |

Parameters

231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 |
string$index
239 | 240 | 241 |

Return Value

242 | 243 | 244 | 245 | 246 | 247 | 248 |
void
249 | 250 | 251 | 252 |
253 |
254 | 255 |
256 |
257 |

258 |
in SearchAbstract at line 40
259 | void 260 | setType(string $type) 261 | 262 |

263 |
264 | 265 | 266 | 267 |
268 |

Set Type to use in Elasticsearch

269 |
270 |

Parameters

271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 |
string$type
279 | 280 | 281 |

Return Value

282 | 283 | 284 | 285 | 286 | 287 | 288 |
void
289 | 290 | 291 | 292 |
293 |
294 | 295 |
296 |
297 |

298 |
in SearchAbstract at line 51
299 | void 300 | setSearchColumn(string $value) 301 | 302 |

303 |
304 | 305 | 306 | 307 |
308 |

Set Search Column to use for search in Elasticsearch

309 |
310 |

Parameters

311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 |
string$value
319 | 320 | 321 |

Return Value

322 | 323 | 324 | 325 | 326 | 327 | 328 |
void
329 | 330 | 331 | 332 |
333 |
334 | 335 |
336 |
337 |

338 |
in SearchAbstract at line 62
339 | protected void 340 | extractResult($query) 341 | 342 |

343 |
344 | 345 | 346 | 347 |
348 |

Function to extract Search Result From ElasticSearch

349 |
350 |

Parameters

351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 |
$query
359 | 360 | 361 |

Return Value

362 | 363 | 364 | 365 | 366 | 367 | 368 |
void
369 | 370 | 371 | 372 |
373 |
374 | 375 |
376 |
377 |

378 |
in SearchAbstract at line 82
379 | protected void 380 | validate(string $query) 381 | 382 |

383 |
384 | 385 | 386 | 387 |
388 |

Function to validate Search

389 |
390 |

Parameters

391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 |
string$query
399 | 400 | 401 |

Return Value

402 | 403 | 404 | 405 | 406 | 407 | 408 |
void
409 | 410 | 411 | 412 |
413 |
414 | 415 |
416 |
417 | 423 |
424 | 425 | 426 | 427 |
428 |

Search in Elasticsearch.

429 |
430 |

Parameters

431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 |
string$query
439 | 440 | 441 |

Return Value

442 | 443 | 444 | 445 | 446 | 447 | 448 |
searchresult
449 | 450 | 451 | 452 |
453 |
454 | 455 |
456 |
457 | 458 | 459 |
460 | 463 | 464 |
465 |
466 | 467 | 468 | 469 | -------------------------------------------------------------------------------- /docs/SearchElastic/SearchAbstract.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | SearchElastic\SearchAbstract | API 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 |
25 |
26 | 29 |
30 | 31 | 35 |
36 |
37 | 38 |
39 | 40 |
41 |
42 | 65 | 66 |
67 | 73 |
74 |
75 | 76 | 79 | 80 | 81 |

Classes

82 | 83 |
84 |
85 |
86 | SearchAbstract 87 | 88 |
89 |
90 | An abstract class for searching in Elasticsearch having an abstract search() 91 | which will be implemented when extending from this class. 92 |
93 |
94 |
95 | 96 | 97 | 98 |
99 | 102 | 103 |
104 |
105 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /docs/SearchElastic/SearchAbstract/SearchAbstract.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | SearchElastic\SearchAbstract\SearchAbstract | API 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 |
25 |
26 | 29 |
30 | 31 | 35 |
36 |
37 | 38 |
39 | 40 |
41 |
42 | 65 | 66 |
67 | 74 |
75 |
76 | 77 | 83 | 84 |

class 85 | SearchAbstract 86 |

87 | 88 | 89 | 90 | 91 |
92 |

An abstract class for searching in Elasticsearch having an abstract search()

93 | 94 | 95 | 96 |

Properties

97 | 98 | 99 | 100 | 103 | 104 | 105 | 106 | 107 | 108 | 111 | 112 | 113 | 114 | 115 |
101 | protected string|null 102 | $client
109 | protected string|null 110 | $searchColumn
116 | 117 | 118 |

Methods

119 | 120 |
121 |
122 |
123 | 124 |
125 |
126 | __construct() 127 | 128 |

No description

129 |
130 |
131 |
132 |
133 |
134 | void 135 |
136 |
137 | setIndex(string $index) 138 | 139 |

Set Index to Use in Elasticsearch.

140 |
141 |
142 |
143 |
144 | void 145 |
146 |
147 | setType(string $type) 148 | 149 |

Set Type to use in Elasticsearch

150 |
151 |
152 |
153 |
154 | void 155 |
156 |
157 | setSearchColumn(string $value) 158 | 159 |

Set Search Column to use for search in Elasticsearch

160 |
161 |
162 |
163 |
164 | void 165 |
166 |
167 | extractResult($query) 168 | 169 |

Function to extract Search Result From ElasticSearch

170 |
171 |
172 |
173 |
174 | void 175 |
176 |
177 | validate(string $query) 178 | 179 |

Function to validate Search

180 |
181 |
182 |
183 |
184 | search 185 |
186 |
187 | search(string $query) 188 | 189 |

Abstract function to be implement for search

190 |
191 |
192 |
193 | 194 | 195 |

Details

196 | 197 |
198 |
199 |

200 |
at line 17
201 | 202 | __construct() 203 | 204 |

205 |
206 | 207 | 208 | 209 |
210 | 211 | 212 | 213 |
214 |
215 | 216 |
217 |
218 |

219 |
at line 28
220 | void 221 | setIndex(string $index) 222 | 223 |

224 |
225 | 226 | 227 | 228 |
229 |

Set Index to Use in Elasticsearch.

230 |
231 |

Parameters

232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 |
string$index
240 | 241 | 242 |

Return Value

243 | 244 | 245 | 246 | 247 | 248 | 249 |
void
250 | 251 | 252 | 253 |
254 |
255 | 256 |
257 |
258 |

259 |
at line 39
260 | void 261 | setType(string $type) 262 | 263 |

264 |
265 | 266 | 267 | 268 |
269 |

Set Type to use in Elasticsearch

270 |
271 |

Parameters

272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 |
string$type
280 | 281 | 282 |

Return Value

283 | 284 | 285 | 286 | 287 | 288 | 289 |
void
290 | 291 | 292 | 293 |
294 |
295 | 296 |
297 |
298 |

299 |
at line 50
300 | void 301 | setSearchColumn(string $value) 302 | 303 |

304 |
305 | 306 | 307 | 308 |
309 |

Set Search Column to use for search in Elasticsearch

310 |
311 |

Parameters

312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 |
string$value
320 | 321 | 322 |

Return Value

323 | 324 | 325 | 326 | 327 | 328 | 329 |
void
330 | 331 | 332 | 333 |
334 |
335 | 336 |
337 |
338 |

339 |
at line 61
340 | protected void 341 | extractResult($query) 342 | 343 |

344 |
345 | 346 | 347 | 348 |
349 |

Function to extract Search Result From ElasticSearch

350 |
351 |

Parameters

352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 |
$query
360 | 361 | 362 |

Return Value

363 | 364 | 365 | 366 | 367 | 368 | 369 |
void
370 | 371 | 372 | 373 |
374 |
375 | 376 |
377 |
378 |

379 |
at line 81
380 | protected void 381 | validate(string $query) 382 | 383 |

384 |
385 | 386 | 387 | 388 |
389 |

Function to validate Search

390 |
391 |

Parameters

392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 |
string$query
400 | 401 | 402 |

Return Value

403 | 404 | 405 | 406 | 407 | 408 | 409 |
void
410 | 411 | 412 | 413 |
414 |
415 | 416 |
417 |
418 | 424 |
425 | 426 | 427 | 428 |
429 |

Abstract function to be implement for search

430 |
431 |

Parameters

432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 |
string$query
440 | 441 | 442 |

Return Value

443 | 444 | 445 | 446 | 447 | 448 | 449 |
searchresult
450 | 451 | 452 | 453 |
454 |
455 | 456 |
457 |
458 | 459 | 460 |
461 | 464 | 465 |
466 |
467 | 468 | 469 | 470 | -------------------------------------------------------------------------------- /docs/SyncMySql.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | SyncMySql | API 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 |
25 |
26 | 29 |
30 | 31 | 35 |
36 |
37 | 38 |
39 | 40 |
41 |
42 | 65 | 66 |
67 | 72 |
73 |
74 | 75 | 78 | 79 |

Namespaces

80 | 82 | 83 |

Classes

84 | 85 |
86 |
87 |
88 | SyncMySql 89 | 90 |
91 |
92 | Class to Sync MySQL Database 93 |
94 |
95 |
96 | 97 | 98 | 99 |
100 | 103 | 104 |
105 |
106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /docs/SyncMySql/Connection.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | SyncMySql\Connection | API 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 |
25 |
26 | 29 |
30 | 31 | 35 |
36 |
37 | 38 |
39 | 40 |
41 |
42 | 65 | 66 |
67 | 73 |
74 |
75 | 76 | 79 | 80 | 81 |

Classes

82 | 83 |
84 |
85 |
86 | MySQLiConnection 87 | 88 |
89 |
90 | Class to handle MySqli Object Oriented connection 91 |
92 |
93 |
94 |
95 | PDOConnection 96 | 97 |
98 |
99 | Class to handle PDO connection 100 |
101 |
102 |
103 | 104 |

Interfaces

105 | 106 |
107 |
108 |
109 | Connection 110 | 111 |
112 |
113 | An Interface for database connection classes 114 |
115 |
116 |
117 | 118 | 119 |
120 | 123 | 124 |
125 |
126 | 127 | 128 | 129 | -------------------------------------------------------------------------------- /docs/SyncMySql/Connection/Connection.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | SyncMySql\Connection\Connection | API 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 |
25 |
26 | 29 |
30 | 31 | 35 |
36 |
37 | 38 |
39 | 40 |
41 |
42 | 65 | 66 |
67 | 74 |
75 |
76 | 77 | 83 | 84 |

interface 85 | Connection 86 |

87 | 88 | 89 | 90 | 91 |
92 |

An Interface for database connection classes

93 | 94 | 95 | 96 | 97 |

Methods

98 | 99 |
100 |
101 |
102 | Result 103 |
104 |
105 | getData(string $con, string $query) 106 | 107 |

Get Data From Elasticsearch

108 |
109 |
110 |
111 | 112 | 113 |

Details

114 | 115 |
116 |
117 |

118 |
at line 16
119 | Result 120 | getData(string $con, string $query) 121 | 122 |

123 |
124 | 125 | 126 | 127 |
128 |

Get Data From Elasticsearch

129 |
130 |

Parameters

131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 |
string$conDatabase connectin string
string$querySelect query to get data
144 | 145 | 146 |

Return Value

147 | 148 | 149 | 150 | 151 | 152 | 153 |
Resultfrom database
154 | 155 | 156 | 157 |
158 |
159 | 160 |
161 |
162 | 163 | 164 |
165 | 168 | 169 |
170 |
171 | 172 | 173 | 174 | -------------------------------------------------------------------------------- /docs/SyncMySql/Connection/MySQLiConnection.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | SyncMySql\Connection\MySQLiConnection | API 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 |
25 |
26 | 29 |
30 | 31 | 35 |
36 |
37 | 38 |
39 | 40 |
41 |
42 | 65 | 66 |
67 | 74 |
75 |
76 | 77 | 83 | 84 |

class 85 | MySQLiConnection implements 86 | Connection 87 |

88 | 89 | 90 | 91 | 92 |
93 |

Class to handle MySqli Object Oriented connection

94 | 95 | 96 | 97 | 98 |

Methods

99 | 100 |
101 |
102 |
103 | Result 104 |
105 |
106 | getData(string $con, string $query) 107 | 108 |

Get Data From Elasticsearch

109 |
110 |
111 |
112 | 113 | 114 |

Details

115 | 116 |
117 |
118 |

119 |
at line 18
120 | Result 121 | getData(string $con, string $query) 122 | 123 |

124 |
125 | 126 | 127 | 128 |
129 |

Get Data From Elasticsearch

130 |
131 |

Parameters

132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 |
string$conDatabase connectin string
string$querySelect query to get data
145 | 146 | 147 |

Return Value

148 | 149 | 150 | 151 | 152 | 153 | 154 |
Resultfrom database
155 | 156 | 157 | 158 |
159 |
160 | 161 |
162 |
163 | 164 | 165 |
166 | 169 | 170 |
171 |
172 | 173 | 174 | 175 | -------------------------------------------------------------------------------- /docs/SyncMySql/Connection/PDOConnection.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | SyncMySql\Connection\PDOConnection | API 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 |
25 |
26 | 29 |
30 | 31 | 35 |
36 |
37 | 38 |
39 | 40 |
41 |
42 | 65 | 66 |
67 | 74 |
75 |
76 | 77 | 83 | 84 |

class 85 | PDOConnection implements 86 | Connection 87 |

88 | 89 | 90 | 91 | 92 |
93 |

Class to handle PDO connection

94 | 95 | 96 | 97 | 98 |

Methods

99 | 100 |
101 |
102 |
103 | Result 104 |
105 |
106 | getData(string $con, string $query) 107 | 108 |

Get Data From Elasticsearch

109 |
110 |
111 |
112 | 113 | 114 |

Details

115 | 116 |
117 |
118 |

119 |
at line 18
120 | Result 121 | getData(string $con, string $query) 122 | 123 |

124 |
125 | 126 | 127 | 128 |
129 |

Get Data From Elasticsearch

130 |
131 |

Parameters

132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 |
string$conDatabase connectin string
string$querySelect query to get data
145 | 146 | 147 |

Return Value

148 | 149 | 150 | 151 | 152 | 153 | 154 |
Resultfrom database
155 | 156 | 157 | 158 |
159 |
160 | 161 |
162 |
163 | 164 | 165 |
166 | 169 | 170 |
171 |
172 | 173 | 174 | 175 | -------------------------------------------------------------------------------- /docs/classes.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | All Classes | API 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 |
25 |
26 | 29 |
30 | 31 | 35 |
36 |
37 | 38 |
39 | 40 |
41 |
42 | 65 | 66 |
67 | 70 | 71 | 72 |
73 |
74 |
75 | ElasticSearchClient 76 | 77 |
78 |
79 | Class to get Elasticsearch connection. Also used to set and get "index" 80 | and "type" in Elasticsearch 81 |
82 |
83 |
84 |
85 | Mapping 86 | 87 |
88 |
89 | Class to create Maps on Elasticsearch 90 |
91 |
92 |
93 |
94 | SearchException 95 | 96 |
97 |
98 | Handle exception thrown by Search Elastic 99 |
100 |
101 |
102 |
103 | SyncMySqlExceptions 104 | 105 |
106 |
107 | Handle Exception thrown by SynMySql class 108 |
109 |
110 |
111 |
112 | Search 113 | 114 |
115 |
116 | Class to perform basic search extends from SearchElastic\SearchAbstract\SearchAbstract 117 |
118 |
119 |
120 |
121 | SearchAbstract 122 | 123 |
124 |
125 | An abstract class for searching in Elasticsearch having an abstract search() 126 |
127 |
128 |
129 |
130 | Connection 131 | 132 |
133 |
134 | An Interface for database connection classes 135 |
136 |
137 |
138 |
139 | MySQLiConnection 140 | 141 |
142 |
143 | Class to handle MySqli Object Oriented connection 144 |
145 |
146 |
147 |
148 | PDOConnection 149 | 150 |
151 |
152 | Class to handle PDO connection 153 |
154 |
155 |
156 |
157 | SyncMySql 158 | 159 |
160 |
161 | Class to Sync MySQL Database 162 |
163 |
164 |
165 |
166 | 169 | 170 |
171 |
172 | 173 | 174 | 175 | -------------------------------------------------------------------------------- /docs/css/sami.css: -------------------------------------------------------------------------------- 1 | html, body, #content { 2 | height: 100%; 3 | } 4 | 5 | /* Site menu */ 6 | 7 | #site-nav.navbar-default { 8 | margin: 0; 9 | border-radius: 0; 10 | border-bottom: 1px solid #ccc; 11 | background-color: #EDF3FE; 12 | background-image: none; 13 | } 14 | 15 | #site-nav.navbar-default .navbar-brand, 16 | #site-nav.navbar-default .navbar-nav > li > a { 17 | color: #000; 18 | } 19 | 20 | #site-nav.navbar-default .navbar-nav > li > a:hover { 21 | text-decoration: underline; 22 | } 23 | 24 | #navbar-elements { 25 | float: right; 26 | } 27 | 28 | @media (max-width: 768px) { 29 | #navbar-elements { 30 | float: none !important; 31 | } 32 | } 33 | 34 | /* Namespace breadcrumbs */ 35 | 36 | .namespace-breadcrumbs .breadcrumb { 37 | margin: 0 0 12px; 38 | border-radius: 0 0 4px 4px; 39 | padding-left: 35px; 40 | } 41 | 42 | .namespace-breadcrumbs .breadcrumb > li + li:before { 43 | content: "\\" 44 | } 45 | 46 | /* Site columns */ 47 | 48 | #right-column { 49 | margin-left: 20%; 50 | } 51 | 52 | #page-content { 53 | padding: 0 30px; 54 | } 55 | 56 | #left-column { 57 | width: 20%; 58 | position: fixed; 59 | height: 100%; 60 | border-right: 1px solid #ccc; 61 | line-height: 18px; 62 | font-size: 13px; 63 | display: flex; 64 | flex-flow: column; 65 | } 66 | 67 | @media (max-width: 991px) { 68 | #left-column { 69 | display: none; 70 | } 71 | #right-column { 72 | width: 100%; 73 | margin-left: 0; 74 | } 75 | } 76 | 77 | /* API Tree */ 78 | 79 | #api-tree { 80 | background: linear-gradient( 81 | to bottom, 82 | #FFF, 83 | #FFF 50%, 84 | #EDF3FE 50%, 85 | #EDF3FE 86 | ); 87 | background-size: 100% 56px; 88 | overflow: auto; 89 | height: 100%; 90 | background-attachment: local; 91 | } 92 | 93 | #api-tree ul { 94 | list-style-type: none; 95 | margin: 0; 96 | padding: 0; 97 | } 98 | 99 | #api-tree ul li { 100 | padding: 0; 101 | margin: 0; 102 | } 103 | 104 | /* Prevents the menu from jittering on lad */ 105 | #api-tree .glyphicon-play { 106 | width: 26px; 107 | } 108 | 109 | #api-tree ul li .hd { 110 | padding: 5px; 111 | } 112 | 113 | #api-tree li .hd:nth-child(even) { 114 | background-color: #EDF3FE; 115 | } 116 | 117 | #api-tree ul li.opened > .hd span { 118 | -webkit-transform: rotate(90deg); 119 | -moz-transform: rotate(90deg); 120 | -o-transform: rotate(90deg); 121 | -ms-transform: rotate(90deg); 122 | transform: rotate(90deg); 123 | } 124 | 125 | #api-tree .bd { 126 | display: none; 127 | } 128 | 129 | #api-tree li.opened > .bd { 130 | display: block; 131 | } 132 | 133 | #api-tree li .hd:hover { 134 | background-color: #eee; 135 | } 136 | 137 | #api-tree li.active > .hd { 138 | background-color: #3875D7; 139 | } 140 | 141 | #api-tree li.active > .hd a { 142 | color: #eee; 143 | font-weight: bold; 144 | } 145 | 146 | #api-tree a { 147 | color: #222; 148 | } 149 | 150 | #api-tree div.leaf a { 151 | margin-left: 20px; 152 | } 153 | 154 | #api-tree .hd span { 155 | padding: 2px 8px; 156 | font-size: 10px; 157 | line-height: 85%; 158 | } 159 | 160 | /* Control panel, search form, version drop-down */ 161 | 162 | #control-panel { 163 | background: #e8e8e8; 164 | border-bottom: 1px solid #666; 165 | padding: 4px; 166 | } 167 | 168 | #control-panel form { 169 | margin: 4px 4px 5px 4px; 170 | } 171 | 172 | #search-form { 173 | position: relative; 174 | } 175 | 176 | #search-form input { 177 | width: 100%; 178 | padding-left: 28px; 179 | } 180 | 181 | #search-form span.glyphicon-search { 182 | position: absolute; 183 | left: 9px; 184 | top: 9px; 185 | font-size: 14px; 186 | z-index: 2; 187 | } 188 | 189 | /* Typeahead */ 190 | 191 | .twitter-typeahead { 192 | width: 100%; 193 | z-index: 1; 194 | } 195 | 196 | .tt-dropdown-menu { 197 | overflow: auto; 198 | max-height: 260px; 199 | margin-top: 9px; 200 | background-color: #fff; 201 | border: 1px solid #ccc; 202 | border-radius: 8px; 203 | box-shadow: 0 5px 10px rgba(0,0,0,.2); 204 | padding: 8px; 205 | } 206 | 207 | .tt-dropdown-menu p { 208 | margin: 0; 209 | padding: 0; 210 | } 211 | 212 | .tt-suggestion { 213 | padding: 8px; 214 | border-bottom: 1px solid #ccc; 215 | font-size: 1.1em; 216 | } 217 | 218 | .tt-cursor { 219 | background-color: #3875D7; 220 | color: #fff; 221 | } 222 | 223 | /** General typography **/ 224 | 225 | .navbar { 226 | border-bottom: 0; 227 | } 228 | 229 | .page-header { 230 | margin: 0 0 20px; 231 | } 232 | 233 | abbr[title], abbr[data-original-title], abbr { 234 | border-bottom: none; 235 | cursor: pointer; 236 | } 237 | 238 | a abbr { 239 | cursor: pointer; 240 | } 241 | 242 | /** General Sami styling **/ 243 | 244 | .underlined > .row { 245 | padding: 8px 0; 246 | border-bottom: 1px solid #ddd; 247 | } 248 | 249 | #footer { 250 | text-align: right; 251 | margin: 30px; 252 | font-size: 11px; 253 | } 254 | 255 | .description { 256 | margin: 10px 0; 257 | padding: 10px; 258 | background-color: #efefef; 259 | } 260 | 261 | .description p { 262 | padding: 0; 263 | margin: 8px 0; 264 | } 265 | 266 | .method-description { 267 | margin: 0 0 24px 0; 268 | } 269 | 270 | .details { 271 | padding-left: 30px; 272 | } 273 | 274 | #method-details .method-item { 275 | margin-bottom: 30px; 276 | } 277 | 278 | .method-item h3, 279 | .method-item h3 code { 280 | background-color: #eee; 281 | } 282 | 283 | .method-item h3 { 284 | padding: 4px; 285 | margin-bottom: 20px; 286 | font-size: 20px; 287 | } 288 | 289 | .location { 290 | font-size: 11px; 291 | float: right; 292 | font-style: italic; 293 | } 294 | 295 | .namespace-list a { 296 | padding: 3px 8px; 297 | margin: 0 5px 5px 0; 298 | border: 1px solid #ddd; 299 | background-color: #f9f9f9; 300 | display: inline-block; 301 | border-radius: 4px; 302 | } 303 | 304 | .no-description { 305 | color: #ccc; 306 | font-size: 90%; 307 | } 308 | 309 | /* Namespaces page */ 310 | 311 | .namespaces { 312 | clear: both; 313 | } 314 | 315 | .namespaces .namespace-container { 316 | float: left; 317 | margin: 0 14px 14px 0; 318 | min-width: 30%; 319 | } 320 | 321 | .namespaces h2 { 322 | margin: 0 0 20px 0; 323 | } 324 | 325 | @media (max-width: 991px) { 326 | .namespaces .namespace-container { 327 | margin-right: 0; 328 | width: 100%; 329 | } 330 | } 331 | 332 | /** Code and pre tags **/ 333 | 334 | tt, code, pre { 335 | font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; 336 | } 337 | 338 | code { 339 | padding: 0; 340 | padding-top: 0.2em; 341 | padding-bottom: 0.2em; 342 | margin: 0; 343 | font-size: 85%; 344 | background-color: rgba(0,0,0,0.04); 345 | border-radius: 3px; 346 | color: #333; 347 | } 348 | 349 | pre { 350 | padding: 16px; 351 | overflow: auto; 352 | font-size: 85%; 353 | line-height: 1.45; 354 | background-color: #f7f7f7; 355 | border-radius: 3px; 356 | } 357 | 358 | h2 { 359 | background-color: #EDF3FE; 360 | padding: 4px 4px 4px 8px; 361 | font-size: 25px; 362 | margin: 20px 0; 363 | } 364 | 365 | /** Doc index **/ 366 | 367 | dt { 368 | font-weight: normal; 369 | } 370 | 371 | dd { 372 | margin-left: 30px; 373 | line-height: 1.5em; 374 | } 375 | 376 | #doc-index h2 { 377 | font-weight: bold; 378 | margin: 30px 0; 379 | } 380 | 381 | #doc-index .pagination { 382 | margin: 0; 383 | } 384 | 385 | /* Search page */ 386 | 387 | .search-results { 388 | list-style-type: none; 389 | padding: 0; 390 | margin: 0; 391 | } 392 | 393 | .search-results li { 394 | list-style-type: none; 395 | margin: 0; 396 | padding: 14px 0; 397 | border-bottom: 1px solid #ccc; 398 | } 399 | 400 | .search-results h2 { 401 | background: none; 402 | margin: 0; 403 | padding: 0; 404 | font-size: 18px; 405 | } 406 | 407 | .search-results h2 a { 408 | float: left; 409 | display: block; 410 | margin: 0 0 4px 0; 411 | } 412 | 413 | .search-results .search-type { 414 | float: right; 415 | margin: 0 0 4px 0; 416 | } 417 | 418 | .search-results .search-from { 419 | margin: 0 0 12px 0; 420 | font-size: 12px; 421 | color: #999; 422 | } 423 | 424 | .search-results .search-from a { 425 | font-style: italic; 426 | } 427 | 428 | .search-results .search-description { 429 | margin: 8px 0 0 30px; 430 | } 431 | -------------------------------------------------------------------------------- /docs/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahmedkhan847/mysqlwithelasticsearch/33dead222e31d28d39fc1b4e40a9cb7401262e64/docs/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /docs/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahmedkhan847/mysqlwithelasticsearch/33dead222e31d28d39fc1b4e40a9cb7401262e64/docs/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /docs/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahmedkhan847/mysqlwithelasticsearch/33dead222e31d28d39fc1b4e40a9cb7401262e64/docs/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Namespaces | API 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 |
25 |
26 | 29 |
30 | 31 | 35 |
36 |
37 | 38 |
39 | 40 |
41 |
42 | 65 | 66 |
67 | 70 | 71 |
72 |
73 |

ElasticSearchClient

74 |
77 |

MySQLWithElasticsearchExceptions

78 |
81 |

SearchElastic

82 |
86 |

SyncMySql

87 | 91 |
92 |
93 | 94 |
95 | 98 | 99 |
100 |
101 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /docs/interfaces.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Interfaces | API 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 |
25 |
26 | 29 |
30 | 31 | 35 |
36 |
37 | 38 |
39 | 40 |
41 |
42 | 65 | 66 |
67 | 70 | 71 | 72 |
73 |
74 |
75 | Connection 76 | 77 |
78 |
79 | An Interface for database connection classes 80 |
81 |
82 |
83 |
84 | 87 | 88 |
89 |
90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /docs/namespaces.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Namespaces | API 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 |
25 |
26 | 29 |
30 | 31 | 35 |
36 |
37 | 38 |
39 | 40 |
41 |
42 | 65 | 66 |
67 | 70 | 71 |
72 |
73 |

ElasticSearchClient

74 |
77 |

MySQLWithElasticsearchExceptions

78 |
81 |

SearchElastic

82 |
86 |

SyncMySql

87 | 91 |
92 |
93 | 94 |
95 | 98 | 99 |
100 |
101 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /docs/opensearch.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahmedkhan847/mysqlwithelasticsearch/33dead222e31d28d39fc1b4e40a9cb7401262e64/docs/opensearch.xml -------------------------------------------------------------------------------- /docs/renderer.index: -------------------------------------------------------------------------------- 1 | C:19:"Sami\Renderer\Index":1156:{a:3:{i:0;a:10:{s:39:"ElasticSearchClient\ElasticSearchClient";s:40:"186c8d2c71a0821a31fe81645b3f13e53f70b4d6";s:27:"ElasticSearchClient\Mapping";s:40:"b52099faebfedf4c3e1008ef38dcf03783c837b4";s:48:"MySQLWithElasticsearchExceptions\SearchException";s:40:"5f45085446fc2a9c65f3fdd05426945c598ddb7f";s:52:"MySQLWithElasticsearchExceptions\SyncMySqlExceptions";s:40:"2462be23a26201e3558cae391cd5a1c8c324542b";s:20:"SearchElastic\Search";s:40:"94ef3103c7c7b7149dfa4af5703781b5fbfa99b2";s:43:"SearchElastic\SearchAbstract\SearchAbstract";s:40:"862c7dd6ba047a9e3336befb3136200d48784839";s:31:"SyncMySql\Connection\Connection";s:40:"fd8a0355233f630d6b5561887dd22295683f3956";s:37:"SyncMySql\Connection\MySQLiConnection";s:40:"6a9dbc6fe42668ba2f47be6d89a39f8daf25f6c1";s:34:"SyncMySql\Connection\PDOConnection";s:40:"ed92bb015ea9aa3762fffdab9d494b871547f92f";s:19:"SyncMySql\SyncMySql";s:40:"61188607ba6856b5362efc5f2c823b51ed1d0379";}i:1;a:1:{i:0;s:6:"master";}i:2;a:6:{i:0;s:19:"ElasticSearchClient";i:1;s:32:"MySQLWithElasticsearchExceptions";i:2;s:13:"SearchElastic";i:3;s:28:"SearchElastic\SearchAbstract";i:4;s:9:"SyncMySql";i:5;s:20:"SyncMySql\Connection";}}} -------------------------------------------------------------------------------- /docs/search.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Search | API 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 |
25 |
26 | 29 |
30 | 31 | 35 |
36 |
37 | 38 |
39 | 40 |
41 |
42 | 65 | 66 |
67 | 68 | 71 | 72 |

This page allows you to search through the API documentation for 73 | specific terms. Enter your search words into the box below and click 74 | "submit". The search will be performed on namespaces, classes, interfaces, 75 | traits, functions, and methods.

76 | 77 |
78 |
79 | 80 | 81 |
82 | 83 |
84 | 85 |

Search Results

86 | 87 |
88 |
    89 |
    90 | 91 | 143 | 144 | 145 |
    146 | 149 | 150 |
    151 |
    152 | 153 | 154 | 155 | -------------------------------------------------------------------------------- /docs/traits.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Traits | API 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 |
    24 |
    25 |
    26 | 29 |
    30 | 31 | 35 |
    36 |
    37 | 38 |
    39 | 40 |
    41 |
    42 | 65 | 66 |
    67 | 70 | 71 |
    72 |
    73 |
    74 | 77 | 78 |
    79 |
    80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | setIndex("blog"); 15 | $sync->setType("user"); 16 | $sync->setSearchColumn("name"); 17 | // $sync->setConnection($mysqls); 18 | echo print_r($sync->search("ahmed khan")); 19 | // echo print_r($sync->updateNode($con,'users',21)); 20 | // echo $sync->insertNode([ 21 | // "id" => 5, 22 | // "name0" => "abc", 23 | // "design" => "pattern" 24 | // ]); 25 | 26 | // $search = new Search(); 27 | // $search->setIndex("abc"); 28 | // $search->setType("asd"); 29 | // $search->setSearchColumn("name"); 30 | // echo print_r($search->search("ahmed")); 31 | 32 | // $client = new Mapping(); 33 | // // $map=; 34 | // $mapping = ['index' => 'abc3', 35 | // 'body' => [ 36 | // 'mappings' => [ 37 | // 'article' => [ 38 | // 'properties' => [ 39 | // 'id' => [ 40 | // 'type' => 'integer' 41 | // ], 42 | // 'article_name' => [ 43 | // 'type' => 'string' 44 | // ], 45 | // 'article_content' => [ 46 | // 'type' => 'string' 47 | // ], 48 | // 'article_url' => [ 49 | // 'type' => 'string' 50 | // ], 51 | // 'category_name' => [ 52 | // 'type' => 'string' 53 | // ], 54 | // 'username' => [ 55 | // 'type' => 'string' 56 | // ], 57 | // 'date' => [ 58 | // 'type' => 'date', 59 | // 'format' => 'dd-MM-yyyy' 60 | // ], 61 | // 'article_img' => [ 62 | // 'type' => 'string' 63 | // ], 64 | // ] 65 | // ] 66 | // ] 67 | // ] 68 | // ]; 69 | // echo print_r($client->deleteMapping("abc")); 70 | 71 | $connection = new PDO('mysql:host=localhost;dbname=laravel;','root', ''); 72 | 73 | print_r($connection); -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | tests/ 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/ElasticSearchClient/ElasticSearchClient.php: -------------------------------------------------------------------------------- 1 | index = $index; 26 | } 27 | 28 | /** 29 | * Set Type to use in Elasticsearch 30 | * 31 | * @param string $type 32 | * @return void 33 | */ 34 | public function setType($type) 35 | { 36 | $this->type = $type; 37 | } 38 | 39 | /** 40 | * Get Index to use in Elasticsearch. 41 | * 42 | * @return index 43 | */ 44 | public function getIndex() 45 | { 46 | return $this->index; 47 | } 48 | 49 | /** 50 | * Get Type to use in Elasticsearch. 51 | * 52 | * @return type 53 | */ 54 | public function getType() 55 | { 56 | return $this->type; 57 | } 58 | 59 | /** 60 | * Get Elasticsearch Client. 61 | * 62 | * @return ClientBuilder 63 | */ 64 | public function getClient() 65 | { 66 | return ClientBuilder::create()->build(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/ElasticSearchClient/Mapping.php: -------------------------------------------------------------------------------- 1 | client = new ElasticSearchClient; 22 | } 23 | /** 24 | * Create mapping for Elasticsearch. 25 | * 26 | * @param array $map An array of elasticsearch mapping 27 | * @return \ElasticSearchClient\ElasticSearchClient 28 | */ 29 | public function createMapping(array $map) 30 | { 31 | try { 32 | $elasticclient = $this->client->getClient(); 33 | $response = $elasticclient->indices()->create($map); 34 | return $response['acknowledged']; 35 | } catch (\Exception $ex) { 36 | return $ex->getMessage(); 37 | } 38 | } 39 | 40 | /** 41 | * Delete the previous mapping by passing its name 42 | * 43 | * @param $index Name of an exisiting index to delete 44 | * @return \ElasticSearchClient\ElasticSearchClient 45 | */ 46 | public function deleteMapping($index) 47 | { 48 | try { 49 | $elasticclient = $this->client->getClient(); 50 | $map = ['index' => $index]; 51 | $response = $elasticclient->indices()->delete($map); 52 | return $response['acknowledged']; 53 | } catch (\Exception $ex) { 54 | return $ex->getMessage(); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/MySQLWithElasticsearchExceptions/SearchException.php: -------------------------------------------------------------------------------- 1 | validate($query); 20 | $client = $this->client->getClient(); 21 | $result = array(); 22 | // Change the match column name with the column name you want to search in it. 23 | $params = [ 24 | 'index' => $this->client->getIndex(), 25 | 'type' => $this->client->getType(), 26 | 'body' => [ 27 | 'query' => [ 28 | 'match' => [ $this->searchColumn => $query], 29 | ], 30 | ], 31 | ]; 32 | $query = $client->search($params); 33 | 34 | return $this->extractResult($query); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/SearchElastic/SearchAbstract/SearchAbstract.php: -------------------------------------------------------------------------------- 1 | client = new ElasticSearchClient(); 21 | } 22 | 23 | /** 24 | * Set Index to Use in Elasticsearch. 25 | * 26 | * @param string $index 27 | * @return void 28 | */ 29 | public function setIndex($index) 30 | { 31 | $this->client->setIndex($index); 32 | } 33 | 34 | /** 35 | * Set Type to use in Elasticsearch 36 | * 37 | * @param string $type 38 | * @return void 39 | */ 40 | public function setType($type) 41 | { 42 | $this->client->setType($type); 43 | } 44 | 45 | /** 46 | * Set Search Column to use for search in Elasticsearch 47 | * 48 | * @param string $value 49 | * @return void 50 | */ 51 | public function setSearchColumn($value) 52 | { 53 | $this->searchColumn = $value; 54 | } 55 | 56 | /** 57 | * Function to extract Search Result From ElasticSearch 58 | * 59 | * @param $query 60 | * @return void 61 | */ 62 | protected function extractResult($query) 63 | { 64 | $result = null; 65 | $i = 0; 66 | $hits = sizeof($query['hits']['hits']); 67 | $hit = $query['hits']['hits']; 68 | $result['searchfound'] = $hits; 69 | while ($i < $hits) { 70 | $result['result'][$i] = $query['hits']['hits'][$i]['_source']; 71 | 72 | $i++; 73 | } 74 | return $result; 75 | } 76 | 77 | /** 78 | * Get the total count from a raw result returned by the engine. 79 | * 80 | * @param mixed $results 81 | * @return int 82 | */ 83 | public function getTotalCount($results) 84 | { 85 | return $results['nbHits']; 86 | } 87 | 88 | 89 | /** 90 | * Function to validate Search 91 | * @param string $query 92 | * @return void 93 | */ 94 | protected function validate($query) 95 | { 96 | if ($this->client->getIndex() == null) { 97 | throw new SearchException("Index cannot be null"); 98 | } 99 | if ($this->client->getType() == null) { 100 | throw new SearchException("Type cannot be null"); 101 | } 102 | if ($query == null) { 103 | throw new SearchException("Query can't be null"); 104 | } 105 | } 106 | 107 | /** 108 | * Abstract function to be implement for search 109 | * 110 | * @param string $query 111 | * @return search result 112 | */ 113 | abstract public function search($query); 114 | } 115 | -------------------------------------------------------------------------------- /src/SyncMySql/Connection/Connection.php: -------------------------------------------------------------------------------- 1 | query($query); 21 | return $result->fetch_all(MYSQLI_ASSOC); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/SyncMySql/Connection/PDOConnection.php: -------------------------------------------------------------------------------- 1 | prepare($query); 21 | $stmt->execute(); 22 | return $stmt->fetchAll(\PDO::FETCH_ASSOC); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/SyncMySql/Connection/YiiConnection.php: -------------------------------------------------------------------------------- 1 | $value) { 22 | $data[$key] = $value; 23 | } 24 | return $data; 25 | } 26 | 27 | /** 28 | * Get Data From Elasticsearch 29 | * 30 | * @param string $model Yii2 model 31 | * @param string $query Select query to get data 32 | * @return Result from database 33 | */ 34 | public function getAllData($models, $query = null) 35 | { 36 | $data = []; 37 | foreach ($models as $key => $model) { 38 | foreach ($model as $key2 => $value) { 39 | $data[$key][$key2] = $value; 40 | } 41 | } 42 | return $data; 43 | } 44 | } -------------------------------------------------------------------------------- /src/SyncMySql/SyncMySql.php: -------------------------------------------------------------------------------- 1 | con = new PDOConnection(); 32 | $this->client = new ElasticSearchClient(); 33 | } 34 | 35 | /** 36 | * Set Database Connection. 37 | * 38 | * @param SyncMySql\Connection\Connection $con 39 | * @return void 40 | */ 41 | public function setConnection(Connection $con) 42 | { 43 | $this->con = $con; 44 | } 45 | /** 46 | * Set Index to Use in Elasticsearch. 47 | * 48 | * @param string $index 49 | * @return void 50 | */ 51 | public function setIndex($index) 52 | { 53 | $this->client->setIndex($index); 54 | } 55 | 56 | /** 57 | * Set Type to use in Elasticsearch 58 | * 59 | * @param string $type 60 | * @return void 61 | */ 62 | public function setType($type) 63 | { 64 | $this->client->setType($type); 65 | } 66 | 67 | /** 68 | * Set Id column which will be set as ID in Elasticsearch index 69 | * 70 | * @param string $column 71 | * @return void 72 | */ 73 | public function setIdColumn($column) 74 | { 75 | $this->idColumn = $column; 76 | } 77 | 78 | /** 79 | * Set sqlQuery to get data from database 80 | * 81 | * @param string $sqlQuery Select query for database 82 | * @return void 83 | */ 84 | public function setSqlQuery($sqlQuery) 85 | { 86 | $this->queryChanged = true; 87 | $this->selectQuery = $sqlQuery; 88 | } 89 | 90 | /** 91 | * Sync All data of MySQL in Elasticsearch. 92 | * 93 | * @param $con, $tablename 94 | * @return \ElasticSearchClient\ElasticSearchClient 95 | */ 96 | public function insertAllData($con, $tableName = null) 97 | { 98 | try { 99 | $this->validate(['con' => $con, 'tableName' => $tableName]); 100 | $query = null; 101 | 102 | if ($this->queryChanged) { 103 | $query = $this->selectQuery; 104 | } else { 105 | $query = $this->selectQuery.$tableName; 106 | } 107 | 108 | $allData = $this->con->getData($con, $query); 109 | $params = null; 110 | foreach ($allData as $key => $data) { 111 | $params['body'][] = array( 112 | 'index' => array( 113 | '_index' => $this->client->getIndex(), 114 | '_type' => $this->client->getType(), 115 | '_id' => $data[$this->idColumn], 116 | ), 117 | ); 118 | $params['body'][] = $data; 119 | } 120 | $responses = $this->client->getClient()->bulk($params); 121 | return $responses; 122 | } catch (\Elasticsearch\Common\Exceptions\NoNodesAvailableException $ex) { 123 | throw new SyncMySqlExceptions("Check your elasticsearch connetion"); 124 | } 125 | } 126 | 127 | /** 128 | * Insert single data in Elasticsearch. 129 | * 130 | * @param $con,$tablename 131 | * @return \ElasticSearchClient\ElasticSearchClient 132 | */ 133 | public function insertNode($con, $insertId, $tableName = null) 134 | { 135 | $this->validate(['con' => $con, 'tableName' => $tableName, 'insertId' => $insertId]); 136 | if ($this->queryChanged) { 137 | $query = $this->selectQuery." WHERE ".$this->idColumn." = ". $insertId; 138 | } else { 139 | $query = $this->selectQuery.$tableName." WHERE ".$this->idColumn." = ". $insertId; 140 | } 141 | $data = $this->con->getData($con, $query); 142 | $client = ElasticSearchClient::getClient(); 143 | $params = [ 144 | 'index' => $this->client->getIndex(), 145 | 'type' => $this->client->getType(), 146 | 'id' => $data[0][$this->idColumn], 147 | 'body' => $data[0] 148 | ]; 149 | $responses = $this->client->getClient()->index($params); 150 | return $responses['result']; 151 | } 152 | 153 | /** 154 | * Update single data in Elasticsearch. 155 | * 156 | * @param array $data 157 | * @return \ElasticSearchClient\ElasticSearchClient 158 | */ 159 | public function updateNode($con, $insertId, $tableName = null) 160 | { 161 | $this->validate(['con' => $con, 'tableName' => $tableName, 'insertId' => $insertId]); 162 | 163 | if ($this->queryChanged) { 164 | $query = $this->selectQuery." WHERE ".$this->idColumn." = ". $insertId; 165 | } else { 166 | $query = $this->selectQuery.$tableName." WHERE ".$this->idColumn." = ". $insertId; 167 | } 168 | 169 | $data = $this->con->getData($con, $query); 170 | 171 | $params = [ 172 | 'index' => $this->client->getIndex(), 173 | 'type' => $this->client->getType(), 174 | 'id' => $data[0][$this->idColumn], 175 | 'body' => ['doc' => $data[0]] 176 | ]; 177 | 178 | $responses = $this->client->getClient()->update($params); 179 | return $responses['result']; 180 | } 181 | 182 | /** 183 | * Delete single data from Elasticsearch. 184 | * 185 | * @param int $id 186 | * @return \ElasticSearchClient\ElasticSearchClient 187 | */ 188 | public function deleteNode($id) 189 | { 190 | $this->validate(); 191 | 192 | $params = [ 193 | 'index' => $this->client->getIndex(), 194 | 'type' => $this->client->getType(), 195 | 'id' => $id, 196 | ]; 197 | $responses = $this->client->getClient()->delete($params); 198 | return $responses['result']; 199 | } 200 | 201 | /** 202 | * Validation of $data. 203 | * 204 | * @param array $data 205 | * @return \ElasticSearchClient\ElasticSearchClient 206 | */ 207 | protected function validate(array $data = null) 208 | { 209 | if ($this->client->getIndex() == null) { 210 | throw new SyncMySqlExceptions("Index cannot be null"); 211 | } 212 | if ($this->client->getType() == null) { 213 | throw new SyncMySqlExceptions("Type cannot be null"); 214 | } 215 | if ($data != null) { 216 | if ($data['con'] == null) { 217 | throw new SyncMySqlExceptions("Please provide a valid database connection string"); 218 | } 219 | if ($this->queryChanged == false) { 220 | if (empty($data['tableName'])) { 221 | throw new SyncMySqlExceptions("Please provide a tablename for SELECT query"); 222 | } 223 | } 224 | if (isset($data['insertId'])) { 225 | if (empty($data['insertId'])) { 226 | throw new SyncMySqlExceptions("Please provide the last inserted Id"); 227 | } 228 | } 229 | } 230 | } 231 | } 232 | -------------------------------------------------------------------------------- /src/SyncMySql/SyncMySqlYii.php: -------------------------------------------------------------------------------- 1 | con = new YiiConnection(); 18 | $this->client = new ElasticSearchClient(); 19 | } 20 | 21 | /** 22 | * Sync All data of MySQL in Elasticsearch. 23 | * 24 | * @param $con, $tablename 25 | * @return \ElasticSearchClient\ElasticSearchClient 26 | */ 27 | public function insertAllData($model) 28 | { 29 | try { 30 | $this->validate(['model' => $model]); 31 | $query = null; 32 | 33 | $allData = $this->con->getAllData($model, $query); 34 | $params = null; 35 | foreach ($allData as $key => $data) { 36 | $params['body'][] = array( 37 | 'index' => array( 38 | '_index' => $this->client->getIndex(), 39 | '_type' => $model->tableName(), 40 | '_id' => $data[$this->idColumn], 41 | ), 42 | ); 43 | $params['body'][] = $data; 44 | } 45 | $responses = $this->client->getClient()->bulk($params); 46 | return $responses; 47 | } catch (\Elasticsearch\Common\Exceptions\NoNodesAvailableException $ex) { 48 | throw new SyncMySqlExceptions("Check your elasticsearch connetion"); 49 | } 50 | } 51 | 52 | /** 53 | * Insert single data in Elasticsearch. 54 | * 55 | * @param $con,$tablename 56 | * @return \ElasticSearchClient\ElasticSearchClient 57 | */ 58 | public function insertNode($model) 59 | { 60 | $this->validate(['model' => $model]); 61 | $query = null; 62 | 63 | $data = $this->con->getData($model, $query); 64 | 65 | $params = [ 66 | 'index' => $this->client->getIndex(), 67 | 'type' => $model->tableName(), 68 | 'id' => $data[0][$this->idColumn], 69 | 'body' => $data[0] 70 | ]; 71 | $responses = $this->client->getClient()->index($params); 72 | return $responses['result']; 73 | } 74 | 75 | /** 76 | * Update single data in Elasticsearch. 77 | * 78 | * @param array $data 79 | * @return \ElasticSearchClient\ElasticSearchClient 80 | */ 81 | public function updateNode($model) 82 | { 83 | $this->validate(['model' => $model]); 84 | 85 | $query = null; 86 | 87 | $data = $this->con->getData($con, $query); 88 | 89 | $params = [ 90 | 'index' => $this->client->getIndex(), 91 | 'type' => $model->tableName(), 92 | 'id' => $data[0][$this->idColumn], 93 | 'body' => ['doc' => $data[0]] 94 | ]; 95 | 96 | $responses = $this->client->getClient()->update($params); 97 | return $responses['result']; 98 | } 99 | 100 | /** 101 | * Delete single data from Elasticsearch. 102 | * 103 | * @param int $id 104 | * @return \ElasticSearchClient\ElasticSearchClient 105 | */ 106 | public function deleteNode($model,$id) 107 | { 108 | $this->validate(); 109 | 110 | $params = [ 111 | 'index' => $this->client->getIndex(), 112 | 'type' => $model->tableName(), 113 | 'id' => $id, 114 | ]; 115 | $responses = $this->client->getClient()->delete($params); 116 | return $responses['result']; 117 | } 118 | 119 | /** 120 | * Validation of $data. 121 | * 122 | * @param array $data 123 | * @return \ElasticSearchClient\ElasticSearchClient 124 | */ 125 | protected function validate(array $data = null) 126 | { 127 | if ($this->client->getIndex() == null) { 128 | throw new SyncMySqlExceptions("Index cannot be null"); 129 | } 130 | if ($this->client->getType() == null) { 131 | throw new SyncMySqlExceptions("Type cannot be null"); 132 | } 133 | if ($data != null) { 134 | if ($data['model'] == null) { 135 | throw new SyncMySqlExceptions("Please provide a valid model"); 136 | } 137 | } 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /tests/ElasticSearchClientTest.php: -------------------------------------------------------------------------------- 1 | assertArrayHasKey('transport', (array)$client->getClient()); 17 | } 18 | 19 | public function testSetIndex() 20 | { 21 | $client = new ElasticSearchClient(); 22 | $this->assertEmpty($client->setIndex("index")); 23 | } 24 | 25 | public function testSetType() 26 | { 27 | $client = new ElasticSearchClient(); 28 | $this->assertEmpty($client->setType("asd")); 29 | } 30 | 31 | public function testgetIndex() 32 | { 33 | $client = new ElasticSearchClient(); 34 | $client->setIndex("index"); 35 | $this->assertEquals("index", $client->getIndex()); 36 | } 37 | 38 | public function testGetType() 39 | { 40 | $client = new ElasticSearchClient(); 41 | $client->setType("type"); 42 | $this->assertEquals("type", $client->getType()); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /tests/MappingTest.php: -------------------------------------------------------------------------------- 1 | 'blog', 17 | 'body' => [ 18 | 'mappings' => [ 19 | 'article' => [ 20 | 'properties' => [ 21 | 'id' => [ 22 | 'type' => 'integer' 23 | ], 24 | 'article_name' => [ 25 | 'type' => 'string' 26 | ], 27 | 'article_content' => [ 28 | 'type' => 'string' 29 | ], 30 | 'article_url' => [ 31 | 'type' => 'string' 32 | ], 33 | 'category_name' => [ 34 | 'type' => 'string' 35 | ], 36 | 'username' => [ 37 | 'type' => 'string' 38 | ], 39 | 'date' => [ 40 | 'type' => 'date', 41 | 'format' => 'dd-MM-yyyy' 42 | ], 43 | 'article_img' => [ 44 | 'type' => 'string' 45 | ], 46 | ] 47 | ] 48 | ] 49 | ] 50 | ]; 51 | $this->assertTrue($mapping->createMapping($map)); 52 | } 53 | 54 | public function testDeleteMapping() 55 | { 56 | $mapping = new Mapping(); 57 | $this->assertTrue($mapping->deleteMapping("blog")); 58 | } 59 | 60 | public function testDeleteMappingFail() 61 | { 62 | $mapping = new Mapping(); 63 | $this->assertTrue($mapping->deleteMapping("blog")); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /tests/SearchTest.php: -------------------------------------------------------------------------------- 1 | setIndex("blog"); 17 | $search->setType("user"); 18 | $search->setSearchColumn("name"); 19 | $result = $search->search("ahmed khan"); 20 | $this->assertCount(10, $result['result']); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/SyncMySqlTest.php: -------------------------------------------------------------------------------- 1 | setIndex("blog"); 19 | $sync->setType("user"); 20 | $this->assertArrayHasKey("took", (array)$sync->insertAllData($connection, "users")); 21 | } 22 | 23 | public function testInsertAllDataWithDifferentQuery() 24 | { 25 | $sync = new SyncMySQL(); 26 | $connection = new \PDO('mysql:host=localhost;dbname=laravel;', 'root', ''); 27 | $sync->setIndex("blog"); 28 | $sync->setType("post"); 29 | $sync->setSqlQuery("SELECT id,title,body FROM posts"); 30 | $this->assertArrayHasKey("took", (array)$sync->insertAllData($connection, "users")); 31 | } 32 | 33 | public function testDeleteSingleNode() 34 | { 35 | $sync = new SyncMySQL(); 36 | $sync->setIndex("blog"); 37 | $sync->setType("user"); 38 | $this->assertEquals("deleted", $sync->deleteNode(21)); 39 | } 40 | 41 | public function testInsertSingleNode() 42 | { 43 | $sync = new SyncMySQL(); 44 | $connection = new \PDO('mysql:host=localhost;dbname=laravel;', 'root', ''); 45 | $sync->setIndex("blog"); 46 | $sync->setType("user"); 47 | $this->assertEquals("created", $sync->insertNode($connection, 21, "users")); 48 | } 49 | 50 | public function testUpdateSingleNodeWithMySQLi() 51 | { 52 | $sync = new SyncMySQL(); 53 | $connection = new \mysqli('localhost', 'root', '', 'laravel'); 54 | $sync->setIndex("blog"); 55 | $sync->setType("user"); 56 | $sync->setConnection(new MySQLiConnection()); 57 | //Assert Fails 58 | $this->assertEquals("updated", $sync->updateNode($connection, 21,"users")); 59 | } 60 | } 61 | --------------------------------------------------------------------------------