Skip to content

Commit

Permalink
Code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenldl committed Sep 18, 2023
1 parent b0b4205 commit de012ee
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

- Made substring matching bidirectional

- Fixed and improved search result ranking
- Tuned search result ranking

## 1.4.0

Expand Down
30 changes: 20 additions & 10 deletions lib/search_result.ml
Original file line number Diff line number Diff line change
Expand Up @@ -210,27 +210,37 @@ let score (t : t) : float =
let total_char_count =
stats.total_search_char_count +. stats.total_found_char_count
in
let exact_match_weight =
(stats.exact_match_found_char_count *. 2.0) /. total_char_count
in
let ci_exact_match_weight =
(stats.ci_exact_match_found_char_count *. 2.0) /. total_char_count
in
let sub_match_weight =
(stats.sub_match_overlap_char_count *. 2.0) /. total_char_count
in
let ci_sub_match_weight =
(stats.ci_sub_match_overlap_char_count *. 2.0) /. total_char_count
in
let fuzzy_match_weight =
(stats.fuzzy_match_found_char_count *. 2.0) /. total_char_count
in
(1.0 +. (0.10 *. (unique_match_count /. search_phrase_length)))
*.
(1.0 -. (out_of_order_match_count /. search_phrase_length))
*.
(if quite_close_to_zero average_distance then 1.0 else 1.0 /. average_distance)
*.
(
(exact_match_score *.
(stats.exact_match_found_char_count /. total_char_count))
(exact_match_weight *. exact_match_score)
+.
(ci_exact_match_score *.
(stats.ci_exact_match_found_char_count /. total_char_count))
(ci_exact_match_weight *. ci_exact_match_score)
+.
(sub_match_score
*. (stats.sub_match_overlap_char_count /. total_char_count))
(sub_match_weight *. sub_match_score)
+.
(ci_sub_match_score
*. (stats.ci_sub_match_overlap_char_count /. total_char_count))
(ci_sub_match_weight *. ci_sub_match_score)
+.
(fuzzy_match_score
*. (stats.fuzzy_match_found_char_count /. total_char_count))
(fuzzy_match_weight *. fuzzy_match_score)
)

let compare t1 t2 =
Expand Down

0 comments on commit de012ee

Please sign in to comment.