|
187 | 187 | "query_rules = []\n", |
188 | 188 | "\n", |
189 | 189 | "for curation in app_search.list_curations(engine_name=ENGINE_NAME).body[\"results\"]:\n", |
190 | | - " if (curation[\"promoted\"]):\n", |
191 | | - " query_rules.append(\n", |
192 | | - " {\n", |
193 | | - " \"rule_id\": curation[\"id\"] + \"-pinned\",\n", |
194 | | - " \"type\": \"pinned\",\n", |
195 | | - " \"criteria\": [\n", |
196 | | - " {\n", |
197 | | - " \"type\": \"exact\",\n", |
198 | | - " \"metadata\": \"user_query\",\n", |
199 | | - " \"values\": curation[\"queries\"],\n", |
200 | | - " }\n", |
201 | | - " ],\n", |
202 | | - " \"actions\": {\"ids\": curation[\"promoted\"]},\n", |
203 | | - " }\n", |
204 | | - " )\n", |
205 | | - " if(curation[\"hidden\"]):\n", |
206 | | - " query_rules.append(\n", |
207 | | - " {\n", |
208 | | - " \"rule_id\": curation[\"id\"] + \"-exclude\",\n", |
209 | | - " \"type\": \"exclude\",\n", |
210 | | - " \"criteria\": [\n", |
211 | | - " {\n", |
212 | | - " \"type\": \"exact\",\n", |
213 | | - " \"metadata\": \"user_query\",\n", |
214 | | - " \"values\": curation[\"queries\"],\n", |
215 | | - " }\n", |
216 | | - " ],\n", |
217 | | - " \"actions\": {\"ids\": curation[\"hidden\"]},\n", |
218 | | - " }\n", |
219 | | - " )\n", |
| 190 | + " if curation[\"promoted\"]:\n", |
| 191 | + " query_rules.append(\n", |
| 192 | + " {\n", |
| 193 | + " \"rule_id\": curation[\"id\"] + \"-pinned\",\n", |
| 194 | + " \"type\": \"pinned\",\n", |
| 195 | + " \"criteria\": [\n", |
| 196 | + " {\n", |
| 197 | + " \"type\": \"exact\",\n", |
| 198 | + " \"metadata\": \"user_query\",\n", |
| 199 | + " \"values\": curation[\"queries\"],\n", |
| 200 | + " }\n", |
| 201 | + " ],\n", |
| 202 | + " \"actions\": {\"ids\": curation[\"promoted\"]},\n", |
| 203 | + " }\n", |
| 204 | + " )\n", |
| 205 | + " if curation[\"hidden\"]:\n", |
| 206 | + " query_rules.append(\n", |
| 207 | + " {\n", |
| 208 | + " \"rule_id\": curation[\"id\"] + \"-exclude\",\n", |
| 209 | + " \"type\": \"exclude\",\n", |
| 210 | + " \"criteria\": [\n", |
| 211 | + " {\n", |
| 212 | + " \"type\": \"exact\",\n", |
| 213 | + " \"metadata\": \"user_query\",\n", |
| 214 | + " \"values\": curation[\"queries\"],\n", |
| 215 | + " }\n", |
| 216 | + " ],\n", |
| 217 | + " \"actions\": {\"ids\": curation[\"hidden\"]},\n", |
| 218 | + " }\n", |
| 219 | + " )\n", |
220 | 220 | "\n", |
221 | 221 | "elasticsearch.query_rules.put_ruleset(ruleset_id=ENGINE_NAME, rules=query_rules)" |
222 | 222 | ] |
|
234 | 234 | "metadata": {}, |
235 | 235 | "outputs": [], |
236 | 236 | "source": [ |
237 | | - "print(json.dumps(elasticsearch.query_rules.get_ruleset(ruleset_id=ENGINE_NAME).body, indent=2))" |
| 237 | + "print(\n", |
| 238 | + " json.dumps(\n", |
| 239 | + " elasticsearch.query_rules.get_ruleset(ruleset_id=ENGINE_NAME).body, indent=2\n", |
| 240 | + " )\n", |
| 241 | + ")" |
238 | 242 | ] |
239 | 243 | }, |
240 | 244 | { |
|
649 | 653 | "# add the semantic_text field to our mapping for each field defined\n", |
650 | 654 | "for field_name in SEMANTIC_TEXT_FIELDS:\n", |
651 | 655 | " semantic_field_name = field_name + \"_semantic\"\n", |
652 | | - " mapping[semantic_field_name] = {\n", |
653 | | - " \"type\": \"semantic_text\"\n", |
654 | | - " }\n", |
| 656 | + " mapping[semantic_field_name] = {\"type\": \"semantic_text\"}\n", |
655 | 657 | "\n", |
656 | 658 | "# and for our text fields, add a \"copy_to\" directive to copy the text to the semantic_text field\n", |
657 | 659 | "for field_name in SEMANTIC_TEXT_FIELDS:\n", |
|
838 | 840 | " \"order\": \"score\",\n", |
839 | 841 | " \"encoder\": \"html\",\n", |
840 | 842 | " \"require_field_match\": False,\n", |
841 | | - " \"fields\": { \"description\" : { \"pre_tags\" : [\"<em>\"], \"post_tags\" : [\"</em>\"] } },\n", |
| 843 | + " \"fields\": {\"description\": {\"pre_tags\": [\"<em>\"], \"post_tags\": [\"</em>\"]}},\n", |
842 | 844 | " },\n", |
843 | 845 | " \"size\": 10,\n", |
844 | 846 | " \"_source\": result_fields,\n", |
|
895 | 897 | "\n", |
896 | 898 | "for field_name in SEMANTIC_TEXT_FIELDS:\n", |
897 | 899 | " semantic_field_name = field_name + \"_semantic\"\n", |
898 | | - " semantic_text_queries.append(\n", |
899 | | - " {\n", |
900 | | - " \"match\": {\n", |
901 | | - " semantic_field_name: QUERY_STRING\n", |
902 | | - " }\n", |
903 | | - " }\n", |
904 | | - " )\n", |
| 900 | + " semantic_text_queries.append({\"match\": {semantic_field_name: QUERY_STRING}})\n", |
905 | 901 | "\n", |
906 | 902 | "semantic_query = {\"bool\": {\"should\": semantic_text_queries}}\n", |
907 | 903 | "print(f\"Elasticsearch query:\\n{json.dumps(semantic_query, indent=2)}\\n\")" |
|
0 commit comments