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

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 the word 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 a 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.

主站蜘蛛池模板: 成都市| 康乐县| 旅游| 唐河县| 衢州市| 洛川县| 新郑市| 沭阳县| 崇文区| 昭觉县| 乳山市| 塘沽区| 潢川县| 涞源县| 封开县| 法库县| 富民县| 慈溪市| 井研县| 北川| 东辽县| 浑源县| 临泉县| 邓州市| 宁明县| 沙雅县| 正蓝旗| 高尔夫| 云林县| 武乡县| 万全县| 灵寿县| 锡林郭勒盟| 亚东县| 镇安县| 霸州市| 都江堰市| 益阳市| 来凤县| 新安县| 郸城县|