Compare commits
5 commits
45bd1b408d
...
850ebff7c0
Author | SHA1 | Date | |
---|---|---|---|
850ebff7c0 | |||
5b4b2b59be | |||
1a4bcf8755 | |||
b11da225fb | |||
138b4f24ee |
|
@ -7,7 +7,7 @@ when:
|
||||||
event: [push, pull_request, tag, manual]
|
event: [push, pull_request, tag, manual]
|
||||||
branch: [master, master-*, develop, develop-*, feature/*]
|
branch: [master, master-*, develop, develop-*, feature/*]
|
||||||
|
|
||||||
pipeline:
|
steps:
|
||||||
db-wait:
|
db-wait:
|
||||||
image: gitnet.fr/deblan/timeout:latest
|
image: gitnet.fr/deblan/timeout:latest
|
||||||
commands:
|
commands:
|
||||||
|
@ -72,7 +72,7 @@ pipeline:
|
||||||
commands:
|
commands:
|
||||||
- apt-get update && apt-get -y install rsync
|
- apt-get update && apt-get -y install rsync
|
||||||
- cd /data/deblan/deblan.io-murph/
|
- cd /data/deblan/deblan.io-murph/
|
||||||
- rsync -avz "$CI_WORKSPACE/" "$CI_COMMIT_SHA"
|
- rsync -az "$CI_WORKSPACE/" "$CI_COMMIT_SHA"
|
||||||
|
|
||||||
services:
|
services:
|
||||||
db:
|
db:
|
||||||
|
|
|
@ -5,7 +5,7 @@ variables:
|
||||||
when:
|
when:
|
||||||
event: [deployment]
|
event: [deployment]
|
||||||
|
|
||||||
pipeline:
|
steps:
|
||||||
app-deploy:
|
app-deploy:
|
||||||
image: deblan/php:8.1
|
image: deblan/php:8.1
|
||||||
secrets: [ssh_user, ssh_host, ssh_priv_key, app_directory]
|
secrets: [ssh_user, ssh_host, ssh_priv_key, app_directory]
|
||||||
|
|
|
@ -54,15 +54,13 @@ class PostRepositoryQuery extends RepositoryQuery
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function filterHandler(string $name, $value)
|
|
||||||
{
|
|
||||||
if ('category' === $name) {
|
|
||||||
$this->inCategory($value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function search(?string $keywords, ?string $tag)
|
public function search(?string $keywords, ?string $tag)
|
||||||
{
|
{
|
||||||
|
$keywords = explode(' ', $keywords);
|
||||||
|
|
||||||
|
$filterWords = fn ($keyword) => '' !== trim($keyword) && preg_match('/[a-zA-Z]+/', $keyword);
|
||||||
|
$keywords = array_filter($keywords, $filterWords);
|
||||||
|
|
||||||
if ($keywords) {
|
if ($keywords) {
|
||||||
$conn = $this->repository->getEm()->getConnection();
|
$conn = $this->repository->getEm()->getConnection();
|
||||||
|
|
||||||
|
@ -70,43 +68,107 @@ class PostRepositoryQuery extends RepositoryQuery
|
||||||
'SELECT
|
'SELECT
|
||||||
post.id,
|
post.id,
|
||||||
post.title,
|
post.title,
|
||||||
MATCH(post.title) AGAINST(:search) AS MATCH_TITLE,
|
post.content,
|
||||||
MATCH(post.content) AGAINST(:search) AS MATCH_CONTENT
|
post.published_at
|
||||||
FROM post
|
FROM post
|
||||||
WHERE
|
WHERE
|
||||||
post.status = 1 AND
|
post.status = 1 AND
|
||||||
post.published_at < :date
|
post.published_at < :date
|
||||||
ORDER BY
|
'
|
||||||
MATCH_TITLE DESC,
|
);
|
||||||
MATCH_CONTENT DESC
|
|
||||||
');
|
|
||||||
|
|
||||||
$statement = $query->execute([
|
$statement = $query->execute([
|
||||||
':search' => $keywords,
|
|
||||||
':date' => (new \DateTime())->format('Y-m-d H:i:s'),
|
':date' => (new \DateTime())->format('Y-m-d H:i:s'),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$results = $statement->fetchAll();
|
$results = $statement->fetchAll();
|
||||||
$ids = [];
|
$ids = [];
|
||||||
|
$matches = [];
|
||||||
|
|
||||||
foreach ($results as $k => $v) {
|
foreach ($results as $k => $v) {
|
||||||
$rate = ($v['MATCH_TITLE'] * 2) + $v['MATCH_CONTENT'];
|
$initWords = explode(' ', $v['title']);
|
||||||
|
$words = [];
|
||||||
|
|
||||||
if ($rate >= 7) {
|
foreach ($initWords as $initWord) {
|
||||||
$ids[] = $v['id'];
|
$words = array_merge($words, preg_split('/[:_\'-]+/', $initWord));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (0 == count($ids)) {
|
$words = array_filter($words, $filterWords);
|
||||||
foreach ($results as $k => $v) {
|
|
||||||
$rate = ($v['MATCH_TITLE'] * 2) + $v['MATCH_CONTENT'];
|
|
||||||
|
|
||||||
if ($rate >= 6) {
|
foreach ($keywords as $keyword) {
|
||||||
$ids[] = $v['id'];
|
if (str_contains(mb_strtolower($v['content']), mb_strtolower($keyword))) {
|
||||||
|
$similarity = 99;
|
||||||
|
|
||||||
|
if (isset($matches[$v['id']])) {
|
||||||
|
$matches[$v['id']]['similarity'] += $similarity;
|
||||||
|
++$matches[$v['id']]['count'];
|
||||||
|
} else {
|
||||||
|
$matches[$v['id']] = [
|
||||||
|
'id' => $v['id'],
|
||||||
|
'title' => $v['title'],
|
||||||
|
'published_at' => $v['published_at'],
|
||||||
|
'similarity' => $similarity,
|
||||||
|
'count' => 1,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($words as $word) {
|
||||||
|
if (str_contains(mb_strtolower($word), mb_strtolower($keyword))) {
|
||||||
|
$similarity = 150;
|
||||||
|
|
||||||
|
if (isset($matches[$v['id']])) {
|
||||||
|
$matches[$v['id']]['similarity'] += $similarity;
|
||||||
|
++$matches[$v['id']]['count'];
|
||||||
|
} else {
|
||||||
|
$matches[$v['id']] = [
|
||||||
|
'id' => $v['id'],
|
||||||
|
'title' => $v['title'],
|
||||||
|
'published_at' => $v['published_at'],
|
||||||
|
'similarity' => $similarity,
|
||||||
|
'count' => 1,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$lev = levenshtein($word, $keyword);
|
||||||
|
$similarity = 100 - ($lev * 100 / mb_strlen($word));
|
||||||
|
|
||||||
|
if ($similarity > 70) {
|
||||||
|
if (isset($matches[$v['id']])) {
|
||||||
|
$matches[$v['id']]['similarity'] += $similarity;
|
||||||
|
} else {
|
||||||
|
$matches[$v['id']] = [
|
||||||
|
'id' => $v['id'],
|
||||||
|
'title' => $v['title'],
|
||||||
|
'published_at' => $v['published_at'],
|
||||||
|
'similarity' => $similarity,
|
||||||
|
'count' => 1,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$matches = array_filter($matches, function($match) use ($keywords) {
|
||||||
|
return (100 * $match['count'] / count($keywords)) > 80;
|
||||||
|
});
|
||||||
|
|
||||||
|
usort($matches, function ($a, $b) {
|
||||||
|
if ($a['similarity'] > $b['similarity']) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($b['similarity'] > $a['similarity']) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ($a['published_at'] != $b['published_at']) * -1;
|
||||||
|
});
|
||||||
|
|
||||||
|
$ids = array_column($matches, 'id');
|
||||||
|
|
||||||
if (!$ids) {
|
if (!$ids) {
|
||||||
$ids = [-1];
|
$ids = [-1];
|
||||||
}
|
}
|
||||||
|
@ -127,4 +189,11 @@ class PostRepositoryQuery extends RepositoryQuery
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function filterHandler(string $name, $value)
|
||||||
|
{
|
||||||
|
if ('category' === $name) {
|
||||||
|
$this->inCategory($value);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue