Skip to content

Commit ae22cf3

Browse files
committed
Adjust ordering of content in search results
1 parent 60177a9 commit ae22cf3

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/Libraries/Search/Search.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ public static function query(string $user_input): Results|null
2929
self::runIdQuery($pdo, $results,
3030
'SELECT `id` FROM `comments` WHERE
3131
MATCH(`content`) AGAINST (:fulltext IN BOOLEAN MODE)
32-
OR `content` LIKE :like',
32+
OR `content` LIKE :like
33+
ORDER BY `created_datetime` DESC, `id` DESC',
3334
[':fulltext' => $fulltext, ':like' => $like],
3435
fn($id) => new Comment((int) $id),
3536
fn($r, $obj) => $r->addComment($obj)
@@ -41,7 +42,8 @@ public static function query(string $user_input): Results|null
4142
MATCH(`title`, `brief`, `content`) AGAINST (:fulltext IN BOOLEAN MODE)
4243
OR `title` LIKE :like
4344
OR `brief` LIKE :like
44-
OR `content` LIKE :like',
45+
OR `content` LIKE :like
46+
ORDER BY IFNULL(`edited_datetime`, `created_datetime`) DESC',
4547
[':fulltext' => $fulltext, ':like' => $like],
4648
fn($id) => new Document((int) $id),
4749
fn($r, $obj) => $r->addDocument($obj)
@@ -52,7 +54,8 @@ public static function query(string $user_input): Results|null
5254
'SELECT `id` FROM `news_posts` WHERE
5355
MATCH(`title`, `content`) AGAINST (:fulltext IN BOOLEAN MODE)
5456
OR `title` LIKE :like
55-
OR `content` LIKE :like',
57+
OR `content` LIKE :like
58+
ORDER BY IFNULL(`edited_datetime`, `created_datetime`) DESC',
5659
[':fulltext' => $fulltext, ':like' => $like],
5760
fn($id) => new NewsPost((int) $id),
5861
fn($r, $obj) => $r->addNewsPost($obj)
@@ -66,7 +69,8 @@ public static function query(string $user_input): Results|null
6669
OR `packet_name` LIKE :like
6770
OR `packet_brief` LIKE :like
6871
OR `packet_format` LIKE :like
69-
OR `packet_remarks` LIKE :like',
72+
OR `packet_remarks` LIKE :like
73+
ORDER BY `packet_id` ASC, `packet_name` ASC, `packet_direction_id` ASC',
7074
[':fulltext' => $fulltext, ':like' => $like],
7175
fn($id) => new Packet((int) $id),
7276
fn($r, $obj) => $r->addPacket($obj)
@@ -77,7 +81,8 @@ public static function query(string $user_input): Results|null
7781
'SELECT `id` FROM `servers` WHERE
7882
MATCH(`label`, `address`) AGAINST (:fulltext IN BOOLEAN MODE)
7983
OR `label` LIKE :like
80-
OR `address` LIKE :like',
84+
OR `address` LIKE :like
85+
ORDER BY `label` ASC, `address` ASC, `port` ASC',
8186
[':fulltext' => $fulltext, ':like' => $like],
8287
fn($id) => new Server((int) $id),
8388
fn($r, $obj) => $r->addServer($obj)
@@ -88,7 +93,8 @@ public static function query(string $user_input): Results|null
8893
'SELECT `id` FROM `users` WHERE
8994
MATCH(`username`, `display_name`) AGAINST (:fulltext IN BOOLEAN MODE)
9095
OR `username` LIKE :like
91-
OR `display_name` LIKE :like',
96+
OR `display_name` LIKE :like
97+
ORDER BY IFNULL(`display_name`, `username`) ASC',
9298
[':fulltext' => $fulltext, ':like' => $like],
9399
fn($id) => new User((int) $id),
94100
fn($r, $obj) => $r->addUser($obj)
@@ -117,7 +123,8 @@ public static function query(string $user_input): Results|null
117123
OR `facebook_username` LIKE :like
118124
OR `twitter_username` LIKE :like
119125
OR `instagram_username` LIKE :like
120-
OR `skype_username` LIKE :like',
126+
OR `skype_username` LIKE :like
127+
ORDER BY `user_id` ASC',
121128
[':fulltext' => $fulltext, ':like' => $like],
122129
fn($id) => new User((int) $id),
123130
fn($r, $obj) => $r->addUser($obj)

0 commit comments

Comments
 (0)