Skip to content

Instantly share code, notes, and snippets.

@Ananto30
Created November 4, 2020 05:13
Show Gist options
  • Save Ananto30/3781b5cbbf22621d7976b5f530dcdee4 to your computer and use it in GitHub Desktop.
Save Ananto30/3781b5cbbf22621d7976b5f530dcdee4 to your computer and use it in GitHub Desktop.
db[collection].aggregate(
[
{
"$search": {
"compound": {
"must": [
{
"text": {
"query": term,
"path": ["body_en", "chapter_en"],
"fuzzy": {"maxEdits": 1, "maxExpansions": 10},
}
}
],
"should": [
{
"phrase": {
"query": term,
"path": "body_en",
"slop": 2,
}
}
],
},
"highlight": {"path": ["body_en", "chapter_en"]},
}
},
{"$limit": 50},
{
"$project": {
"_id": 0,
"collection_id": 1,
"collection": 1,
"hadith_no": 1,
"book_no": 1,
"book_en": 1,
"chapter_no": 1,
"chapter_en": 1,
"narrator_en": 1,
"body_en": 1,
"book_ref_no": 1,
"hadith_grade": 1,
"score": {"$meta": "searchScore"},
"highlights": {"$meta": "searchHighlights"},
}
},
]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment