mirror of
https://github.com/bitwarden/android.git
synced 2024-12-25 18:38:27 +03:00
PS-592 Mobile - Name field is not prioritised in search results (#1907)
- Search method now gives priority to matches in the Name property Co-authored-by: André Bispo <abispo@bitwarden.com>
This commit is contained in:
parent
22c746543a
commit
a259560d29
1 changed files with 30 additions and 18 deletions
|
@ -74,28 +74,34 @@ namespace Bit.Core.Services
|
||||||
CancellationToken ct = default, bool deleted = false)
|
CancellationToken ct = default, bool deleted = false)
|
||||||
{
|
{
|
||||||
ct.ThrowIfCancellationRequested();
|
ct.ThrowIfCancellationRequested();
|
||||||
|
var matchedCiphers = new List<CipherView>();
|
||||||
|
var lowPriorityMatchedCiphers = new List<CipherView>();
|
||||||
query = query.Trim().ToLower();
|
query = query.Trim().ToLower();
|
||||||
return ciphers.Where(c =>
|
|
||||||
|
foreach (var c in ciphers)
|
||||||
{
|
{
|
||||||
ct.ThrowIfCancellationRequested();
|
ct.ThrowIfCancellationRequested();
|
||||||
if (c.Name?.ToLower().Contains(query) ?? false)
|
if (c.Name?.ToLower().Contains(query) ?? false)
|
||||||
{
|
{
|
||||||
return true;
|
matchedCiphers.Add(c);
|
||||||
}
|
}
|
||||||
if (query.Length >= 8 && c.Id.StartsWith(query))
|
else if (query.Length >= 8 && c.Id.StartsWith(query))
|
||||||
{
|
{
|
||||||
return true;
|
lowPriorityMatchedCiphers.Add(c);
|
||||||
}
|
}
|
||||||
if (c.SubTitle?.ToLower().Contains(query) ?? false)
|
else if (c.SubTitle?.ToLower().Contains(query) ?? false)
|
||||||
{
|
{
|
||||||
return true;
|
lowPriorityMatchedCiphers.Add(c);
|
||||||
}
|
}
|
||||||
if (c.Login?.Uri?.ToLower()?.Contains(query) ?? false)
|
else if (c.Login?.Uri?.ToLower()?.Contains(query) ?? false)
|
||||||
{
|
{
|
||||||
return true;
|
lowPriorityMatchedCiphers.Add(c);
|
||||||
}
|
}
|
||||||
return false;
|
}
|
||||||
}).ToList();
|
|
||||||
|
ct.ThrowIfCancellationRequested();
|
||||||
|
matchedCiphers.AddRange(lowPriorityMatchedCiphers);
|
||||||
|
return matchedCiphers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<List<SendView>> SearchSendsAsync(string query, Func<SendView, bool> filter = null,
|
public async Task<List<SendView>> SearchSendsAsync(string query, Func<SendView, bool> filter = null,
|
||||||
|
@ -133,25 +139,31 @@ namespace Bit.Core.Services
|
||||||
public List<SendView> SearchSendsBasic(List<SendView> sends, string query, CancellationToken ct = default,
|
public List<SendView> SearchSendsBasic(List<SendView> sends, string query, CancellationToken ct = default,
|
||||||
bool deleted = false)
|
bool deleted = false)
|
||||||
{
|
{
|
||||||
|
var matchedSends = new List<SendView>();
|
||||||
|
var lowPriorityMatchSends = new List<SendView>();
|
||||||
ct.ThrowIfCancellationRequested();
|
ct.ThrowIfCancellationRequested();
|
||||||
query = query.Trim().ToLower();
|
query = query.Trim().ToLower();
|
||||||
return sends.Where(s =>
|
|
||||||
|
foreach (var s in sends)
|
||||||
{
|
{
|
||||||
ct.ThrowIfCancellationRequested();
|
ct.ThrowIfCancellationRequested();
|
||||||
if (s.Name?.ToLower().Contains(query) ?? false)
|
if (s.Name?.ToLower().Contains(query) ?? false)
|
||||||
{
|
{
|
||||||
return true;
|
matchedSends.Add(s);
|
||||||
}
|
}
|
||||||
if (s.Text?.Text?.ToLower().Contains(query) ?? false)
|
else if (s.Text?.Text?.ToLower().Contains(query) ?? false)
|
||||||
{
|
{
|
||||||
return true;
|
lowPriorityMatchSends.Add(s);
|
||||||
}
|
}
|
||||||
if (s.File?.FileName?.ToLower()?.Contains(query) ?? false)
|
else if (s.File?.FileName?.ToLower()?.Contains(query) ?? false)
|
||||||
{
|
{
|
||||||
return true;
|
lowPriorityMatchSends.Add(s);
|
||||||
}
|
}
|
||||||
return false;
|
}
|
||||||
}).ToList();
|
|
||||||
|
ct.ThrowIfCancellationRequested();
|
||||||
|
matchedSends.AddRange(lowPriorityMatchSends);
|
||||||
|
return matchedSends;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue