mirror of https://github.com/zulip/zulip.git
pgroonga: Upgrade to PGroonga 2 API.
This commit is contained in:
parent
aaad7fe2f7
commit
46711a43f0
|
@ -0,0 +1,38 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from django.db import models, migrations
|
||||
from django.contrib.postgres import operations
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
atomic = False
|
||||
|
||||
dependencies = [
|
||||
('pgroonga', '0002_html_escape_subject'),
|
||||
]
|
||||
|
||||
database_setting = settings.DATABASES["default"]
|
||||
operations = [
|
||||
migrations.RunSQL(["""
|
||||
ALTER ROLE %(USER)s SET search_path TO %(SCHEMA)s,public;
|
||||
|
||||
SET search_path = %(SCHEMA)s,public;
|
||||
|
||||
DROP INDEX zerver_message_search_pgroonga;
|
||||
""" % database_setting, """
|
||||
|
||||
CREATE INDEX CONCURRENTLY zerver_message_search_pgroonga ON zerver_message
|
||||
USING pgroonga(search_pgroonga pgroonga_text_full_text_search_ops_v2);
|
||||
"""],
|
||||
["""
|
||||
ALTER ROLE %(USER)s SET search_path TO %(SCHEMA)s,public,pgroonga,pg_catalog;
|
||||
|
||||
SET search_path = %(SCHEMA)s,public,pgroonga,pg_catalog;
|
||||
|
||||
DROP INDEX zerver_message_search_pgroonga;
|
||||
""" % database_setting, """
|
||||
|
||||
CREATE INDEX CONCURRENTLY zerver_message_search_pgroonga ON zerver_message
|
||||
USING pgroonga(search_pgroonga pgroonga.text_full_text_search_ops);
|
||||
"""])
|
||||
]
|
|
@ -262,13 +262,13 @@ class NarrowBuilderTest(ZulipTestCase):
|
|||
@override_settings(USING_PGROONGA=True)
|
||||
def test_add_term_using_search_operator_pgroonga(self) -> None:
|
||||
term = dict(operator='search', operand='"french fries"')
|
||||
self._do_add_term_test(term, 'WHERE search_pgroonga @@ escape_html(:escape_html_1)')
|
||||
self._do_add_term_test(term, 'WHERE search_pgroonga &@~ escape_html(:escape_html_1)')
|
||||
|
||||
@override_settings(USING_PGROONGA=True)
|
||||
def test_add_term_using_search_operator_and_negated_pgroonga(
|
||||
self) -> None: # NEGATED
|
||||
term = dict(operator='search', operand='"french fries"', negated=True)
|
||||
self._do_add_term_test(term, 'WHERE NOT (search_pgroonga @@ escape_html(:escape_html_1))')
|
||||
self._do_add_term_test(term, 'WHERE NOT (search_pgroonga &@~ escape_html(:escape_html_1))')
|
||||
|
||||
def test_add_term_using_has_operator_and_attachment_operand(self) -> None:
|
||||
term = dict(operator='has', operand='attachment')
|
||||
|
|
|
@ -357,15 +357,15 @@ class NarrowBuilder:
|
|||
|
||||
def _by_search_pgroonga(self, query: Query, operand: str,
|
||||
maybe_negate: ConditionTransform) -> Query:
|
||||
match_positions_character = func.pgroonga.match_positions_character
|
||||
query_extract_keywords = func.pgroonga.query_extract_keywords
|
||||
match_positions_character = func.pgroonga_match_positions_character
|
||||
query_extract_keywords = func.pgroonga_query_extract_keywords
|
||||
operand_escaped = func.escape_html(operand)
|
||||
keywords = query_extract_keywords(operand_escaped)
|
||||
query = query.column(match_positions_character(column("rendered_content"),
|
||||
keywords).label("content_matches"))
|
||||
query = query.column(match_positions_character(func.escape_html(column("subject")),
|
||||
keywords).label("subject_matches"))
|
||||
condition = column("search_pgroonga").op("@@")(operand_escaped)
|
||||
condition = column("search_pgroonga").op("&@~")(operand_escaped)
|
||||
return query.where(maybe_negate(condition))
|
||||
|
||||
def _by_search_tsearch(self, query: Query, operand: str,
|
||||
|
|
|
@ -598,16 +598,6 @@ elif REMOTE_POSTGRES_HOST != '':
|
|||
else:
|
||||
DATABASES['default']['OPTIONS']['sslmode'] = 'verify-full'
|
||||
|
||||
if USING_PGROONGA:
|
||||
# We need to have "pgroonga" schema before "pg_catalog" schema in
|
||||
# the PostgreSQL search path, because "pgroonga" schema overrides
|
||||
# the "@@" operator from "pg_catalog" schema, and "pg_catalog"
|
||||
# schema is searched first if not specified in the search path.
|
||||
# See also: http://www.postgresql.org/docs/current/static/runtime-config-client.html
|
||||
pg_options = '-c search_path=%(SCHEMA)s,zulip,public,pgroonga,pg_catalog' % \
|
||||
DATABASES['default']
|
||||
DATABASES['default']['OPTIONS']['options'] = pg_options
|
||||
|
||||
########################################################################
|
||||
# RABBITMQ CONFIGURATION
|
||||
########################################################################
|
||||
|
|
|
@ -34,15 +34,6 @@ DATABASES["default"] = {
|
|||
"TEST_NAME": "django_zulip_tests",
|
||||
"OPTIONS": {"connection_factory": TimeTrackingConnection},
|
||||
}
|
||||
if USING_PGROONGA:
|
||||
# We need to have "pgroonga" schema before "pg_catalog" schema in
|
||||
# the PostgreSQL search path, because "pgroonga" schema overrides
|
||||
# the "@@" operator from "pg_catalog" schema, and "pg_catalog"
|
||||
# schema is searched first if not specified in the search path.
|
||||
# See also: http://www.postgresql.org/docs/current/static/runtime-config-client.html
|
||||
pg_options = '-c search_path=%(SCHEMA)s,zulip,public,pgroonga,pg_catalog' % \
|
||||
DATABASES['default']
|
||||
DATABASES['default']['OPTIONS']['options'] = pg_options
|
||||
|
||||
if "TORNADO_SERVER" in os.environ:
|
||||
# This covers the Casper test suite case
|
||||
|
|
Loading…
Reference in New Issue