Skip to content

Commit

Permalink
fix: add functions and institutions to person documents
Browse files Browse the repository at this point in the history
Closes: #15
  • Loading branch information
b1rger committed Feb 20, 2024
1 parent b40346b commit 32d22e5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
5 changes: 3 additions & 2 deletions viecpro_typesense/collections.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .handlers import GenericDocIDHandler
from viecpro_typesense import Collection, StaticField, CollectionConfig, O
from copy import deepcopy
from .fields import StringField, FullNameField, TitlesNestedObjectField, RelationTypeHierarchyHandler, WrittenDateField, BibtexShortTitleHandler, BibtexTitleHandler, BibtexTypeHandler, RelatedReferenceDocField, ObjectIDField, DateObjectDateField, LabelsNestedObjectField, KindField, SourceField, TargetField, HofstaatsinhaberField, MainOwnerField
from .fields import StringField, FullNameField, TitlesNestedObjectField, RelationTypeHierarchyHandler, WrittenDateField, BibtexShortTitleHandler, BibtexTitleHandler, BibtexTypeHandler, RelatedReferenceDocField, ObjectIDField, DateObjectDateField, LabelsNestedObjectField, KindField, SourceField, TargetField, HofstaatsinhaberField, MainOwnerField, FunctionsArrayField, PersonInstitutionArrayField
from apis_bibsonomy.models import Reference
from apis_core.apis_relations.models import AbstractRelation
from apis_core.apis_entities.models import AbstractEntity, Institution, Person, Place, Event, Work
Expand Down Expand Up @@ -99,7 +99,8 @@ def create_entity_collections():
"fullname": FullNameField(("name", "first_name"), options=O(sort=True)),
"gender": StringField("gender", options=O(facet=True, optional=True, type="string")),
"titles": TitlesNestedObjectField("id", pass_instance=True),
# "functions": FunctionsArrayField("id", pass_instance=True),# TODO: need to remove need to pass field param to field with pass_instance. id won't be accessed here, its a dummy
"functions": FunctionsArrayField("id", pass_instance=True, options=O(facet=True)),# TODO: need to remove need to pass field param to field with pass_instance. id won't be accessed here, its a dummy
"institutions": PersonInstitutionArrayField("id", pass_instance=True, options=O(facet=True)),
}
base_fields.update(per_fields)
detail_fields = get_entity_specific_detail_fields(
Expand Down
11 changes: 9 additions & 2 deletions viecpro_typesense/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,15 @@ class Config:


class FunctionsArrayField(Field):
handler = ParseFunctionsHandler
options = O(type="object", optional=True)
class Config:
handler = ParseFunctionsHandler
options = O(type="string[]", optional=True)


class PersonInstitutionArrayField(Field):
class Config:
handler = ParsePersonInstitutionHandler
options = O(type="string[]", optional=True)


class SourceField(Field):
Expand Down
10 changes: 5 additions & 5 deletions viecpro_typesense/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ def func(x): return [


class ParseFunctionsHandler(Handler):
def func(x): return [
{"name": f.name, "object_id": str(
f.id), "model": "PersonInstitutionRelation"}
for f in x.institution_relationtype_set.all()
]
def func(x): return [f.name for f in x.institution_relationtype_set.all()]


class ParsePersonInstitutionHandler(Handler):
def func(x): return [f.name for f in x.personinstitution_set.all()]


class GenericDocIDHandler(Handler):
Expand Down

0 comments on commit 32d22e5

Please sign in to comment.