bbcarchdev / twine

An RDF workflow engine
https://bbcarchdev.github.io/twine/
Apache License 2.0
8 stars 2 forks source link

index vectors end up empty if one of the source fields is empty #8

Closed nevali closed 9 years ago

nevali commented 9 years ago

The current query is:

UPDATE "index" SET "index_en_gb" = setweight(to_tsvector(coalesce("title" -> 'en-gb', "title" -> 'en', "title" -> '_')), 'A') ||
setweight(to_tsvector(coalesce("description" -> 'en-gb', "description" -> 'en', "description" -> '_')), 'B') WHERE "id" = 'cb90e10a13aa42ad82a0d047e56ab2bb';

If either of title or description is empty, then setweight() ends up returning an empty value (possibly NULL), which causes the whole expression to also be empty and so the item is not indexed.

The query should instead read:

UPDATE "index" SET "index_en_gb" = setweight(to_tsvector(coalesce("title" -> 'en-gb', "title" -> 'en', "title" -> '_', '')), 'A') ||
setweight(to_tsvector(coalesce("description" -> 'en-gb', "description" -> 'en', "description" -> '_', '')), 'B') WHERE "id" = 'cb90e10a13aa42ad82a0d047e56ab2bb';

(i.e., include an empty string in the coalesce() call)

nevali commented 9 years ago

(Should have been against the bbcarchdev/spindle project)