gpt4 book ai didi

sql - mysql查询: it's not fetching first result

转载 作者:行者123 更新时间:2023-11-29 01:01:28 25 4
gpt4 key购买 nike

我的数据库中有以下值。

  1. 曾经是 Lorem Ipsum 和炒过
  2. 乱序文本textofandtooktooktypetexthastheunknownspecimenstandardsincetypeset

这是我的查询:

SELECT
nBusinessAdID,
MATCH (`sHeadline`) AGAINST ("text" IN BOOLEAN MODE) AS score
FROM wiki_businessads
WHERE MATCH (`sHeadline`) AGAINST ("text" IN BOOLEAN MODE)
AND bDeleted ="0" AND nAdStatus ="1"
ORDER BY score DESC, bPrimeListing DESC, dDateCreated DESC

它没有获取第一个结果,为什么?它应该获取第一个结果,因为它包含文本单词。我已禁用停用词过滤。

这个也不行

SELECT
nBusinessAdID,
MATCH (`sHeadline`) AGAINST ('"text"' IN BOOLEAN MODE) AS score
FROM wiki_businessads
WHERE MATCH (`sHeadline`) AGAINST ('"text"' IN BOOLEAN MODE)
AND bDeleted ="0" AND nAdStatus ="1"
ORDER BY score DESC, bPrimeListing DESC, dDateCreated DESC

最佳答案

全文搜索只匹配单词和单词前缀。因为你在数据库中的数据不包含单词边界(空格),所以这些单词没有被索引,所以找不到。

您可以做出的一些可能的选择是:

  • 修正您的数据,使其在单词之间包含空格。
  • 使用 LIKE '%text%' 而不是全文搜索。
  • 使用外部全文搜索引擎。

我将依次展开其中的每一个。

修复您的数据,使其在单词之间包含空格。

您的数据似乎已以某种方式损坏。它看起来像单词或句子,但删除了所有空格。你知道那是怎么发生的吗?是故意的吗?也许系统中的其他地方存在错误。尝试解决这个问题。找出数据的来源,看看是否可以正确地重新导入。

如果原始源不包含空格,也许您可​​以使用一些自然语言工具包来猜测空格应该在哪里并插入它们。很可能已经存在可以执行此操作的库,尽管我碰巧不知道。 Google 搜索可能会找到一些东西。

使用 LIKE '%text%' 而不是全文搜索。

解决方法是改用 LIKE '%text%' 但请注意,这会慢很多,因为它无法使用索引。但是它会给出正确的结果。

使用外部全文搜索引擎。

您还可以查看 LuceneSphinx .例如,我知道 Sphinx 支持使用 *text* 查找文本。这是文档的摘录,它解释了如何启用中缀搜索,这正是您所需要的。

9.2.16. min_infix_len

Minimum infix prefix length to index. Optional, default is 0 (do not index infixes). Infix indexing allows to implement wildcard searching by 'start*', '*end', and 'middle' wildcards (refer to enable_star option for details on wildcard syntax). When mininum infix length is set to a positive number, indexer will index all the possible keyword infixes (ie. substrings) in addition to the keywords themselves. Too short infixes (below the minimum allowed length) will not be indexed.

For instance, indexing a keyword "test" with min_infix_len=2 will result in indexing "te", "es", "st", "tes", "est" infixes along with the word itself. Searches against such index for "es" will match documents that contain "test" word, even if they do not contain "es" on itself. However, indexing infixes will make the index grow significantly (because of many more indexed keywords), and will degrade both indexing and searching times.

关于sql - mysql查询: it's not fetching first result,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2839441/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com