Skip to content

Commit

Permalink
Merged fixes for ASKBOT#845 and ASKBOT#846
Browse files Browse the repository at this point in the history
  • Loading branch information
mag3me committed Dec 12, 2019
2 parents 7a3b351 + 8c3739e commit 030bd7a
Show file tree
Hide file tree
Showing 20 changed files with 26 additions and 94 deletions.
6 changes: 3 additions & 3 deletions askbot/doc/source/mysql-to-postgres.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ Test this by running a search query on the askbot site.

..
If you have an issue with the above command, it is possible to run the search setup sql script manually:
1. Download `thread_and_post_models_10032013.plsql <https://raw.github.com/ASKBOT/askbot-devel/master/askbot/search/postgresql/thread_and_post_models_10032013.plsql>`_
2. Download `user_profile_search_08312012.plsql <https://raw.github.com/ASKBOT/askbot-devel/master/askbot/search/postgresql/user_profile_search_08312012.plsql>`_
1. Download `thread_and_post_models_03012016.plsql <https://raw.github.com/ASKBOT/askbot-devel/master/askbot/search/postgresql/thread_and_post_models_03012016.plsql>`_
2. Download `user_profile_search_12202015.plsql <https://raw.github.com/ASKBOT/askbot-devel/master/askbot/search/postgresql/user_profile_search_12202015.plsql>`_
3. Apply the scripts to your postgres database::
psql your_database < thread_and_post_models_10032013.plsql
psql your_database < user_profile_search_08312012.plsql
psql your_database < user_profile_search_12202015.plsql

Fixing data types
Expand Down
4 changes: 2 additions & 2 deletions askbot/migrations/0004_auto_20151219_0751.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ def init_postgresql_fts(apps, schema_editor):
askbot.get_install_directory(),
'search',
'postgresql',
'thread_and_post_models_10032013.plsql'
'thread_and_post_models_03012016.plsql'
)
setup_full_text_search(script_path)

script_path = os.path.join(
askbot.get_install_directory(),
'search',
'postgresql',
'user_profile_search_12192015.plsql'
'user_profile_search_12202015.plsql'
)
setup_full_text_search(script_path)

Expand Down
37 changes: 0 additions & 37 deletions askbot/migrations/0007_auto_20151220_0653.py

This file was deleted.

3 changes: 2 additions & 1 deletion askbot/migrations/0008_auto_20160101_0951.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
class Migration(migrations.Migration):

dependencies = [
('askbot', '0007_auto_20151220_0653'),
('askbot', '0006_auto_20151220_0459'),

]

