Skip to content

Commit

Permalink
Fix total_doc synth population (#322)
Browse files Browse the repository at this point in the history
* Fix total_doc synth population with other criteria

* Update synthesis query op test
  • Loading branch information
Jason Munro authored Jul 6, 2021
1 parent 1366950 commit a31b032
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 47 deletions.
5 changes: 4 additions & 1 deletion src/mp_api/routes/synthesis/query_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,10 @@ def query(
}

if crit:
pipeline[-1]["$facet"]["results"].append({"$match": crit})
if keywords:
pipeline.insert(1, {"$match": crit})
else:
pipeline.insert(0, {"$match": crit})

pipeline[-1]["$facet"]["total_doc"].append({"$count": "count"})
pipeline.extend(
Expand Down
72 changes: 26 additions & 46 deletions tests/synthesis/test_query_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ def test_synthesis_search_query():
for keywords in keyword_lists:
pipeline = (
[
{
"$match": {
"synthesis_type": {"$in": ["solid-state"]},
"targets_formula_s": "SiO2",
"precursors_formula_s": "SiO2",
"operations.type": {"$all": ["ShapingOperation"]},
"operations.conditions.heating_temperature.values": {"$lte": 5},
"operations.conditions.heating_time.values": {"$lte": 5},
"operations.conditions.heating_atmosphere": {"$all": "air"},
"operations.conditions.mixing_device": {"$all": "zirconia"},
"operations.conditions.mixing_media": {"$all": "water"},
}
},
{
"$facet": {
"results": [
Expand All @@ -33,29 +46,6 @@ def test_synthesis_search_query():
"paragraph_string": 1,
}
},
{
"$match": {
"synthesis_type": {"$in": ["solid-state"]},
"targets_formula_s": "SiO2",
"precursors_formula_s": "SiO2",
"operations.type": {"$all": ["ShapingOperation"]},
"operations.conditions.heating_temperature.values": {
"$lte": 5
},
"operations.conditions.heating_time.values": {
"$lte": 5
},
"operations.conditions.heating_atmosphere": {
"$all": "air"
},
"operations.conditions.mixing_device": {
"$all": "zirconia"
},
"operations.conditions.mixing_media": {
"$all": "water"
},
}
},
],
"total_doc": [{"$count": "count"}],
}
Expand Down Expand Up @@ -85,6 +75,19 @@ def test_synthesis_search_query():
"highlight": {"path": "paragraph_string"},
}
},
{
"$match": {
"synthesis_type": {"$in": ["solid-state"]},
"targets_formula_s": "SiO2",
"precursors_formula_s": "SiO2",
"operations.type": {"$all": ["ShapingOperation"]},
"operations.conditions.heating_temperature.values": {"$lte": 5},
"operations.conditions.heating_time.values": {"$lte": 5},
"operations.conditions.heating_atmosphere": {"$all": "air"},
"operations.conditions.mixing_device": {"$all": "zirconia"},
"operations.conditions.mixing_media": {"$all": "water"},
}
},
{
"$facet": {
"results": [
Expand All @@ -106,29 +109,6 @@ def test_synthesis_search_query():
"highlights": {"$meta": "searchHighlights"},
}
},
{
"$match": {
"synthesis_type": {"$in": ["solid-state"]},
"targets_formula_s": "SiO2",
"precursors_formula_s": "SiO2",
"operations.type": {"$all": ["ShapingOperation"]},
"operations.conditions.heating_temperature.values": {
"$lte": 5
},
"operations.conditions.heating_time.values": {
"$lte": 5
},
"operations.conditions.heating_atmosphere": {
"$all": "air"
},
"operations.conditions.mixing_device": {
"$all": "zirconia"
},
"operations.conditions.mixing_media": {
"$all": "water"
},
}
},
],
"total_doc": [{"$count": "count"}],
}
Expand Down

0 comments on commit a31b032

Please sign in to comment.