gpt4 book ai didi

sql - 返回在全文搜索中找到的短语的周围文本,SQL 2005

转载 作者:行者123 更新时间:2023-12-02 02:37:36 24 4
gpt4 key购买 nike

我正在使用包含谓词在 SQL Server 索引文本字段中查找短语。有没有办法返回包含搜索短语的文本字段部分或其周围的某些区域?

例如,如果我在葛底斯堡演说(摘录如下)中搜索“人人生而平等”,我想返回“致力于人人生而平等的命题”,例如它周围有一些文字。

Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that *all men are created equal.*

Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and so dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should do this.

最佳答案

好吧,我不熟悉 SQL Server 语法,但您可以在字段中找到匹配项并返回它的子字符串。 伪代码:

SELECT
SUBSTRING(field, MAX(0, STRPOS(field, 'all men are equal' - 20), STRLEN('all men are equal') + 40)
FROM
yourtable
WHERE
field CONTAINS 'all men are equal'

有了这个,您只能找到包含该短语的那些记录的子字符串的位置,并返回一个长 40 个字符的字符串,所以类似的东西应该可以工作。

关于sql - 返回在全文搜索中找到的短语的周围文本,SQL 2005,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/730449/

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