- Mastering PostgreSQL 10
- Hans Jürgen Sch?nig
- 244字
- 2021-06-30 19:03:59
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.
- 繪制進程圖:可視化D++語言(第1冊)
- 輕松學C語言
- 大數(shù)據(jù)項目管理:從規(guī)劃到實現(xiàn)
- 三菱FX3U/5U PLC從入門到精通
- Visual Basic.NET程序設計
- 內(nèi)模控制及其應用
- 分析力!專業(yè)Excel的制作與分析實用法則
- 智能生產(chǎn)線的重構方法
- Salesforce for Beginners
- 零起點學西門子S7-200 PLC
- 統(tǒng)計挖掘與機器學習:大數(shù)據(jù)預測建模和分析技術(原書第3版)
- Silverlight 2完美征程
- Learning Apache Apex
- 工業(yè)機器人實操進階手冊
- 網(wǎng)絡安全概論