1
0
mirror of https://github.com/flarum/core.git synced 2025-08-13 11:54:32 +02:00

Implement search on front end

This commit is contained in:
Toby Zerner
2015-06-03 18:10:56 +09:30
parent ea510b5ea0
commit 5d89618bbd
18 changed files with 717 additions and 202 deletions

View File

@@ -33,7 +33,9 @@ class IndexAction extends SerializeCollectionAction
'lastUser' => true,
'startPost' => false,
'lastPost' => false,
'relevantPosts' => false
'relevantPosts' => false,
'relevantPosts.discussion' => false,
'relevantPosts.user' => false
];
/**

View File

@@ -93,7 +93,7 @@ class DiscussionSearcher implements SearcherInterface
}
if (in_array('relevantPosts', $load) && count($this->relevantPosts)) {
$load = array_diff($load, ['relevantPosts']);
$load = array_diff($load, ['relevantPosts', 'relevantPosts.discussion', 'relevantPosts.user']);
$postIds = [];
foreach ($this->relevantPosts as $id => $posts) {
@@ -104,12 +104,6 @@ class DiscussionSearcher implements SearcherInterface
foreach ($discussions as $discussion) {
$discussion->relevantPosts = $posts->filter(function ($post) use ($discussion) {
return $post->discussion_id == $discussion->id;
})
->each(function ($post) {
$pos = strpos(strtolower($post->content), strtolower($this->fulltext));
// TODO: make clipping more intelligent (full words only)
$start = max(0, $pos - 50);
$post->content = ($start > 0 ? '...' : '').str_limit(substr($post->content, $start), 300);
});
}
}