From eab0f0c6b0c066fb3ec606ec3e279eada45d69bd Mon Sep 17 00:00:00 2001 From: mat Date: Sat, 13 Apr 2024 01:09:19 -0500 Subject: [PATCH] don't show numbat result when it's identical to the query --- src/engines/answer/numbat.rs | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/engines/answer/numbat.rs b/src/engines/answer/numbat.rs index d71b8de..e7cffc4 100644 --- a/src/engines/answer/numbat.rs +++ b/src/engines/answer/numbat.rs @@ -78,7 +78,7 @@ fn is_potential_request(query: &str) -> bool { true } -fn interpret(query: &str) -> Option<(Statement, InterpreterResult)> { +fn interpret(query: &str) -> Option<(Statement, Markup)> { if !is_potential_request(query) { return None; } @@ -98,16 +98,19 @@ fn interpret(query: &str) -> Option<(Statement, InterpreterResult)> { } }; - Some((statements.into_iter().last()?, res)) -} - -fn evaluate_for_autocomplete(query: &str) -> Option { - let (_statements, res) = interpret(query)?; - let res_markup = match res { InterpreterResult::Value(val) => val.pretty_print(), InterpreterResult::Continue => return None, }; + if res_markup.to_string().trim() == query { + return None; + } + + Some((statements.into_iter().last()?, res_markup)) +} + +fn evaluate_for_autocomplete(query: &str) -> Option { + let (_statements, res_markup) = interpret(query)?; Some(res_markup.to_string().trim().to_string()) } @@ -118,12 +121,7 @@ pub struct NumbatResponse { } fn evaluate(query: &str) -> Option { - let (statement, res) = interpret(query)?; - - let res_markup = match res { - InterpreterResult::Value(val) => val.pretty_print(), - InterpreterResult::Continue => return None, - }; + let (statement, res_markup) = interpret(query)?; let statement_markup = statement.pretty_print(); let query_html = markup_to_html(statement_markup);