Skip to content

Commit

Permalink
Merge pull request #169 from DripEmail/167-exact-sub-string-matches-s…
Browse files Browse the repository at this point in the history
…hould-show-up-higher-when-filteringsearching

Tweaking the filtering logic so sub string matches get better scores.
  • Loading branch information
jachin authored May 20, 2022
2 parents 072d31a + bafec2b commit d05e425
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
29 changes: 27 additions & 2 deletions src/OptionSearcher.elm
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,37 @@ updateSearchResultInOption searchString option =
, descriptionHandicap searchResult.descriptionMatch.score
, groupHandicap searchResult.groupMatch.score
]

cappedBestScore =
-- Just putting our thumb on the scale here for the sake of substring matches
if bestScore > 100 then
if String.contains (SearchString.toString searchString |> String.toLower) (option |> Option.getOptionLabel |> OptionLabel.optionLabelToSearchString |> String.toLower) then
if String.length (SearchString.toString searchString) < 3 then
bestScore

else if String.length (SearchString.toString searchString) < 4 then
20

else if String.length (SearchString.toString searchString) < 5 then
15

else if String.length (SearchString.toString searchString) < 6 then
10

else
bestScore

else
bestScore

else
bestScore
in
Option.setOptionSearchFilter
(Just
(OptionSearchFilter.new
totalScore
bestScore
cappedBestScore
labelTokens
descriptionTokens
groupTokens
Expand All @@ -123,7 +148,7 @@ updateOrAddCustomOption searchString selectionMode options =
TransformAndValidate.ValidationFailed _ _ _ ->
( False, searchString )

TransformAndValidate.ValidationPending string _ ->
TransformAndValidate.ValidationPending _ _ ->
( False, searchString )

NoCustomOptions ->
Expand Down
17 changes: 16 additions & 1 deletion tests/FilteringOptions/OptionSearcher.elm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Option
import OptionSearchFilter
import OptionSearcher exposing (doesSearchStringFindNothing)
import OptionSorting exposing (sortOptionsBySearchFilterTotalScore)
import OptionsUtilities
import OutputStyle exposing (MaxDropdownItems(..), SearchStringMinimumLength(..))
import PositiveInt
import SearchString
Expand Down Expand Up @@ -166,9 +167,23 @@ suite =
|> Maybe.map List.length
)
(Just 1)
, test "if the search string is 'win' and there's an option with 'winners' and another with 'webinars' in the label the winners should win" <|
\_ ->
Expect.equal
(OptionSearcher.updateOptionsWithSearchStringAndCustomOption
(SelectionMode.setSearchStringMinimumLength NoMinimumToSearchStringLength selectionConfig)
(SearchString.new "win")
[ Option.newOption "LevelUp2021_SwagWinnersFinal" Nothing
, Option.newOption "Q2 2021 Webinar Registrants" Nothing
]
|> OptionsUtilities.sortOptionsByBestScore
|> List.head
|> Maybe.map Option.getOptionValueAsString
)
(Just "LevelUp2021_SwagWinnersFinal")
]
, describe "encoders and decoders"
[ test "round trip for the serach result encoders and decoders" <|
[ test "round trip for the search result encoders and decoders" <|
\_ ->
Expect.ok
(OptionSearcher.updateOptionsWithSearchStringAndCustomOption
Expand Down

0 comments on commit d05e425

Please sign in to comment.