File tree Expand file tree Collapse file tree 7 files changed +14
-7
lines changed Expand file tree Collapse file tree 7 files changed +14
-7
lines changed Original file line number Diff line number Diff line change 4848 from .field import Field
4949 from .index_base import IndexBase
5050 from .response import Hit # noqa: F401
51+ from .types import Hit as HitBaseType
5152
5253UsingType : TypeAlias = Union [str , "Elasticsearch" ]
5354AsyncUsingType : TypeAlias = Union [str , "AsyncElasticsearch" ]
@@ -468,7 +469,13 @@ def _clone(self) -> Self:
468469 return c
469470
470471
471- class HitMeta (AttrDict [Any ]):
472+ if TYPE_CHECKING :
473+ HitMetaBase = HitBaseType
474+ else :
475+ HitMetaBase = AttrDict [Any ]
476+
477+
478+ class HitMeta (HitMetaBase ):
472479 def __init__ (
473480 self ,
474481 document : Dict [str , Any ],
Original file line number Diff line number Diff line change @@ -190,7 +190,7 @@ async def get_answers(self) -> List[Any]:
190190 elasticsearch.
191191 """
192192 if "inner_hits" in self .meta and "answer" in self .meta .inner_hits :
193- return cast (List [Any ], self .meta .inner_hits . answer .hits )
193+ return cast (List [Any ], self .meta .inner_hits [ " answer" ] .hits )
194194 return [a async for a in self .search_answers ()]
195195
196196 async def save (self , ** kwargs : Any ) -> None : # type: ignore[override]
Original file line number Diff line number Diff line change @@ -186,7 +186,7 @@ async def main() -> None:
186186 )
187187 print (f"Summary: { hit .summary } " )
188188 if args .show_inner_hits :
189- for passage in hit .meta .inner_hits . passages :
189+ for passage in hit .meta .inner_hits [ " passages" ] :
190190 print (f" - [Score: { passage .meta .score } ] { passage .content !r} " )
191191 print ("" )
192192
Original file line number Diff line number Diff line change @@ -175,7 +175,7 @@ async def main() -> None:
175175 )
176176 print (f"Summary: { hit .summary } " )
177177 if args .show_inner_hits :
178- for passage in hit .meta .inner_hits . passages :
178+ for passage in hit .meta .inner_hits [ " passages" ] :
179179 print (f" - [Score: { passage .meta .score } ] { passage .content !r} " )
180180 print ("" )
181181
Original file line number Diff line number Diff line change @@ -189,7 +189,7 @@ def get_answers(self) -> List[Any]:
189189 elasticsearch.
190190 """
191191 if "inner_hits" in self .meta and "answer" in self .meta .inner_hits :
192- return cast (List [Any ], self .meta .inner_hits . answer .hits )
192+ return cast (List [Any ], self .meta .inner_hits [ " answer" ] .hits )
193193 return [a for a in self .search_answers ()]
194194
195195 def save (self , ** kwargs : Any ) -> None : # type: ignore[override]
Original file line number Diff line number Diff line change @@ -185,7 +185,7 @@ def main() -> None:
185185 )
186186 print (f"Summary: { hit .summary } " )
187187 if args .show_inner_hits :
188- for passage in hit .meta .inner_hits . passages :
188+ for passage in hit .meta .inner_hits [ " passages" ] :
189189 print (f" - [Score: { passage .meta .score } ] { passage .content !r} " )
190190 print ("" )
191191
Original file line number Diff line number Diff line change @@ -174,7 +174,7 @@ def main() -> None:
174174 )
175175 print (f"Summary: { hit .summary } " )
176176 if args .show_inner_hits :
177- for passage in hit .meta .inner_hits . passages :
177+ for passage in hit .meta .inner_hits [ " passages" ] :
178178 print (f" - [Score: { passage .meta .score } ] { passage .content !r} " )
179179 print ("" )
180180
You can’t perform that action at this time.
0 commit comments