Skip to content

Commit

Permalink
Add query highlighting to synthesis response
Browse files Browse the repository at this point in the history
  • Loading branch information
mkhorton committed Apr 25, 2021
1 parent 228e0e5 commit 8856979
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/mp_api/synthesis/models.py
@@ -1,5 +1,5 @@
from pydantic import BaseModel, Field

from typing import List, Dict

class SynthesisDoc(BaseModel):
"""
Expand All @@ -20,3 +20,8 @@ class SynthesisDoc(BaseModel):
None,
description="Synthesis description.",
)

highlights: List[Dict] = Field(
None,
description="Highlighted search terms when searching by keyword(s)."
)
5 changes: 5 additions & 0 deletions src/mp_api/synthesis/resources.py
Expand Up @@ -30,6 +30,10 @@ async def query_synth_text(
"path": "text",
"allowAnalyzedField": True,
},
"highlight": {
"path": "text",
"maxNumPassages": 1
}
}
},
{
Expand All @@ -39,6 +43,7 @@ async def query_synth_text(
"formula": 1,
"text": 1,
"search_score": {"$meta": "searchScore"},
"highlights": {"$meta": "searchHighlights"}
}
},
{"$sort": {"search_score": -1}},
Expand Down

0 comments on commit 8856979

Please sign in to comment.