Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ogc 508 replace elastic search by postgres v3 #1559

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
6ff58c9
Introduce postgres search views and integration (start over from v2 n…
Tschuppi81 Oct 24, 2024
18658fb
Introduce postgres search views and integration (start over from v2 n…
Tschuppi81 Oct 24, 2024
d0aad65
Put only upcoming events to the top of search results (instead of all…
Tschuppi81 Oct 25, 2024
0dd6e57
Revert several changes
Tschuppi81 Oct 25, 2024
0e165e3
store static search property data in separate column. Determine publi…
Tschuppi81 Oct 25, 2024
a3d2a4b
Fix linter issues
Tschuppi81 Oct 25, 2024
54d9860
Fix fsi search views and add tests
Tschuppi81 Oct 25, 2024
2e3816d
fix tests
Tschuppi81 Oct 25, 2024
f4b87d0
Adds to index data and filter for it during search
Tschuppi81 Oct 28, 2024
333f57a
Exclude members from seeing non es_public documents
Tschuppi81 Oct 29, 2024
7e652e4
Ensure member finds documents with access level 'member'
Tschuppi81 Oct 29, 2024
b021ef4
Resolve mypy issues
Tschuppi81 Oct 29, 2024
f75fccf
Fix statement for members
Tschuppi81 Oct 30, 2024
e2f9e00
Removed unused import
Tschuppi81 Oct 30, 2024
037d6ce
Fix member / manager filters
Tschuppi81 Oct 31, 2024
41b2714
Ignore mypy truthy-function and unreachable
Tschuppi81 Nov 4, 2024
0eef94f
Extend search tests
Tschuppi81 Nov 4, 2024
8e50ff5
Revert renaming
Tschuppi81 Nov 11, 2024
e11f317
Test for instance to identify events
Tschuppi81 Nov 11, 2024
1ed1d1d
Renaming variables
Tschuppi81 Nov 11, 2024
b168a85
Update src/onegov/org/models/search.py
Tschuppi81 Nov 12, 2024
39313d0
Update src/onegov/org/models/search.py
Tschuppi81 Nov 12, 2024
14bf8f2
Performance: use jsonb instead of json
Tschuppi81 Nov 14, 2024
c0f95ed
Rework search suggestions
Tschuppi81 Nov 18, 2024
2bdd14c
Fix static number of priorities for properties
Tschuppi81 Nov 25, 2024
8ab1dee
Merge master
Tschuppi81 Dec 2, 2024
d7f0958
mend
Tschuppi81 Dec 2, 2024
7c82279
Filter search models removing base classes
Tschuppi81 Dec 3, 2024
b13f212
Cleanup
Tschuppi81 Dec 3, 2024
d34584f
Also compare table name
Tschuppi81 Dec 3, 2024
2db81c5
Index only searchable base classes removing duplicates in search results
Tschuppi81 Dec 13, 2024
324ebbe
Update src/onegov/search/integration.py
Tschuppi81 Dec 16, 2024
e449cd7
Update src/onegov/search/utils.py
Tschuppi81 Dec 16, 2024
11e93ff
Fix syntax
Tschuppi81 Dec 16, 2024
5191975
Revert filter for base models for search
Tschuppi81 Dec 17, 2024
50ac000
Rework test
Tschuppi81 Dec 17, 2024
cad0655
Merge master
Tschuppi81 Dec 17, 2024
1f142d9
Move weighted tsvector to indexing step
Tschuppi81 Dec 23, 2024
d3912d3
Adjust search
Tschuppi81 Dec 24, 2024
127bc26
Adds a time decay function to search results
Tschuppi81 Dec 24, 2024
a68d9fd
Merge branch 'master' into ogc-508-replace-elastic-search-by-postgres-v3
Tschuppi81 Dec 24, 2024
775c48e
Fix test
Tschuppi81 Dec 24, 2024
61f3268
Resolve merge conflicts
Tschuppi81 Jan 17, 2025
95abc04
Town6 is now in h5 tag, simplify strip
Tschuppi81 Jan 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/onegov/agency/views/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
from onegov.agency import AgencyApp
from onegov.agency.layout import AgencySearchLayout
from onegov.core.security import Public
from onegov.org.models import Search
from onegov.org.views.search import search as search_view

from onegov.org.models import Search, SearchPostgres
from onegov.org.views.search import search as search_view, search_postgres

from typing import TYPE_CHECKING
if TYPE_CHECKING:
Expand All @@ -25,3 +24,15 @@ def search(
if isinstance(data, dict):
data['layout'] = AgencySearchLayout(self, request)
return data


@AgencyApp.html(model=SearchPostgres, template='search_postgres.pt',
permission=Public)
def agency_search_postgres(
self: SearchPostgres[Base],
request: AgencyRequest
) -> RenderData | Response:
data = search_postgres(self, request)
if isinstance(data, dict):
data['layout'] = AgencySearchLayout(self, request)
return data
2 changes: 1 addition & 1 deletion src/onegov/directory/models/directory_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ class DirectoryEntry(Base, ContentMixin, CoordinatesMixin, TimestampMixin,
__tablename__ = 'directory_entries'

es_properties = {
'keywords': {'type': 'keyword'},
'title': {'type': 'localized'},
'lead': {'type': 'localized'},
'keywords': {'type': 'keyword'},
'directory_id': {'type': 'keyword'},

# since the searchable text might include html, we remove it
Expand Down
42 changes: 33 additions & 9 deletions src/onegov/fsi/views/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

from onegov.core.security import Personal
from onegov.fsi import FsiApp
from onegov.org.models import Search
from onegov.town6.views.search import town_search as search_view
from onegov.org.views.search import suggestions as suggestions_view

from onegov.fsi.layout import DefaultLayout
from onegov.org.models import Search, SearchPostgres
from onegov.org.views.search import (search, search_postgres,
suggestions, suggestions_postgres)

from typing import TYPE_CHECKING
if TYPE_CHECKING:
Expand All @@ -15,17 +15,41 @@
from webob import Response


@FsiApp.html(model=Search, template='search.pt', permission=Personal)
def search(
@FsiApp.html(
model=Search,
template='search.pt',
permission=Personal
)
def fsi_search(
self: Search[Base],
request: FsiRequest
) -> RenderData | Response:
return search_view(self, request)
return search(self, request, DefaultLayout(self, request))


@FsiApp.html(
model=SearchPostgres,
template='search_postgres.pt',
permission=Personal
)
def fsi_search_postgres(
self: SearchPostgres[Base],
request: FsiRequest
) -> RenderData | Response:
return search_postgres(self, request, DefaultLayout(self, request))


@FsiApp.json(model=Search, name='suggest', permission=Personal)
def suggestions(
def fsi_suggestions(
self: Search[Base],
request: FsiRequest
) -> JSON_ro:
return suggestions_view(self, request)
return suggestions(self, request)


@FsiApp.json(model=SearchPostgres, name='suggest', permission=Personal)
def fsi_suggestions_postgres(
self: SearchPostgres[Base],
request: FsiRequest
) -> JSON_ro:
return suggestions_postgres(self, request)

Check warning on line 55 in src/onegov/fsi/views/search.py

View check run for this annotation

Codecov / codecov/patch

src/onegov/fsi/views/search.py#L55

Added line #L55 was not covered by tests
14 changes: 11 additions & 3 deletions src/onegov/landsgemeinde/views/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
from onegov.core.security import Public
from onegov.landsgemeinde import LandsgemeindeApp
from onegov.landsgemeinde.layouts import DefaultLayout
from onegov.org.models import Search
from onegov.org.views.search import search

from onegov.org.models import Search, SearchPostgres
from onegov.org.views.search import search, search_postgres

from typing import TYPE_CHECKING
if TYPE_CHECKING:
Expand All @@ -21,3 +20,12 @@ def landsgemeinde_search(
request: LandsgemeindeRequest
) -> RenderData | Response:
return search(self, request, DefaultLayout(self, request))


@LandsgemeindeApp.html(model=SearchPostgres, template='search_postgres.pt',
permission=Public)
def landsgemeinde_search_postgres(
self: SearchPostgres[Base],
request: LandsgemeindeRequest
) -> RenderData | Response:
return search_postgres(self, request, DefaultLayout(self, request))
4 changes: 2 additions & 2 deletions src/onegov/onboarding/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
from onegov.file import DepotApp
from onegov.onboarding.theme import OnboardingTheme
from onegov.reservation import LibresIntegration
from onegov.search import ElasticsearchApp
from onegov.search import SearchApp


from typing import Any, TYPE_CHECKING
if TYPE_CHECKING:
from collections.abc import Iterator


class OnboardingApp(Framework, LibresIntegration, DepotApp, ElasticsearchApp):
class OnboardingApp(Framework, LibresIntegration, DepotApp, SearchApp):

serve_static_files = True

Expand Down
2 changes: 1 addition & 1 deletion src/onegov/onboarding/models/town_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def add_town(
'org': name
})

self.app.es_perform_reindex()
self.app.perform_reindex()
self.app.send_transactional_email(
subject=title,
receivers=(user, ),
Expand Down
4 changes: 2 additions & 2 deletions src/onegov/org/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from onegov.org.theme import OrgTheme
from onegov.pay import PayApp
from onegov.reservation import LibresIntegration
from onegov.search import ElasticsearchApp
from onegov.search import SearchApp
from onegov.ticket import TicketCollection
from onegov.ticket import TicketPermission
from onegov.user import UserApp
Expand All @@ -55,7 +55,7 @@
from webob import Response


class OrgApp(Framework, LibresIntegration, ElasticsearchApp, MapboxApp,
class OrgApp(Framework, LibresIntegration, SearchApp, MapboxApp,
DepotApp, PayApp, FormApp, UserApp, WebsocketsApp):

serve_static_files = True
Expand Down
2 changes: 1 addition & 1 deletion src/onegov/org/cronjobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def publish_files(request: OrgRequest) -> None:
def reindex_published_models(request: OrgRequest) -> None:
"""
Reindexes all recently published/unpublished objects
in the elasticsearch database.
in the elasticsearch and postgres database.

For pages it also updates the propagated access to any
associated files.
Expand Down
9 changes: 9 additions & 0 deletions src/onegov/org/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
from onegov.org.models.extensions import PersonLinkExtension
from onegov.org.models.external_link import ExternalLinkCollection
from onegov.org.models.form import submission_deletable
from onegov.org.models.search import SearchPostgres
from onegov.org.open_graph import OpenGraphMixin
from onegov.org.theme.org_theme import user_options
from onegov.org.utils import IMG_URLS
Expand Down Expand Up @@ -338,11 +339,19 @@ def homepage_url(self) -> str:
@cached_property
def search_url(self) -> str:
""" Returns the url to the search page. """
# Allows using postgres search while es search remains default
if (self.request.path_info
and 'search-postgres' in self.request.path_info):
return self.request.class_link(SearchPostgres)
return self.request.class_link(Search)

@cached_property
def suggestions_url(self) -> str:
""" Returns the url to the suggestions json view. """
# Allows using postgres search while es search remains default
if (self.request.path_info
and 'search-postgres' in self.request.path_info):
return self.request.class_link(SearchPostgres, name='suggest')
return self.request.class_link(Search, name='suggest')

@cached_property
Expand Down
3 changes: 2 additions & 1 deletion src/onegov/org/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
from onegov.org.models.recipient import ResourceRecipient
from onegov.org.models.recipient import ResourceRecipientCollection
from onegov.org.models.resource import DaypassResource
from onegov.org.models.search import Search
from onegov.org.models.search import Search, SearchPostgres
from onegov.org.models.sitecollection import SiteCollection
from onegov.org.models.swiss_holidays import SwissHolidays
from onegov.org.models.tan import TANAccess
Expand Down Expand Up @@ -103,6 +103,7 @@
'ResourceRecipient',
'ResourceRecipientCollection',
'Search',
'SearchPostgres',
'SiteCollection',
'SubmissionMessage',
'SwissHolidays',
Expand Down
Loading
Loading