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

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.

主站蜘蛛池模板: 永新县| 新巴尔虎左旗| 手游| 威信县| 炎陵县| 原平市| 南川市| 临泉县| 马公市| 安远县| 成安县| 马山县| 阳高县| 雷州市| 普宁市| 仁布县| 翼城县| 邮箱| 仙游县| 故城县| 义乌市| 虎林市| 玉田县| 庆安县| 汨罗市| 从化市| 西畴县| 托克托县| 宁国市| 瑞丽市| 固阳县| 乌拉特中旗| 大理市| 达尔| 探索| 通海县| 米林县| 张掖市| 宁都县| 新闻| 法库县|