mirror of
https://github.com/umap-project/umap.git
synced 2025-05-04 21:51:50 +02:00
Allow to create search index without changing unaccent mutability
cf #519
This commit is contained in:
parent
1194bd3b77
commit
cf149bc450
2 changed files with 10 additions and 10 deletions
|
@ -82,15 +82,15 @@ Start the server
|
|||
UMap uses PostgreSQL tsvector for searching. In case your database is big, you
|
||||
may want to add an index. For that, you should do so:
|
||||
|
||||
# Create a basic search configuration
|
||||
CREATE TEXT SEARCH CONFIGURATION umapdict (COPY=simple);
|
||||
|
||||
# If you also want to deal with accents and case, add this before creating the index
|
||||
CREATE EXTENSION unaccent;
|
||||
CREATE EXTENSION btree_gin;
|
||||
ALTER FUNCTION unaccent(text) IMMUTABLE;
|
||||
ALTER FUNCTION to_tsvector(text) IMMUTABLE;
|
||||
CREATE INDEX search_idx ON leaflet_storage_map USING gin(to_tsvector(unaccent(name)), share_status);
|
||||
ALTER TEXT SEARCH CONFIGURATION umapdict ALTER MAPPING FOR hword, hword_part, word WITH unaccent, simple;
|
||||
|
||||
# Now create the index
|
||||
CREATE INDEX IF NOT EXISTS search_idx ON umap_map USING GIN(to_tsvector('umapdict', name), share_status);
|
||||
|
||||
## Optimisations
|
||||
|
||||
To speed up uMap homepage rendering on a large instance, the following index can be added as well (make sure you set the center to your default instance map center):
|
||||
|
||||
CREATE INDEX leaflet_storage_map_optim ON leaflet_storage_map (modified_at) WHERE ("leaflet_storage_map"."share_status" = 1 AND ST_Distance("leaflet_storage_map"."center", ST_GeomFromEWKT('SRID=4326;POINT(2 51)')) > 1000.0);
|
||||
And change `UMAP_SEARCH_CONFIGURATION = "umapdict"` in your settings.
|
||||
|
|
|
@ -179,9 +179,9 @@ class Search(TemplateView, PaginatorMixin):
|
|||
q = self.request.GET.get("q")
|
||||
results = []
|
||||
if q:
|
||||
where = "to_tsvector(name) @@ plainto_tsquery(%s)"
|
||||
where = "to_tsvector(name) @@ websearch_to_tsquery(%s)"
|
||||
if getattr(settings, "UMAP_USE_UNACCENT", False):
|
||||
where = "to_tsvector(unaccent(name)) @@ plainto_tsquery(unaccent(%s))" # noqa
|
||||
where = "to_tsvector(unaccent(name)) @@ websearch_to_tsquery(unaccent(%s))" # noqa
|
||||
results = Map.objects.filter(share_status=Map.PUBLIC)
|
||||
results = results.extra(where=[where], params=[q])
|
||||
results = results.order_by("-modified_at")
|
||||
|
|
Loading…
Reference in a new issue