1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-19 13:54:25 +01:00

poc using tsvector

This commit is contained in:
Sylvain 2020-06-17 16:49:38 +02:00
parent 40dd39304e
commit a164ec402d
6 changed files with 32 additions and 2 deletions

View File

@ -86,6 +86,24 @@ class Project < ApplicationRecord
end
def self.search(params, current_user)
connection = ActiveRecord::Base.connection
return unless connection.instance_values['config'][:adapter] == 'postgresql'
return connection.execute <<~SQL
SELECT pid, p_name
FROM (SELECT projects.id as pid,
projects.name as p_name,
to_tsvector('#{Rails.application.secrets.postgresql_language_analyzer}', unaccent(projects.tags)) ||
to_tsvector('#{Rails.application.secrets.postgresql_language_analyzer}', unaccent(projects.name)) ||
to_tsvector('#{Rails.application.secrets.postgresql_language_analyzer}', unaccent(projects.description)) ||
to_tsvector('#{Rails.application.secrets.postgresql_language_analyzer}', unaccent(projects.description)) ||
to_tsvector('#{Rails.application.secrets.postgresql_language_analyzer}', unaccent(ps.title)) ||
to_tsvector('#{Rails.application.secrets.postgresql_language_analyzer}', unaccent(ps.description)) as document
FROM projects
JOIN project_steps ps on projects.id = ps.project_id) p_search
WHERE p_search.document @@ to_tsquery('#{Rails.application.secrets.postgresql_language_analyzer}', unaccent('#{params['q']}'));
SQL
Project.__elasticsearch__.search(build_search_query_from_context(params, current_user))
end

View File

@ -26,6 +26,7 @@ development:
angular_locale: <%= ENV["ANGULAR_LOCALE"] %>
fullcalendar_locale: <%= ENV["FULLCALENDAR_LOCALE"] %>
elasticsearch_language_analyzer: <%= ENV["ELASTICSEARCH_LANGUAGE_ANALYZER"] %>
postgresql_language_analyzer: <%= ENV.fetch("POSTGRESQL_LANGUAGE_ANALYZER", 'simple') %>
openlab_base_uri: <%= ENV["OPENLAB_BASE_URI"] %>
navinum_api_login: <%= ENV["NAVINUM_API_LOGIN"] %>
navinum_api_password: <%= ENV["NAVINUM_API_PASSWORD"] %>
@ -54,6 +55,7 @@ test:
angular_locale: en-us
fullcalendar_locale: en
elasticsearch_language_analyzer: french
postgresql_language_analyzer: french
openlab_base_uri:
navinum_api_login:
navinum_api_password:
@ -90,6 +92,7 @@ staging:
angular_locale: <%= ENV["ANGULAR_LOCALE"] %>
fullcalendar_locale: <%= ENV["FULLCALENDAR_LOCALE"] %>
elasticsearch_language_analyzer: <%= ENV["ELASTICSEARCH_LANGUAGE_ANALYZER"] %>
postgresql_language_analyzer: <%= ENV.fetch("POSTGRESQL_LANGUAGE_ANALYZER", 'simple') %>
openlab_base_uri: <%= ENV["OPENLAB_BASE_URI"] %>
navinum_api_login: <%= ENV["NAVINUM_API_LOGIN"] %>
navinum_api_password: <%= ENV["NAVINUM_API_PASSWORD"] %>
@ -129,6 +132,7 @@ production:
angular_locale: <%= ENV["ANGULAR_LOCALE"] %>
fullcalendar_locale: <%= ENV["FULLCALENDAR_LOCALE"] %>
elasticsearch_language_analyzer: <%= ENV["ELASTICSEARCH_LANGUAGE_ANALYZER"] %>
postgresql_language_analyzer: <%= ENV.fetch("POSTGRESQL_LANGUAGE_ANALYZER", 'simple') %>
openlab_base_uri: <%= ENV["OPENLAB_BASE_URI"] %>
navinum_api_login: <%= ENV["NAVINUM_API_LOGIN"] %>
navinum_api_password: <%= ENV["NAVINUM_API_PASSWORD"] %>

View File

@ -200,6 +200,12 @@ See [github.com/fullcalendar/fullcalendar/lang/*.js](https://github.com/fullcale
This configure the language analyzer for indexing and searching in projects with ElasticSearch.
See [ElasticSearch guide](https://www.elastic.co/guide/en/elasticsearch/reference/5.6/analysis-lang-analyzer.html) for a list of available analyzers.
<a name="POSTGRESQL_LANGUAGE_ANALYZER"></a>
POSTGRESQL_LANGUAGE_ANALYZER
This variable configures the language analyzer for indexing and searching in projets with PostgreSQL.
List all available values with `docker-compose exec -T postgres psql -Upostgres -c \\dFd | head -n -2 | tail -n +3 | awk '{ print gensub(/([a-z]+)_stem/,"\\1","g",$3); }'`
<a name="TIME_ZONE"></a>
TIME_ZONE

View File

@ -34,6 +34,7 @@ FORCE_VERSION_CHECK=false
ALLOW_INSECURE_HTTP=false
ELASTICSEARCH_LANGUAGE_ANALYZER=french
POSTGRESQL_LANGUAGE_ANALYZER=french
TIME_ZONE=Paris
WEEK_STARTING_DAY=monday

View File

@ -28,6 +28,7 @@ ANGULAR_LOCALE=fr-fr
FULLCALENDAR_LOCALE=fr
ELASTICSEARCH_LANGUAGE_ANALYZER=french
POSTGRESQL_LANGUAGE_ANALYZER=french
TIME_ZONE=Paris
WEEK_STARTING_DAY=monday

View File

@ -236,8 +236,8 @@ configure_env_file()
doc=$(\curl -sSL https://raw.githubusercontent.com/sleede/fab-manager/master/doc/environment.md)
variables=(DEFAULT_HOST DEFAULT_PROTOCOL DELIVERY_METHOD SMTP_ADDRESS SMTP_PORT SMTP_USER_NAME SMTP_PASSWORD SMTP_AUTHENTICATION \
SMTP_ENABLE_STARTTLS_AUTO SMTP_OPENSSL_VERIFY_MODE SMTP_TLS LOG_LEVEL MAX_IMAGE_SIZE MAX_CAO_SIZE MAX_IMPORT_SIZE DISK_SPACE_MB_ALERT \
SUPERADMIN_EMAIL APP_LOCALE RAILS_LOCALE MOMENT_LOCALE SUMMERNOTE_LOCALE ANGULAR_LOCALE FULLCALENDAR_LOCALE ELASTICSEARCH_LANGUAGE_ANALYZER TIME_ZONE \
WEEK_STARTING_DAY D3_DATE_FORMAT UIB_DATE_FORMAT EXCEL_DATE_FORMAT)
SUPERADMIN_EMAIL APP_LOCALE RAILS_LOCALE MOMENT_LOCALE SUMMERNOTE_LOCALE ANGULAR_LOCALE FULLCALENDAR_LOCALE ELASTICSEARCH_LANGUAGE_ANALYZER \
POSTGRESQL_LANGUAGE_ANALYZER TIME_ZONE WEEK_STARTING_DAY D3_DATE_FORMAT UIB_DATE_FORMAT EXCEL_DATE_FORMAT)
for variable in "${variables[@]}"; do
local var_doc current
var_doc=$(get_md_anchor "$doc" "$variable")