Skip to content

Commit

Permalink
makes directory entries searchable
Browse files Browse the repository at this point in the history
  • Loading branch information
Tschuppi81 committed Jul 18, 2024
1 parent 5718732 commit 737fb14
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/onegov/directory/models/directory_entry.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from sqlalchemy.ext.hybrid import hybrid_property

from onegov.core.orm import Base
from onegov.core.orm.mixins import ContentMixin
from onegov.core.orm.mixins import TimestampMixin
Expand All @@ -6,7 +8,7 @@
from onegov.file import AssociatedFiles
from onegov.gis import CoordinatesMixin
from onegov.search import SearchableContent
from sqlalchemy import Column
from sqlalchemy import Column, cast
from sqlalchemy import ForeignKey
from sqlalchemy import Index
from sqlalchemy import Text
Expand All @@ -30,10 +32,10 @@ class DirectoryEntry(Base, ContentMixin, CoordinatesMixin, TimestampMixin,
__tablename__ = 'directory_entries'

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

# since the searchable text might include html, we remove it
# even if there's no html -> possibly decreasing the search
Expand All @@ -43,6 +45,7 @@ class DirectoryEntry(Base, ContentMixin, CoordinatesMixin, TimestampMixin,

@property
def es_public(self) -> bool:
return True # for tests

Check warning on line 48 in src/onegov/directory/models/directory_entry.py

View check run for this annotation

Codecov / codecov/patch

src/onegov/directory/models/directory_entry.py#L48

Added line #L48 was not covered by tests
return False # to be overridden downstream

#: An interal id for references (not public)
Expand Down Expand Up @@ -109,6 +112,10 @@ def external_link_title(self) -> str | None:
def external_link_visible(self) -> bool | None:
return self.directory.configuration.link_visible

@hybrid_property
def _directory_id(self):
return cast(self.directory_id, Text)

@property
def directory_name(self) -> str:
return self.directory.name
Expand All @@ -117,13 +124,18 @@ def directory_name(self) -> str:
def keywords(self) -> set[str]:
return set(self._keywords.keys()) if self._keywords else set()

# @property
@hybrid_property
def keywords_as_text(self) -> str:
return cast(self._keywords.keys(), Text)

# FIXME: asymmetric properties are not supported by mypy, switch to
# a custom descriptor, if desired.
@keywords.setter
def keywords(self, value: 'Collection[str] | None') -> None:
self._keywords = dict.fromkeys(value, '') if value else None

@property
@hybrid_property
def text(self) -> str:
return self.directory.configuration.extract_searchable(self.values)

Expand Down

0 comments on commit 737fb14

Please sign in to comment.