5

For a particular full text search I need to modify the standard stopword file and exclude some words. What I did so far:

Copied german.stop to german_modified.stop and then removed the words from german_modified.stop. Then:

CREATE TEXT SEARCH DICTIONARY public.german_nostop (
   TEMPLATE = pg_catalog.simple,
   STOPWORDS = german_modified
);

CREATE TEXT SEARCH CONFIGURATION public.german_nostop (
   COPY = pg_catalog.german
);

ALTER TEXT SEARCH CONFIGURATION public.german_nostop
   ALTER MAPPING
      FOR asciiword, asciihword, hword_asciipart, hword, hword_part, word
      WITH german_nostop;

CREATE INDEX body_idx ON comments
   USING gin (to_tsvector('german_nostop', body));

But when I do

SELECT body, autor
FROM comments
WHERE to_tsvector('german_nostop', body) @@ to_tsquery('wie');

I get:

NOTICE:  text-search query contains only stop words or doesn't contain lexemes, ignored
NOTICE:  text-search query contains only stop words or doesn't contain lexemes, ignored
NOTICE:  text-search query contains only stop words or doesn't contain lexemes, ignored
 body | autor
------+-------
(0 rows)

'wie' is the word that I removed from the modified stop words list. For some reason PostgreSQL did not use the new stoplist. I do not really want to modify the original since I do want to use the origal for other searches.

Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263
Alexander
  • 93
  • 1
  • 6

1 Answers1

3

You forgot to add your text search configuration to the to_tsquery call.

You should write:

to_tsquery('german_nostop', 'wie')

to_tsquery also removes stopwords, and since it used the german configuration by default, 'wie' was removed.

You can set default_text_search_config to german_nostop if you want your new text search configuration to be the default setting.

Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263