Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 组合查询以按正确顺序获取所有匹配的搜索文本_Sql_Postgresql_Search_Indexing_Full Text Search - Fatal编程技术网

Sql 组合查询以按正确顺序获取所有匹配的搜索文本

Sql 组合查询以按正确顺序获取所有匹配的搜索文本,sql,postgresql,search,indexing,full-text-search,Sql,Postgresql,Search,Indexing,Full Text Search,我有下表: postgres=# \d so_rum; Table "public.so_rum" Column | Type | Collation | Nullable | Default -----------+-------------------------+-----------+----------+--------- id | integer

我有下表:

postgres=# \d so_rum;
                        Table "public.so_rum"
  Column   |          Type           | Collation | Nullable | Default 
-----------+-------------------------+-----------+----------+---------
 id        | integer                 |           |          | 
 title     | character varying(1000) |           |          | 
 posts     | text                    |           |          | 
 body      | tsvector                |           |          | 
 parent_id | integer                 |           |          | 
Indexes:
    "so_rum_body_idx" rum (body)
我想进行短语搜索查询,因此我提出了以下查询,例如:

select id from so_rum
    where body @@ phraseto_tsquery('english','Is it possible to toggle the visibility');
这给了我结果,它只匹配整个文本。然而,有些文档中词条之间的距离更大,上面的查询没有返回这些数据。例如:
“可以在。可见性“
不会返回。我知道我可以通过手动将
(例如)距离操作符中的
输入到\u tsquery
,将其返回

但我想了解,如何在我的sql语句本身中实现这一点,以便我首先获得距离为
1
的结果,然后是
2
,依此类推(可能直到
6-7
)。最后,使用搜索词的实际计数附加结果,如以下查询:

select count(id) from so_rum
    where body @@ to_tsquery('english','string & string . . . ')

是否可以在一个查询中以良好的性能执行此操作?

我看不到解决此问题的固定解决方案。听起来您需要使用plainto_tsquery来获取所有词素的所有结果,然后实现您自己的自定义排名功能,根据词素之间的距离对它们进行排名,并可能筛选出顺序错误的结果。

听起来您需要全文搜索:。是的。上面的查询实际上是在进行全文搜索。