Ejemplo n.º 1
0
    def formulaFromExplanation(self, query, doc_id):
        """
            Runs .explain() for one query/doc pair, generates and returns a \
            StoredFormula instance from it

            :param query: StructuredQuery dict, with a "dsl_query" key
            :param doc_id: id of document to run .explain() for
            :returns:
        """
        explanation=None
        retries=0
        while retries < 2:
            try:
                explanation=self.es.explain(
                    index=self.index_name,
                    doc_type=ES_TYPE_DOC,
                    body={"query":query["dsl_query"]},
                    id=doc_id,
                    request_timeout=QUERY_TIMEOUT,
                    )
                break
            except Exception as e:
                logging.exception("Exception, retrying...")
                retries+=1

        formula=StoredFormula()
        if explanation:
            formula.fromElasticExplanation(explanation, self.save_terms)
        return formula
Ejemplo n.º 2
0
    def formulaFromExplanation(self, query, doc_id):
        """
            Runs .explain() for one query/doc pair, generates and returns a \
            StoredFormula instance from it

            :param query: Elastic DSL Query
            :param doc_id: id of document to run .explain() for
            :returns:
        """
        explanation=self.searcher.explain(query,doc_id)

        formula=StoredFormula()
        formula.fromLuceneExplanation(explanation)
        return formula