Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Client often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Client, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 38 | class Client |
||
| 39 | { |
||
| 40 | /** |
||
| 41 | * Searchd host |
||
| 42 | * |
||
| 43 | * @var string |
||
| 44 | */ |
||
| 45 | protected $host = 'localhost'; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Searchd port |
||
| 49 | * |
||
| 50 | * @var int |
||
| 51 | */ |
||
| 52 | protected $port = 9312; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * How many records to seek from result-set start |
||
| 56 | * |
||
| 57 | * @var int |
||
| 58 | */ |
||
| 59 | protected $offset = 0; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * How many records to return from result-set starting at offset |
||
| 63 | * |
||
| 64 | * @var int |
||
| 65 | */ |
||
| 66 | protected $limit = 20; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Query matching mode |
||
| 70 | * |
||
| 71 | * @var int |
||
| 72 | */ |
||
| 73 | protected $mode = self::MATCH_EXTENDED2; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Per-field weights (default is 1 for all fields) |
||
| 77 | * |
||
| 78 | * @var array |
||
| 79 | */ |
||
| 80 | protected $weights = array(); |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Match sorting mode |
||
| 84 | * |
||
| 85 | * @var int |
||
| 86 | */ |
||
| 87 | protected $sort = self::SORT_RELEVANCE; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Attribute to sort by |
||
| 91 | * |
||
| 92 | * @var string |
||
| 93 | */ |
||
| 94 | protected $sort_by = ''; |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Min ID to match (0 means no limit) |
||
| 98 | * |
||
| 99 | * @var int |
||
| 100 | */ |
||
| 101 | protected $min_id = 0; |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Max ID to match (0 means no limit) |
||
| 105 | * |
||
| 106 | * @var int |
||
| 107 | */ |
||
| 108 | protected $max_id = 0; |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Search filters |
||
| 112 | * |
||
| 113 | * @var array |
||
| 114 | */ |
||
| 115 | protected $filters = array(); |
||
| 116 | |||
| 117 | /** |
||
| 118 | * Group-by attribute name |
||
| 119 | * |
||
| 120 | * @var string |
||
| 121 | */ |
||
| 122 | protected $group_by = ''; |
||
| 123 | |||
| 124 | /** |
||
| 125 | * Group-by function (to pre-process group-by attribute value with) |
||
| 126 | * |
||
| 127 | * @var int |
||
| 128 | */ |
||
| 129 | protected $group_func = self::GROUP_BY_DAY; |
||
| 130 | |||
| 131 | /** |
||
| 132 | * Group-by sorting clause (to sort groups in result set with) |
||
| 133 | * |
||
| 134 | * @var string |
||
| 135 | */ |
||
| 136 | protected $group_sort = '@group desc'; |
||
| 137 | |||
| 138 | /** |
||
| 139 | * Group-by count-distinct attribute |
||
| 140 | * |
||
| 141 | * @var string |
||
| 142 | */ |
||
| 143 | protected $group_distinct = ''; |
||
| 144 | |||
| 145 | /** |
||
| 146 | * Max matches to retrieve |
||
| 147 | * |
||
| 148 | * @var int |
||
| 149 | */ |
||
| 150 | protected $max_matches = 1000; |
||
| 151 | |||
| 152 | /** |
||
| 153 | * Cutoff to stop searching at |
||
| 154 | * |
||
| 155 | * @var int |
||
| 156 | */ |
||
| 157 | protected $cutoff = 0; |
||
| 158 | |||
| 159 | /** |
||
| 160 | * Distributed retries count |
||
| 161 | * |
||
| 162 | * @var int |
||
| 163 | */ |
||
| 164 | protected $retry_count = 0; |
||
| 165 | |||
| 166 | /** |
||
| 167 | * Distributed retries delay |
||
| 168 | * |
||
| 169 | * @var int |
||
| 170 | */ |
||
| 171 | protected $retry_delay = 0; |
||
| 172 | |||
| 173 | /** |
||
| 174 | * Geographical anchor point |
||
| 175 | * |
||
| 176 | * @var array |
||
| 177 | */ |
||
| 178 | protected $anchor = array(); |
||
| 179 | |||
| 180 | /** |
||
| 181 | * Per-index weights |
||
| 182 | * |
||
| 183 | * @var array |
||
| 184 | */ |
||
| 185 | protected $index_weights = array(); |
||
| 186 | |||
| 187 | /** |
||
| 188 | * Ranking mode |
||
| 189 | * |
||
| 190 | * @var int |
||
| 191 | */ |
||
| 192 | protected $ranker = self::RANK_PROXIMITY_BM25; |
||
| 193 | |||
| 194 | /** |
||
| 195 | * Ranking mode expression (for self::RANK_EXPR) |
||
| 196 | * |
||
| 197 | * @var string |
||
| 198 | */ |
||
| 199 | protected $rank_expr = ''; |
||
| 200 | |||
| 201 | /** |
||
| 202 | * Max query time, milliseconds (0 means no limit) |
||
| 203 | * |
||
| 204 | * @var int |
||
| 205 | */ |
||
| 206 | protected $max_query_time = 0; |
||
| 207 | |||
| 208 | /** |
||
| 209 | * Per-field-name weights |
||
| 210 | * |
||
| 211 | * @var array |
||
| 212 | */ |
||
| 213 | protected $field_weights = array(); |
||
| 214 | |||
| 215 | /** |
||
| 216 | * Per-query attribute values overrides |
||
| 217 | * |
||
| 218 | * @var array |
||
| 219 | */ |
||
| 220 | protected $overrides = array(); |
||
| 221 | |||
| 222 | /** |
||
| 223 | * Select-list (attributes or expressions, with optional aliases) |
||
| 224 | * |
||
| 225 | * @var string |
||
| 226 | */ |
||
| 227 | protected $select = '*'; |
||
| 228 | |||
| 229 | /** |
||
| 230 | * Per-query various flags |
||
| 231 | * |
||
| 232 | * @var int |
||
| 233 | */ |
||
| 234 | protected $query_flags = 0; |
||
| 235 | |||
| 236 | /** |
||
| 237 | * Per-query max_predicted_time |
||
| 238 | * |
||
| 239 | * @var int |
||
| 240 | */ |
||
| 241 | protected $predicted_time = 0; |
||
| 242 | |||
| 243 | /** |
||
| 244 | * Outer match sort by |
||
| 245 | * |
||
| 246 | * @var string |
||
| 247 | */ |
||
| 248 | protected $outer_order_by = ''; |
||
| 249 | |||
| 250 | /** |
||
| 251 | * Outer offset |
||
| 252 | * |
||
| 253 | * @var int |
||
| 254 | */ |
||
| 255 | protected $outer_offset = 0; |
||
| 256 | |||
| 257 | /** |
||
| 258 | * Outer limit |
||
| 259 | * |
||
| 260 | * @var int |
||
| 261 | */ |
||
| 262 | protected $outer_limit = 0; |
||
| 263 | |||
| 264 | /** |
||
| 265 | * @var bool |
||
| 266 | */ |
||
| 267 | protected $has_outer = false; |
||
| 268 | |||
| 269 | /** |
||
| 270 | * Last error message |
||
| 271 | * |
||
| 272 | * @var string |
||
| 273 | */ |
||
| 274 | protected $error = ''; |
||
| 275 | |||
| 276 | /** |
||
| 277 | * Last warning message |
||
| 278 | * |
||
| 279 | * @var string |
||
| 280 | */ |
||
| 281 | protected $warning = ''; |
||
| 282 | |||
| 283 | /** |
||
| 284 | * Connection error vs remote error flag |
||
| 285 | * |
||
| 286 | * @var bool |
||
| 287 | */ |
||
| 288 | protected $conn_error = false; |
||
| 289 | |||
| 290 | /** |
||
| 291 | * Requests array for multi-query |
||
| 292 | * |
||
| 293 | * @var array |
||
| 294 | */ |
||
| 295 | protected $reqs = array(); |
||
| 296 | |||
| 297 | /** |
||
| 298 | * Stored mbstring encoding |
||
| 299 | * |
||
| 300 | * @var string |
||
| 301 | */ |
||
| 302 | protected $mbenc = ''; |
||
| 303 | |||
| 304 | /** |
||
| 305 | * Whether $result['matches'] should be a hash or an array |
||
| 306 | * |
||
| 307 | * @var bool |
||
| 308 | */ |
||
| 309 | protected $array_result = false; |
||
| 310 | |||
| 311 | /** |
||
| 312 | * Connect timeout |
||
| 313 | * |
||
| 314 | * @var int |
||
| 315 | */ |
||
| 316 | protected $timeout = 0; |
||
| 317 | |||
| 318 | /** |
||
| 319 | * @var bool |
||
| 320 | */ |
||
| 321 | protected $path = false; |
||
| 322 | |||
| 323 | /** |
||
| 324 | * @var resource|bool |
||
| 325 | */ |
||
| 326 | protected $socket = false; |
||
| 327 | |||
| 328 | // known searchd commands |
||
| 329 | const SEARCHD_COMMAND_SEARCH = 0; |
||
| 330 | const SEARCHD_COMMAND_EXCERPT = 1; |
||
| 331 | const SEARCHD_COMMAND_UPDATE = 2; |
||
| 332 | const SEARCHD_COMMAND_KEYWORDS = 3; |
||
| 333 | const SEARCHD_COMMAND_PERSIST = 4; |
||
| 334 | const SEARCHD_COMMAND_STATUS = 5; |
||
| 335 | const SEARCHD_COMMAND_FLUSH_ATTRS = 7; |
||
| 336 | |||
| 337 | // current client-side command implementation versions |
||
| 338 | const VER_COMMAND_SEARCH = 0x11E; |
||
| 339 | const VER_COMMAND_EXCERPT = 0x104; |
||
| 340 | const VER_COMMAND_UPDATE = 0x103; |
||
| 341 | const VER_COMMAND_KEYWORDS = 0x100; |
||
| 342 | const VER_COMMAND_STATUS = 0x101; |
||
| 343 | const VER_COMMAND_QUERY = 0x100; |
||
| 344 | const VER_COMMAND_FLUSH_ATTRS = 0x100; |
||
| 345 | |||
| 346 | // known searchd status codes |
||
| 347 | const SEARCHD_OK = 0; |
||
| 348 | const SEARCHD_ERROR = 1; |
||
| 349 | const SEARCHD_RETRY = 2; |
||
| 350 | const SEARCHD_WARNING = 3; |
||
| 351 | |||
| 352 | // known match modes |
||
| 353 | const MATCH_ALL = 0; |
||
| 354 | const MATCH_ANY = 1; |
||
| 355 | const MATCH_PHRASE = 2; |
||
| 356 | const MATCH_BOOLEAN = 3; |
||
| 357 | const MATCH_EXTENDED = 4; |
||
| 358 | const MATCH_FULL_SCAN = 5; |
||
| 359 | const MATCH_EXTENDED2 = 6; // extended engine V2 (TEMPORARY, WILL BE REMOVED) |
||
| 360 | |||
| 361 | // known ranking modes (ext2 only) |
||
| 362 | const RANK_PROXIMITY_BM25 = 0; // default mode, phrase proximity major factor and BM25 minor one |
||
| 363 | const RANK_BM25 = 1; // statistical mode, BM25 ranking only (faster but worse quality) |
||
| 364 | const RANK_NONE = 2; // no ranking, all matches get a weight of 1 |
||
| 365 | const RANK_WORD_COUNT = 3; // simple word-count weighting, rank is a weighted sum of per-field keyword |
||
| 366 | // occurrence counts |
||
| 367 | const RANK_PROXIMITY = 4; |
||
| 368 | const RANK_MATCH_ANY = 5; |
||
| 369 | const RANK_FIELD_MASK = 6; |
||
| 370 | const RANK_SPH04 = 7; |
||
| 371 | const RANK_EXPR = 8; |
||
| 372 | const RANK_TOTAL = 9; |
||
| 373 | |||
| 374 | // known sort modes |
||
| 375 | const SORT_RELEVANCE = 0; |
||
| 376 | const SORT_ATTR_DESC = 1; |
||
| 377 | const SORT_ATTR_ASC = 2; |
||
| 378 | const SORT_TIME_SEGMENTS = 3; |
||
| 379 | const SORT_EXTENDED = 4; |
||
| 380 | const SORT_EXPR = 5; |
||
| 381 | |||
| 382 | // known filter types |
||
| 383 | const FILTER_VALUES = 0; |
||
| 384 | const FILTER_RANGE = 1; |
||
| 385 | const FILTER_FLOAT_RANGE = 2; |
||
| 386 | const FILTER_STRING = 3; |
||
| 387 | |||
| 388 | // known attribute types |
||
| 389 | const ATTR_INTEGER = 1; |
||
| 390 | const ATTR_TIMESTAMP = 2; |
||
| 391 | const ATTR_ORDINAL = 3; |
||
| 392 | const ATTR_BOOL = 4; |
||
| 393 | const ATTR_FLOAT = 5; |
||
| 394 | const ATTR_BIGINT = 6; |
||
| 395 | const ATTR_STRING = 7; |
||
| 396 | const ATTR_FACTORS = 1001; |
||
| 397 | const ATTR_MULTI = 0x40000001; |
||
| 398 | const ATTR_MULTI64 = 0x40000002; |
||
| 399 | |||
| 400 | // known grouping functions |
||
| 401 | const GROUP_BY_DAY = 0; |
||
| 402 | const GROUP_BY_WEEK = 1; |
||
| 403 | const GROUP_BY_MONTH = 2; |
||
| 404 | const GROUP_BY_YEAR = 3; |
||
| 405 | const GROUP_BY_ATTR = 4; |
||
| 406 | const GROUP_BY_ATTR_PAIR = 5; |
||
| 407 | |||
| 408 | ///////////////////////////////////////////////////////////////////////////// |
||
| 409 | // common stuff |
||
| 410 | ///////////////////////////////////////////////////////////////////////////// |
||
| 411 | |||
| 412 | 4 | public function __construct() |
|
| 417 | |||
| 418 | public function __destruct() |
||
| 424 | |||
| 425 | /** |
||
| 426 | * @return string |
||
| 427 | */ |
||
| 428 | 1 | public function getLastError() |
|
| 432 | |||
| 433 | /** |
||
| 434 | * @return string |
||
| 435 | */ |
||
| 436 | 1 | public function getLastWarning() |
|
| 440 | |||
| 441 | /** |
||
| 442 | * Get last error flag (to tell network connection errors from searchd errors or broken responses) |
||
| 443 | * |
||
| 444 | * @return bool |
||
| 445 | */ |
||
| 446 | 1 | public function isConnectError() |
|
| 450 | |||
| 451 | /** |
||
| 452 | * Set searchd host name and port |
||
| 453 | * |
||
| 454 | * @param string $host |
||
| 455 | * @param int $port |
||
| 456 | */ |
||
| 457 | public function setServer($host, $port = 0) |
||
| 475 | |||
| 476 | /** |
||
| 477 | * Set server connection timeout (0 to remove) |
||
| 478 | * |
||
| 479 | * @param int $timeout |
||
| 480 | */ |
||
| 481 | public function setConnectTimeout($timeout) |
||
| 486 | |||
| 487 | /** |
||
| 488 | * @param resource $handle |
||
| 489 | * @param string $data |
||
| 490 | * @param int $length |
||
| 491 | * |
||
| 492 | * @return bool |
||
| 493 | */ |
||
| 494 | protected function send($handle, $data, $length) |
||
| 503 | |||
| 504 | ///////////////////////////////////////////////////////////////////////////// |
||
| 505 | |||
| 506 | /** |
||
| 507 | * Enter mbstring workaround mode |
||
| 508 | */ |
||
| 509 | protected function mbPush() |
||
| 517 | |||
| 518 | /** |
||
| 519 | * Leave mbstring workaround mode |
||
| 520 | */ |
||
| 521 | protected function mbPop() |
||
| 527 | |||
| 528 | /** |
||
| 529 | * Connect to searchd server |
||
| 530 | * |
||
| 531 | * @return bool|resource |
||
| 532 | */ |
||
| 533 | protected function connect() |
||
| 598 | |||
| 599 | /** |
||
| 600 | * Get and check response packet from searchd server |
||
| 601 | * |
||
| 602 | * @param resource $fp |
||
| 603 | * @param int $client_ver |
||
| 604 | * |
||
| 605 | * @return bool|string |
||
| 606 | */ |
||
| 607 | protected function getResponse($fp, $client_ver) |
||
| 666 | |||
| 667 | ///////////////////////////////////////////////////////////////////////////// |
||
| 668 | // searching |
||
| 669 | ///////////////////////////////////////////////////////////////////////////// |
||
| 670 | |||
| 671 | /** |
||
| 672 | * Set offset and count into result set, and optionally set max-matches and cutoff limits |
||
| 673 | * |
||
| 674 | * @param int $offset |
||
| 675 | * @param int $limit |
||
| 676 | * @param int $max |
||
| 677 | * @param int $cutoff |
||
| 678 | */ |
||
| 679 | public function setLimits($offset, $limit, $max = 0, $cutoff = 0) |
||
| 695 | |||
| 696 | /** |
||
| 697 | * Set maximum query time, in milliseconds, per-index, 0 means 'do not limit' |
||
| 698 | * |
||
| 699 | * @param int $max |
||
| 700 | */ |
||
| 701 | public function setMaxQueryTime($max) |
||
| 707 | |||
| 708 | /** |
||
| 709 | * Set matching mode |
||
| 710 | * |
||
| 711 | * @param int $mode |
||
| 712 | */ |
||
| 713 | public function setMatchMode($mode) |
||
| 730 | |||
| 731 | /** |
||
| 732 | * Set ranking mode |
||
| 733 | * |
||
| 734 | * @param int $ranker |
||
| 735 | * @param string $rank_expr |
||
| 736 | */ |
||
| 737 | public function setRankingMode($ranker, $rank_expr='') |
||
| 744 | |||
| 745 | /** |
||
| 746 | * Set matches sorting mode |
||
| 747 | * |
||
| 748 | * @param int $mode |
||
| 749 | * @param string $sort_by |
||
| 750 | */ |
||
| 751 | View Code Duplication | public function setSortMode($mode, $sort_by = '') |
|
| 767 | |||
| 768 | /** |
||
| 769 | * Bind per-field weights by order |
||
| 770 | * |
||
| 771 | * @deprecated use setFieldWeights() instead |
||
| 772 | */ |
||
| 773 | 1 | public function setWeights() |
|
| 777 | |||
| 778 | /** |
||
| 779 | * Bind per-field weights by name |
||
| 780 | * |
||
| 781 | * @param array $weights |
||
| 782 | */ |
||
| 783 | public function setFieldWeights(array $weights) |
||
| 791 | |||
| 792 | /** |
||
| 793 | * Bind per-index weights by name |
||
| 794 | * |
||
| 795 | * @param array $weights |
||
| 796 | */ |
||
| 797 | public function setIndexWeights(array $weights) |
||
| 805 | |||
| 806 | /** |
||
| 807 | * Set IDs range to match. Only match records if document ID is beetwen $min and $max (inclusive) |
||
| 808 | * |
||
| 809 | * @param int $min |
||
| 810 | * @param int $max |
||
| 811 | */ |
||
| 812 | public function setIDRange($min, $max) |
||
| 821 | |||
| 822 | /** |
||
| 823 | * Set values set filter. Only match records where $attribute value is in given set |
||
| 824 | * |
||
| 825 | * @param string $attribute |
||
| 826 | * @param array $values |
||
| 827 | * @param bool $exclude |
||
| 828 | */ |
||
| 829 | View Code Duplication | public function setFilter($attribute, array $values, $exclude = false) |
|
| 845 | |||
| 846 | /** |
||
| 847 | * Set string filter |
||
| 848 | * Only match records where $attribute value is equal |
||
| 849 | * |
||
| 850 | * @param string $attribute |
||
| 851 | * @param string $value |
||
| 852 | * @param bool $exclude |
||
| 853 | */ |
||
| 854 | public function setFilterString($attribute, $value, $exclude = false) |
||
| 865 | |||
| 866 | /** |
||
| 867 | * Set range filter |
||
| 868 | * Only match records if $attribute value is beetwen $min and $max (inclusive) |
||
| 869 | * |
||
| 870 | * @param string $attribute |
||
| 871 | * @param int $min |
||
| 872 | * @param int $max |
||
| 873 | * @param bool $exclude |
||
| 874 | */ |
||
| 875 | View Code Duplication | public function setFilterRange($attribute, $min, $max, $exclude = false) |
|
| 890 | |||
| 891 | /** |
||
| 892 | * Set float range filter |
||
| 893 | * Only match records if $attribute value is beetwen $min and $max (inclusive) |
||
| 894 | * |
||
| 895 | * @param string $attribute |
||
| 896 | * @param int $min |
||
| 897 | * @param int $max |
||
| 898 | * @param bool $exclude |
||
| 899 | */ |
||
| 900 | View Code Duplication | public function setFilterFloatRange($attribute, $min, $max, $exclude = false) |
|
| 915 | |||
| 916 | /** |
||
| 917 | * Setup anchor point for geosphere distance calculations |
||
| 918 | * Required to use @geodist in filters and sorting |
||
| 919 | * Latitude and longitude must be in radians |
||
| 920 | * |
||
| 921 | * @param string $attr_lat |
||
| 922 | * @param string $attr_long |
||
| 923 | * @param float $lat |
||
| 924 | * @param float $long |
||
| 925 | */ |
||
| 926 | public function setGeoAnchor($attr_lat, $attr_long, $lat, $long) |
||
| 940 | |||
| 941 | /** |
||
| 942 | * Set grouping attribute and function |
||
| 943 | * |
||
| 944 | * @param string $attribute |
||
| 945 | * @param string $func |
||
| 946 | * @param string $group_sort |
||
| 947 | */ |
||
| 948 | View Code Duplication | public function setGroupBy($attribute, $func, $group_sort = '@group desc') |
|
| 965 | |||
| 966 | /** |
||
| 967 | * Set count-distinct attribute for group-by queries |
||
| 968 | * |
||
| 969 | * @param string $attribute |
||
| 970 | */ |
||
| 971 | public function setGroupDistinct($attribute) |
||
| 976 | |||
| 977 | /** |
||
| 978 | * Set distributed retries count and delay |
||
| 979 | * |
||
| 980 | * @param int $count |
||
| 981 | * @param int $delay |
||
| 982 | */ |
||
| 983 | public function setRetries($count, $delay = 0) |
||
| 990 | |||
| 991 | /** |
||
| 992 | * Set result set format (hash or array; hash by default) |
||
| 993 | * PHP specific; needed for group-by-MVA result sets that may contain duplicate IDs |
||
| 994 | * |
||
| 995 | * @param bool $array_result |
||
| 996 | */ |
||
| 997 | public function setArrayResult($array_result) |
||
| 1002 | |||
| 1003 | /** |
||
| 1004 | * Set attribute values override |
||
| 1005 | * There can be only one override per attribute |
||
| 1006 | * $values must be a hash that maps document IDs to attribute values |
||
| 1007 | * |
||
| 1008 | * @deprecated Do not call this method. Use SphinxQL REMAP() function instead. |
||
| 1009 | * |
||
| 1010 | * @param string $attr_name |
||
| 1011 | * @param string $attr_type |
||
| 1012 | * @param array $values |
||
| 1013 | */ |
||
| 1014 | public function setOverride($attr_name, $attr_type, array $values) |
||
| 1035 | |||
| 1036 | /** |
||
| 1037 | * Set select-list (attributes or expressions), SQL-like syntax |
||
| 1038 | * |
||
| 1039 | * @param string $select |
||
| 1040 | */ |
||
| 1041 | public function setSelect($select) |
||
| 1046 | |||
| 1047 | /** |
||
| 1048 | * @param string $flag_name |
||
| 1049 | * @param string|int $flag_value |
||
| 1050 | */ |
||
| 1051 | public function setQueryFlag($flag_name, $flag_value) |
||
| 1108 | |||
| 1109 | /** |
||
| 1110 | * Set outer order by parameters |
||
| 1111 | * |
||
| 1112 | * @param string $order_by |
||
| 1113 | * @param int $offset |
||
| 1114 | * @param int $limit |
||
| 1115 | */ |
||
| 1116 | public function setOuterSelect($order_by, $offset, $limit) |
||
| 1129 | |||
| 1130 | |||
| 1131 | ////////////////////////////////////////////////////////////////////////////// |
||
| 1132 | |||
| 1133 | /** |
||
| 1134 | * Clear all filters (for multi-queries) |
||
| 1135 | */ |
||
| 1136 | public function resetFilters() |
||
| 1141 | |||
| 1142 | /** |
||
| 1143 | * Clear groupby settings (for multi-queries) |
||
| 1144 | */ |
||
| 1145 | public function resetGroupBy() |
||
| 1152 | |||
| 1153 | /** |
||
| 1154 | * Clear all attribute value overrides (for multi-queries) |
||
| 1155 | */ |
||
| 1156 | public function resetOverrides() |
||
| 1160 | |||
| 1161 | public function resetQueryFlag() |
||
| 1166 | |||
| 1167 | public function resetOuterSelect() |
||
| 1174 | |||
| 1175 | ////////////////////////////////////////////////////////////////////////////// |
||
| 1176 | |||
| 1177 | /** |
||
| 1178 | * Connect to searchd server, run given search query through given indexes, and return the search results |
||
| 1179 | * |
||
| 1180 | * @param string $query |
||
| 1181 | * @param string $index |
||
| 1182 | * @param string $comment |
||
| 1183 | * |
||
| 1184 | * @return bool |
||
| 1185 | */ |
||
| 1186 | public function query($query, $index = '*', $comment = '') |
||
| 1207 | |||
| 1208 | /** |
||
| 1209 | * Helper to pack floats in network byte order |
||
| 1210 | * |
||
| 1211 | * @param float $float |
||
| 1212 | * |
||
| 1213 | * @return string |
||
| 1214 | */ |
||
| 1215 | protected function packFloat($float) |
||
| 1221 | |||
| 1222 | /** |
||
| 1223 | * Add query to multi-query batch |
||
| 1224 | * Returns index into results array from RunQueries() call |
||
| 1225 | * |
||
| 1226 | * @param string $query |
||
| 1227 | * @param string $index |
||
| 1228 | * @param string $comment |
||
| 1229 | * |
||
| 1230 | * @return int |
||
| 1231 | */ |
||
| 1232 | public function addQuery($query, $index = '*', $comment = '') |
||
| 1363 | |||
| 1364 | /** |
||
| 1365 | * Connect to searchd, run queries batch, and return an array of result sets |
||
| 1366 | * |
||
| 1367 | * @return array|bool |
||
| 1368 | */ |
||
| 1369 | public function runQueries() |
||
| 1401 | |||
| 1402 | /** |
||
| 1403 | * Parse and return search query (or queries) response |
||
| 1404 | * |
||
| 1405 | * @param string $response |
||
| 1406 | * @param int $nreqs |
||
| 1407 | * |
||
| 1408 | * @return array |
||
| 1409 | */ |
||
| 1410 | protected function parseSearchResponse($response, $nreqs) |
||
| 1579 | |||
| 1580 | ///////////////////////////////////////////////////////////////////////////// |
||
| 1581 | // excerpts generation |
||
| 1582 | ///////////////////////////////////////////////////////////////////////////// |
||
| 1583 | |||
| 1584 | /** |
||
| 1585 | * Connect to searchd server, and generate exceprts (snippets) of given documents for given query. |
||
| 1586 | * Returns false on failure, an array of snippets on success |
||
| 1587 | * |
||
| 1588 | * @param array $docs |
||
| 1589 | * @param string $index |
||
| 1590 | * @param string $words |
||
| 1591 | * @param array $opts |
||
| 1592 | * |
||
| 1593 | * @return array|bool |
||
| 1594 | */ |
||
| 1595 | public function buildExcerpts(array $docs, $index, $words, array $opts = array()) |
||
| 1725 | |||
| 1726 | |||
| 1727 | ///////////////////////////////////////////////////////////////////////////// |
||
| 1728 | // keyword generation |
||
| 1729 | ///////////////////////////////////////////////////////////////////////////// |
||
| 1730 | |||
| 1731 | /** |
||
| 1732 | * Connect to searchd server, and generate keyword list for a given query returns false on failure, |
||
| 1733 | * an array of words on success |
||
| 1734 | * |
||
| 1735 | * @param string $query |
||
| 1736 | * @param string $index |
||
| 1737 | * @param bool $hits |
||
| 1738 | * |
||
| 1739 | * @return array|bool |
||
| 1740 | */ |
||
| 1741 | public function buildKeywords($query, $index, $hits) |
||
| 1816 | |||
| 1817 | /** |
||
| 1818 | * @param string $string |
||
| 1819 | * |
||
| 1820 | * @return string |
||
| 1821 | */ |
||
| 1822 | public function escapeString($string) |
||
| 1829 | |||
| 1830 | ///////////////////////////////////////////////////////////////////////////// |
||
| 1831 | // attribute updates |
||
| 1832 | ///////////////////////////////////////////////////////////////////////////// |
||
| 1833 | |||
| 1834 | /** |
||
| 1835 | * Batch update given attributes in given rows in given indexes |
||
| 1836 | * Returns amount of updated documents (0 or more) on success, or -1 on failure |
||
| 1837 | * |
||
| 1838 | * @param string $index |
||
| 1839 | * @param array $attrs |
||
| 1840 | * @param array $values |
||
| 1841 | * @param bool $mva |
||
| 1842 | * @param bool $ignore_non_existent |
||
| 1843 | * |
||
| 1844 | * @return int |
||
| 1845 | */ |
||
| 1846 | public function updateAttributes($index, array $attrs, array $values, $mva = false, $ignore_non_existent = false) |
||
| 1920 | |||
| 1921 | ///////////////////////////////////////////////////////////////////////////// |
||
| 1922 | // persistent connections |
||
| 1923 | ///////////////////////////////////////////////////////////////////////////// |
||
| 1924 | |||
| 1925 | /** |
||
| 1926 | * @return bool |
||
| 1927 | */ |
||
| 1928 | public function open() |
||
| 1946 | |||
| 1947 | /** |
||
| 1948 | * @return bool |
||
| 1949 | */ |
||
| 1950 | public function close() |
||
| 1962 | |||
| 1963 | ////////////////////////////////////////////////////////////////////////// |
||
| 1964 | // status |
||
| 1965 | ////////////////////////////////////////////////////////////////////////// |
||
| 1966 | |||
| 1967 | /** |
||
| 1968 | * @param bool $session |
||
| 1969 | * |
||
| 1970 | * @return array|bool |
||
| 1971 | */ |
||
| 1972 | public function status($session = false) |
||
| 2006 | |||
| 2007 | ////////////////////////////////////////////////////////////////////////// |
||
| 2008 | // flush |
||
| 2009 | ////////////////////////////////////////////////////////////////////////// |
||
| 2010 | |||
| 2011 | /** |
||
| 2012 | * @return int |
||
| 2013 | */ |
||
| 2014 | public function flushAttributes() |
||
| 2038 | } |
||
| 2039 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.