import json
from typing import Dict, List

from django.core.management.base import BaseCommand

from mainapp.documents.index import elastic_index_file
from mainapp.functions.search import search_string_to_params, MainappSearch


class Command(BaseCommand):
    help = "Executes a search query, printing the query and the raw response"

    def add_arguments(self, parser):
        parser.add_argument("--analyze", action="store_true")
        parser.add_argument("search")

    def analyze(self, text: str) -> Dict[str, List[Dict]]:
        """ Shows what elasticsearch does with the tokens """
        return elastic_index_file.analyze(
            body={"analyzer": "text_analyzer", "text": text}
        )

    def handle(self, *args, **options):
        self.stdout.write("Searching for '{}'".format(options["search"]))
        params = search_string_to_params(options["search"])
        main_search = MainappSearch(params)
        search = main_search.build_search()
        self.stdout.write(json.dumps(search.to_dict()))
        executed = main_search.execute()
        del executed["_faceted_search"]
        self.stdout.write(json.dumps(executed.to_dict()))

@@ -8,38 +8,8 @@
 json
-%0Afrom typing import Dict, List
 %0A%0Afr
@@ -63,63 +63,8 @@
 nd%0A%0A
-from mainapp.documents.index import elastic_index_file%0A
 from
@@ -314,313 +314,15 @@
 nt(%22
---analyze%22, action=%22store_true%22)%0A        parser.add_argument(%22search%22)%0A%0A    def analyze(self, text: str) -%3E Dict%5Bstr, List%5BDict%5D%5D:%0A        %22%22%22 Shows what elasticsearch does with the tokens %22%22%22%0A        return elastic_index_file.analyze(%0A            body=%7B%22analyzer%22: %22text_analyzer%22, %22text%22: text%7D%0A        
+search%22
 )%0A%0A 

Remove old code from the search command