-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
172b662
commit e2d44f4
Showing
4 changed files
with
121 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,10 @@ | ||
# ESEF (ElasticSearch Explain Formatter) | ||
|
||
## Build project locally | ||
```shell script | ||
# Build for Mac | ||
#rm -r ESEF-0.1-alpha.app | ||
#rm ESEF | ||
|
||
fyne package -os darwin # optional: -icon icon.png | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
) | ||
|
||
type ExplainAPIDocument struct { | ||
Index string `json:"_index"` | ||
Type string `json:"_type"` | ||
DocumentId string `json:"_id"` | ||
Matched bool `json:"matched"` | ||
Explanation ExplainNode `json:"explanation"` | ||
} | ||
|
||
type ExplainNode struct { | ||
Value float64 `json:"value"` | ||
Description string `json:"description"` | ||
Details []ExplainNode `json:"details"` | ||
} | ||
|
||
func ExtractDataFromExplainAPI(explainAPIOutput string) string { | ||
doc := extractDocumentFromJson(explainAPIOutput) | ||
|
||
return FormatExplainApiDocument(doc) | ||
} | ||
|
||
func extractDocumentFromJson(inputJson string) ExplainAPIDocument { | ||
var explainAPIDocument ExplainAPIDocument | ||
byteData := []byte(inputJson) | ||
err := json.Unmarshal(byteData, &explainAPIDocument) | ||
|
||
if err != nil { | ||
return ExplainAPIDocument{} | ||
} | ||
|
||
return explainAPIDocument | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
const TAB = " " | ||
|
||
func FormatExplainApiDocument(doc ExplainAPIDocument) string { | ||
explanation := formatExplainNodes(0, doc.Explanation) | ||
|
||
return fmt.Sprintf("index: %s\ndocumentId: %s\nmatched: %t\nexplanation:\n%s", | ||
doc.Index, doc.DocumentId, doc.Matched, explanation) | ||
} | ||
|
||
func formatExplainNodes(treeLevel int, nodes ...ExplainNode) string { | ||
indentation := strings.Repeat(TAB, treeLevel) | ||
treeLevel++ | ||
var result string | ||
|
||
for _, node := range nodes { | ||
result += fmt.Sprintf(indentation+"%f (%s)\n", node.Value, node.Description) | ||
|
||
if len(node.Details) > 0 { | ||
result += formatExplainNodes(treeLevel, node.Details...) | ||
} | ||
} | ||
|
||
return result | ||
} |