MuditaOS icon indicating copy to clipboard operation
MuditaOS copied to clipboard

Contact application - UI improvement: search for substring matches

Open GravisZro opened this issue 4 years ago • 3 comments

🚀 Feature request

📝 Description

When searching contacts, the search only matches the beginning of fields. This means when searching for the first name "Big Jake" that you must search for "big" because "mike" will not match.

📝 Describe the solution you'd like

Search for match sub-strings.

📝 Describe alternatives you've considered

There could be an "Alias" field for contacts that would be the only substring search if it's a speed issue.

GravisZro avatar Apr 14 '22 16:04 GravisZro

Hi! it's not on the roadmap right now. Saying that - we will propose this be implemented internally. Internal ticket reference: https://appnroll.atlassian.net/browse/MOS-502

Saying that - please feel free to come up with implementation propositions.

pholat avatar May 23 '22 10:05 pholat

How I think it should work:

Initial search screen

  • search box is empty
  • all contact entries are listed (including hidden entries)
  • Entries should appear in the same order as they appear in the Contacts list
  • pressing down (navigation) will let you move through the list

Text entered in search box

  • Every time the search string changes then the list of entries is reduced to only matching entries
  • searched text should match any part of any field (phone numbers and email address included)
  • search should be case insensitive
  • search should be accent insensitive
  • matching text in displayed entries should be bolded (only the first match)
    • if the match isn't for a first or last name then display the matching field after the name in parenthesis with matching part bolded.
    • Example 1:
      • Search string: "ank"
      • Match: Anne Frank
      • Match: Hank Hill
      • Match: Jake (crank[email protected])
    • Example 2:
      • Search string: "854"
      • Match: Jim Jones (555-854-9238)
      • Match: Wayne (555-388-5482)
    • Example 3:
      • Search string: "a"
      • Match: Batman

Search algorithm example code

void remove_accents_and_make_lower_case(std::string&); // std::transform could do this

enum contact_fields
{
  first_name = 0,
  last_name,
  phone_number,
  second_phone_number,
  email,
};
typedef std::array<std::string, 5> contact_t;

std::list<contact_t> on_search_string_changed(std::string search_string)
{
  std::list<contact_t> matches;
  remove_accents_and_make_lower_case(search_string);
  for(const contact_t& entry : get_all_contact_entries())
  {
    for(std::string field : entry)
    {
      remove_accents_and_make_lower_case(field);
      auto result = std::search(std::begin(field), std::end(field), // search "haystack"...
                                std::begin(search_string), std::end(search_string)); // for "needle"
      if(result != std::end(field))
      {
        matches.push_back(entry)
        break;
      }
    }
  }
  return matches;
}

GravisZro avatar Jun 22 '22 13:06 GravisZro

@GravisZro the issue has been reported under MOS-414 ticket, thank you for your suggestion of the solution.

Lefucjusz avatar Jul 18 '22 10:07 Lefucjusz