官术网_书友最值得收藏!

  • Mastering PostgreSQL 9.6
  • Hans Jurgen Schonig
  • 223字
  • 2021-07-09 19:57:23

Comparing strings

After taking a brief look at the stemming process, it is time to figure out how a stemmed text can be compared to a user query. The following code snippet checks for wanted:

test=# SELECT to_tsvector('english', 'A car, I want a car. I would not even mind having many cars') @@ to_tsquery('english', 'wanted'); 
?column?
----------
t
(1 row)

Note that wanted does not actually show up in the original text. Still, PostgreSQL will return true. The reason is that want and wanted are both transformed to the same lexeme so the result is true. Practically, this makes a lot of sense. Imagine you are looking for car on Google. If you find pages selling cars, this is totally fine. Finding common lexemes is therefore an intelligent idea.

Sometimes, people are not only looking for a single word but want to find a set of words. With to_tsquery, this is possible as shown in the next example:

test=# SELECT to_tsvector('english', 'A car, I want a car. I would not even mind having many cars') @@ to_tsquery('english', 'wanted & bmw'); 
?column?
----------
f
(1 row)

In this case, false is returned because bmw cannot be found in our input string. In the to_tsquery function, & means and and | means or. It is therefore easily possible to build complex search strings.

主站蜘蛛池模板: 莱芜市| 德庆县| 盈江县| 洪泽县| 榆树市| 哈尔滨市| 安国市| 呼玛县| 沂南县| 库尔勒市| 财经| 新乡市| 天祝| 江永县| 林甸县| 邵东县| 丰都县| 吕梁市| 博罗县| 腾冲县| 葵青区| 高台县| 武川县| 霍林郭勒市| 启东市| 博乐市| 辽源市| 鞍山市| 徐州市| 和龙市| 西丰县| 噶尔县| 赫章县| 静海县| 兴安盟| 佛坪县| 商城县| 金门县| 通河县| 隆尧县| 江都市|