fix: restore kb retrieve fallback
This commit is contained in:
@@ -23,6 +23,28 @@ class KbService
|
|||||||
{
|
{
|
||||||
public const COLLECTION_GLOBAL = 'global';
|
public const COLLECTION_GLOBAL = 'global';
|
||||||
|
|
||||||
|
private const QUERY_TERM_ALIASES = [
|
||||||
|
'旧澳六合' => ['旧澳六合', '老澳门六合彩'],
|
||||||
|
'新澳六合' => ['新澳六合', '新澳门六合彩'],
|
||||||
|
];
|
||||||
|
|
||||||
|
private const QUERY_COMMON_TERMS = [
|
||||||
|
'分析线索',
|
||||||
|
'走势分析',
|
||||||
|
'开奖记录',
|
||||||
|
'开奖结果',
|
||||||
|
'冷热号',
|
||||||
|
'波色',
|
||||||
|
'生肖',
|
||||||
|
'特码',
|
||||||
|
'号码',
|
||||||
|
'彩票',
|
||||||
|
'比赛',
|
||||||
|
'新闻',
|
||||||
|
'马刺',
|
||||||
|
'NBA',
|
||||||
|
];
|
||||||
|
|
||||||
public static function upsertDocument(string $domain, string $subtype, int $sourceId): array
|
public static function upsertDocument(string $domain, string $subtype, int $sourceId): array
|
||||||
{
|
{
|
||||||
$transactionStarted = false;
|
$transactionStarted = false;
|
||||||
@@ -320,11 +342,18 @@ class KbService
|
|||||||
if (empty($candidates)) {
|
if (empty($candidates)) {
|
||||||
$keywordParts = self::splitQueryTerms($queryText);
|
$keywordParts = self::splitQueryTerms($queryText);
|
||||||
$fallback = clone $query;
|
$fallback = clone $query;
|
||||||
foreach (array_slice($keywordParts, 0, 3) as $term) {
|
if (!empty($keywordParts)) {
|
||||||
$fallback->where(function ($subQuery) use ($term) {
|
$fallback->where(function ($keywordQuery) use ($keywordParts) {
|
||||||
$subQuery->whereLike('c.chunk_text', '%' . $term . '%')
|
foreach (array_slice($keywordParts, 0, 8) as $index => $term) {
|
||||||
->whereOrLike('d.title', '%' . $term . '%')
|
$like = '%' . $term . '%';
|
||||||
->whereOrLike('d.keywords', '%' . $term . '%');
|
$method = $index === 0 ? 'where' : 'whereOr';
|
||||||
|
$keywordQuery->{$method}(function ($subQuery) use ($like) {
|
||||||
|
$subQuery->whereLike('c.chunk_text', $like)
|
||||||
|
->whereOr('d.title', 'like', $like)
|
||||||
|
->whereOr('d.summary', 'like', $like)
|
||||||
|
->whereOr('d.keywords', 'like', $like);
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
$candidates = $fallback->order('d.source_updated_at', 'desc')->limit($limit)->select()->toArray();
|
$candidates = $fallback->order('d.source_updated_at', 'desc')->limit($limit)->select()->toArray();
|
||||||
@@ -800,9 +829,27 @@ class KbService
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$terms = preg_split('/[\s,,。!?;、::\/\\\\]+/u', $queryText) ?: [];
|
$terms = [];
|
||||||
$terms = array_values(array_filter(array_map('trim', $terms), static fn(string $term) => mb_strlen($term) >= 2));
|
foreach (self::QUERY_TERM_ALIASES as $trigger => $aliases) {
|
||||||
return array_unique($terms);
|
if (mb_strpos($queryText, $trigger) !== false) {
|
||||||
|
array_push($terms, ...$aliases);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (self::QUERY_COMMON_TERMS as $term) {
|
||||||
|
if (mb_strpos($queryText, $term) !== false) {
|
||||||
|
$terms[] = $term;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$parts = preg_split('/[\s,,。!?;、::\/\\\\]+/u', $queryText) ?: [];
|
||||||
|
array_push($terms, ...$parts);
|
||||||
|
|
||||||
|
$terms = array_values(array_filter(array_map('trim', $terms), static function (string $term) {
|
||||||
|
return mb_strlen($term) >= 2;
|
||||||
|
}));
|
||||||
|
|
||||||
|
return array_values(array_unique($terms));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function normalizeHtmlText(string $html): string
|
private static function normalizeHtmlText(string $html): string
|
||||||
|
|||||||
Reference in New Issue
Block a user