← All changes
|
vendor/wpfluent/framework/src/WPFluent/Database/Schema.php
+48
-0
2.4.01
→
2.11.0
View file →
| @@ -564,8 +564,56 @@ | ||
| 564 | 564 | return drop_index(static::table($table), $index); |
| 565 | 565 | } |
| 566 | 566 | |
| 567 | 567 | /** |
| 568 | + * Add a FULLTEXT index to the given columns, required by the query | |
| 569 | + * builder's relevance ranking (selectRelevance/orderByRelevance and the | |
| 570 | + * Searchable relevanceSearch scope). No-ops on SQLite, which has no | |
| 571 | + * native FULLTEXT support and degrades to LIKE-based matching. | |
| 572 | + * | |
| 573 | + * @param string $table Table name without prefix | |
| 574 | + * @param string|array $columns | |
| 575 | + * @param string|null $name Optional index name | |
| 576 | + * @return mixed | |
| 577 | + */ | |
| 578 | + public static function fullText($table, $columns, $name = null) | |
| 579 | + { | |
| 580 | + if (static::isSqlite()) { | |
| 581 | + return false; | |
| 582 | + } | |
| 583 | + | |
| 584 | + $columns = is_array($columns) | |
| 585 | + ? $columns | |
| 586 | + : array_map('trim', explode(',', $columns)); | |
| 587 | + | |
| 588 | + $tbl = static::table($table); | |
| 589 | + $name = $name ?: ('ft_' . implode('_', $columns)); | |
| 590 | + $list = implode(', ', $columns); | |
| 591 | + | |
| 592 | + return static::db()->query( | |
| 593 | + "ALTER TABLE {$tbl} ADD FULLTEXT {$name} ({$list})" | |
| 594 | + ); | |
| 595 | + } | |
| 596 | + | |
| 597 | + /** | |
| 598 | + * Drop a FULLTEXT index by name. | |
| 599 | + * | |
| 600 | + * @param string $table Table name without prefix | |
| 601 | + * @param string $name Index name | |
| 602 | + * @return mixed | |
| 603 | + */ | |
| 604 | + public static function dropFullText($table, $name) | |
| 605 | + { | |
| 606 | + if (static::isSqlite()) { | |
| 607 | + return false; | |
| 608 | + } | |
| 609 | + | |
| 610 | + $tbl = static::table($table); | |
| 611 | + | |
| 612 | + return static::db()->query("ALTER TABLE {$tbl} DROP INDEX {$name}"); | |
| 613 | + } | |
| 614 | + | |
| 615 | + /** | |
| 568 | 616 | * Makes raw query and can resolve the table name from the query |
| 569 | 617 | * and can form a full table name including the table prefix if |
| 570 | 618 | * the table name is wrapped like: %table_name% in the query. |
| 571 | 619 | * |