practical-sql icon indicating copy to clipboard operation
practical-sql copied to clipboard

Chapter 13 tsvector

Open MatMel16 opened this issue 4 years ago • 5 comments

Hi, I'm working on Win 10 I've installed PosgreSQL as described in book I'm using version 4.28 Yes, I did download it from GitHub

When Running Listing 13-15 on page 231, chapter 13, SELECT to_tsvector('I am walking across the sitting room to sit with you.');

pg gives me result: 'across':4 'am':2 'i':1 'room':7 'sit':9 'sitting':6 'the':5 'to':8 'walking':3 'with':10 'you':11 As long as I know, it is not, how tsvector should work, but instead should provide shortened version, for example: 'sit' :6,9

Im I doing something wrong?

MatMel16 avatar Feb 17 '21 13:02 MatMel16

Hello, @MatMel16 ... thank you for writing and for using my book.

I am fairly certain the issue is that your computer is set to a default text search configuration other than English. To check, you can run the following command in pgAdmin:

SHOW default_text_search_config;

If it displays a value other than English, that is the issue.

To get around this, you can modify Listing 13-15 like this:

SELECT to_tsvector('english', 'I am walking across the sitting room to sit with you.');

Please try that and let me know how it goes. Also, please let me know the results of the SHOW command above. Thanks!

anthonydb avatar Feb 18 '21 13:02 anthonydb

Hello, thank you very much for the answer. I enjoy your book very much.

After SHOW default_text_search_config; admin shows result: pg_catalog.simple

As you said, inserting english helped, but only for the simple issues as one, you listed. For example for Listing 13-12 from your book: SELECT president, speech_date, ts_headline(speech_text, to_tsquery('transportation & !roads'), 'StartSel = <, StopSel = >, MinWords=5, MaxWords=7, MaxFragments=1') FROM president_speeches WHERE search_speech_text @@ to_tsquery('english', 'transportation & !roads');

I observe 3 result.

  1. without stating 'english', as expected, I've got empty table
  2. Inserting 'english' in both tsqueries (in headline and where clause), I've got pretty confusing results (as in the picture below) image
  3. when I write it only into where clause, it seems to be most sufficient, but there is still one error. (Everything as it should be, but one row looks exatly like in previous result: "Mr. Speaker, Mr. Vice President")

MatMel16 avatar Feb 18 '21 18:02 MatMel16

Hmm, that's interesting. Would you please try something else? In your current pgAdmin session, run the following command:

SET default_text_search_config TO 'english';

That will set your text search language default to English -- but that won't be permanent. It's good only for your current session. If you start a new pgAdmin session, you'll have to run that again.

Try setting that default and running the queries as shown in the book. Please let me know the results.

Also, would you please report to me the result of this command?

show lc_ctype;

Thank you!

anthonydb avatar Feb 19 '21 13:02 anthonydb

Sure, the result of: show lc_ctype; is --> Slovak_Slovakia.1250

After I run the SET command, everything works as it should. Thank you. Is it somehow possible to set this permanent?

MatMel16 avatar Feb 19 '21 13:02 MatMel16

You're welcome.

Yes, you can make the change permanent by editing the value in your postgresql.conf file and re-starting PostgreSQL. Take a look at the section "Changing Server Settings" in Chapter 17. I mention the default search parameter in Listing 17-9.

Please let me know if you have any other questions!

anthonydb avatar Feb 19 '21 13:02 anthonydb