Page MenuHomePhabricator

PostgreSQL and tsearch2 Problems
Closed, ResolvedPublic

Description

Author: alessandro

Description:
I
have a problem with MediaWiki 1.10.0 and PostgreSQL 8.1.9 (from Ubuntu
Server 6.06.1 LTS).

Well, my little problem started today, when I do an update in MediaWiki
from 1.9.3 to 1.10.1.

Everything worked fine, but when I tried to search to something I got:

Warning: pg_query() [function.pg-query]: Query failed: ERROR:
unrecognized normalization method: 5 in
/var/www/embratel-wiki/includes/DatabasePostgres.php on line 497
Internal error

A database error has occurred Query: SELECT page_id, page_namespace,
page_title, rank(textvector, to_tsquery('default','ECT'),5) AS score
FROM page p, revision r, pagecontent c WHERE p.page_latest = r.rev_id
AND r.rev_text_id = c.old_id AND textvector @@
to_tsquery('default','ECT') AND page_is_redirect = 0 AND page_namespace
IN (0) ORDER BY score DESC, page_id DESC LIMIT 20 OFFSET 0 Function:
Error: 1 ERROR: unrecognized normalization method: 5

Backtrace:

#0 /var/www/embratel-wiki/includes/Database.php(762):
DatabasePostgres->reportQueryError('ERROR: unrecog...', 1, 'SELECT
page_id,...', '', false)
#1 /var/www/embratel-wiki/includes/SearchPostgres.php(44):
Database->query('SELECT page_id,...')
#2 /var/www/embratel-wiki/includes/SpecialSearch.php(158):
SearchPostgres->searchText('ECT')
#3 /var/www/embratel-wiki/includes/SpecialSearch.php(108):
SpecialSearch->showResults('ECT')
#4 /var/www/embratel-wiki/includes/SpecialSearch.php(40):
SpecialSearch->goResult('ECT')
#5 /var/www/embratel-wiki/includes/Wiki.php(143): wfSpecialSearch()
#6 /var/www/embratel-wiki/includes/Wiki.php(45):
MediaWiki->initializeSpecialCases(Object(Title), Object(OutputPage),
Object(WebRequest))
#7 /var/www/embratel-wiki/index.php(89):
MediaWiki->initialize(Object(Title), Object(OutputPage), Object(User),
Object(WebRequest))
#8 {main}

Well,

The update.php command executed fine...

I think that this problem is related with tsearch2, because if I
executed the query without rank parameter[1], I got:

"page_id";"page_namespace";"page_title";"score"
13;0;"SERV/Projeto_SGRC-ECT";0.0942146

References:

1-) SELECT page_id, page_namespace, page_title, rank(textvector,
to_tsquery('default','ect')) AS score FROM page p, revision r,
pagecontent c WHERE p.page_latest = r.rev_id AND r.rev_text_id =
c.old_id AND textvector @@ to_tsquery('default','ect') AND
page_is_redirect = 0 AND page_namespace IN (0) ORDER BY score DESC,
page_id DESC LIMIT 20 OFFSET 0


Version: 1.10.x
Severity: normal
OS: Linux
Platform: PC

Details

Reference
bz9908

Related Objects

View Standalone Graph
This task is connected to more than 200 other tasks. Only direct parents and subtasks are shown here. Use View Standalone Graph to show more of the graph.
StatusSubtypeAssignedTask
InvalidNone
ResolvedNone

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 9:41 PM
bzimport added a project: MediaWiki-Search.
bzimport set Reference to bz9908.
bzimport added a subscriber: Unknown Object (MLST).

alessandro wrote:

Greg Sabino Mullane, ask me the following information:

select current_setting('server_encoding');

wikidbprd=# select current_setting('server_encoding');

current_setting

UTF8
(1 row)

select current_setting('lc_ctype');

wikidbprd=# select current_setting('lc_ctype');

current_setting

en_US.UTF-8
(1 row)

select * from pg_ts_cfg;

wikidbprd=# select * from pg_ts_cfg;

ts_name     | prs_name |    locale

-----------------+----------+--------------
default_russian | default | ru_RU.KOI8-R
simple | default |
default | default | en_US.UTF-8
(3 rows)

Also, does this do this for all search requests?

No, I perceived that if I search a word that does not exist, the error
does not happen!

banderson wrote:

I had the same error. My solution:

At line 144 of includes/SearchPostgres.php, I changed the 5 to a 0
(normalization method):
"rank($fulltext, to_tsquery('default',$searchstring),0) AS score"

The normalization methods are shown on
http://www.sai.msu.su/~megera/oddmuse/index.cgi?Tsearch_V2_Notes
under "Document length normalization".

Here is the relevant section:
<quote>
Document length normalization

It's possible to normalize rank of document by document length (total number

of indexed words) To do so, you need to specify the last argument in ranking
function - rank(tsvector,query,len_norm), where len_norm:

  • 0 (default) - no normalization
  • 1 - normalized by log (document length)
  • 2 - normalized by document length itself

</quote>

It appears the default of 5 is not a valid normalization method. Maybe I
installed tsearch2 or mediawiki incorrectly, but either way, I figured I'd
report what worked for me.

alessandro wrote:

Bricklen,

Your workaround solves my problem!

Thanks!

  • Bug 9916 has been marked as a duplicate of this bug. ***
Jdforrester-WMF subscribed.

Migrating from the old tracking task to a tag for PostgreSQL-related tasks.