Fixes: (1) Removed all `# type: ignore` annotations across the codebase; (2) Fixed usage of Django Model methods by eliminating unnecessary `# type: ignore` directives; (3) Adjusted usage of functions like `get()` to align with method expectations, removing incorrect comments; Extra: (1) Deleted `pyrightconfig.json` as part of migration to a stricter type-checked environment; (2) Minor code cleanup, including formatting changes and refactoring import statements in adherence to PEP8 recommendations.
44 lines
1.2 KiB
Python
44 lines
1.2 KiB
Python
from django_elasticsearch_dsl import fields
|
|
from django_elasticsearch_dsl.registries import registry
|
|
|
|
from engine.blog.models import Post
|
|
from engine.core.elasticsearch import (
|
|
COMMON_ANALYSIS,
|
|
ActiveOnlyMixin,
|
|
add_multilang_fields,
|
|
)
|
|
from engine.core.elasticsearch.documents import BaseDocument
|
|
|
|
|
|
class PostDocument(ActiveOnlyMixin, BaseDocument):
|
|
title = fields.TextField(
|
|
attr="title",
|
|
analyzer="standard",
|
|
fields={
|
|
"raw": fields.KeywordField(ignore_above=256),
|
|
"ngram": fields.TextField(
|
|
analyzer="name_ngram", search_analyzer="icu_query"
|
|
),
|
|
"phonetic": fields.TextField(analyzer="name_phonetic"),
|
|
},
|
|
)
|
|
|
|
class Index:
|
|
name = "posts"
|
|
settings = {
|
|
"number_of_shards": 1,
|
|
"number_of_replicas": 0,
|
|
"analysis": COMMON_ANALYSIS,
|
|
"index": {"max_ngram_diff": 18},
|
|
}
|
|
|
|
class Django:
|
|
model = Post
|
|
fields = ["uuid"]
|
|
|
|
def prepare_title(self, instance: Post) -> str:
|
|
return getattr(instance, "title", "") or ""
|
|
|
|
|
|
add_multilang_fields(PostDocument)
|
|
registry.register_document(PostDocument)
|