operations = [
Expand Down
28 changes: 0 additions & 28 deletions askbot/migrations/0009_auto_20160103_1150.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def calculate_localized_reps(apps, schema_editor):
class Migration(migrations.Migration):

dependencies = [
('askbot', '0009_auto_20160103_1150'),
('askbot', '0008_auto_20160101_0951'),
]

operations = [
Expand Down
28 changes: 12 additions & 16 deletions askbot/search/postgresql/thread_and_post_models_03012016.plsql
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/* function testing for existence of a column in a table
if table does not exists, function will return "false" */
CREATE OR REPLACE FUNCTION column_exists(colname text, tablename text)
RETURNS boolean AS
RETURNS boolean AS
$$
DECLARE
q text;
onerow record;
BEGIN

q = 'SELECT attname FROM pg_attribute WHERE attrelid = ( SELECT oid FROM pg_class WHERE relname = '''||tablename||''') AND attname = '''||colname||'''';
q = 'SELECT attname FROM pg_attribute WHERE attrelid = ( SELECT oid FROM pg_class WHERE relname = '''||tablename||''') AND attname = '''||colname||'''';

FOR onerow IN EXECUTE q LOOP
RETURN true;
Expand Down Expand Up @@ -48,12 +48,8 @@ $$ LANGUAGE plpgsql;

CREATE OR REPLACE FUNCTION setup_aggregates() RETURNS boolean AS
$$
DECLARE
onerow record;
BEGIN
FOR onerow IN SELECT * FROM pg_proc WHERE proname = 'concat_tsvectors' AND proisagg LOOP
DROP AGGREGATE concat_tsvectors(tsvector);
END LOOP;
DROP AGGREGATE IF EXISTS concat_tsvectors(tsvector);
CREATE AGGREGATE concat_tsvectors (
BASETYPE = tsvector,
SFUNC = tsv_add,
Expand Down Expand Up @@ -181,7 +177,7 @@ DECLARE
onerow record;
BEGIN
query = 'SELECT concat_tsvectors(text_search_vector), count(*) FROM askbot_post' ||
' WHERE parent_id=' || parent_id ||
' WHERE parent_id=' || parent_id ||
' AND post_type=''comment'' AND deleted=false';
FOR onerow IN EXECUTE query LOOP
IF onerow.count = 0 THEN
Expand Down Expand Up @@ -259,7 +255,7 @@ BEGIN
RETURN new;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER thread_search_vector_update_trigger
CREATE TRIGGER thread_search_vector_update_trigger
BEFORE UPDATE ON askbot_thread FOR EACH ROW EXECUTE PROCEDURE thread_update_trigger();

CREATE OR REPLACE FUNCTION thread_insert_trigger() RETURNS trigger AS
Expand All @@ -283,7 +279,7 @@ BEGIN
new.post_type,
new.language_code
);
UPDATE askbot_thread SET text_search_vector=text_search_vector ||
UPDATE askbot_thread SET text_search_vector=text_search_vector ||
new.text_search_vector WHERE id=new.thread_id;
ELSIF new.post_type = 'comment' THEN
new.text_search_vector = get_post_tsv(
Expand All @@ -297,14 +293,14 @@ BEGIN
return new;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER post_search_vector_insert_trigger
BEFORE INSERT ON askbot_post
FOR EACH ROW
CREATE TRIGGER post_search_vector_insert_trigger
BEFORE INSERT ON askbot_post
FOR EACH ROW
EXECUTE PROCEDURE post_trigger();

CREATE TRIGGER post_search_vector_update_trigger
BEFORE UPDATE ON askbot_post
FOR EACH ROW
CREATE TRIGGER post_search_vector_update_trigger
BEFORE UPDATE ON askbot_post
FOR EACH ROW
WHEN (
(old.text IS DISTINCT FROM new.text)
OR (old.text_search_vector IS DISTINCT FROM new.text_search_vector)
Expand Down
12 changes: 6 additions & 6 deletions askbot/search/postgresql/user_profile_search_12202015.plsql
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
/*
Script depends on functions defined for general askbot full text search.
to_tsvector(), add_tsvector_column()

calculates text search vector for the user profile
the searched fields are:
the searched fields are:
1) user name
2) user profile
3) group names - for groups to which user belongs
Expand Down Expand Up @@ -40,8 +40,8 @@ BEGIN
'INNER JOIN askbot_userprofile AS p ON id=p.auth_user_ptr_id ' ||
'WHERE id=' || user_id;
FOR onerow in EXECUTE user_query LOOP
tsv = tsv ||
to_tsvector(onerow.username) ||
tsv = tsv ||
to_tsvector(onerow.username) ||
to_tsvector(onerow.real_name) ||
to_tsvector(onerow.email);
END LOOP;
Expand Down Expand Up @@ -69,7 +69,7 @@ $$ LANGUAGE plpgsql;
DROP TRIGGER IF EXISTS auth_user_tsv_update_trigger ON auth_user;

CREATE TRIGGER auth_user_tsv_update_trigger
BEFORE INSERT OR UPDATE ON auth_user
BEFORE INSERT OR UPDATE ON auth_user
FOR EACH ROW EXECUTE PROCEDURE auth_user_tsv_update_handler();

/* localized user profile trigger */
Expand Down Expand Up @@ -132,7 +132,7 @@ AFTER INSERT OR DELETE
ON auth_user_groups
FOR EACH ROW EXECUTE PROCEDURE group_membership_tsv_update_handler();

/* todo: whenever group name changes - also
/* todo: whenever group name changes - also
* reindex users belonging to the group */

DROP INDEX IF EXISTS auth_user_search_idx;
Expand Down

0 comments on commit 030bd7a

Please sign in to comment.