Skip to content

Commit 5e7760f

Browse files
committed
Fixed the searching algorithm
1 parent a7f3d0f commit 5e7760f

File tree

1 file changed

+5
-28
lines changed

1 file changed

+5
-28
lines changed

CutCode/DataBase/DataBaseManager.cs

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -237,39 +237,16 @@ public bool FavModify(CodeBoxModel code)
237237
}
238238
return true;
239239
}
240-
241240
public async Task<ObservableCollection<CodeBoxModel>> SearchCode(string text, string from)
242241
{
243242
var currentCode = from == "Home" ? AllCodes : FavCodes;
244-
245-
var lst = new ObservableCollection<CodeBoxModel>();
246-
var lst2 = new ObservableCollection<CodeBoxModel>();
247-
foreach (var code in currentCode)
243+
var newCodesList = currentCode.Where(x => x.title.ToLower().Contains(text.ToLower())).ToList();
244+
var newCodes = new ObservableCollection<CodeBoxModel>();
245+
foreach(var code in newCodesList)
248246
{
249-
int f = 0;
250-
if (code.title.Length >= text.Length)
251-
{
252-
foreach (var i in code.title)
253-
{
254-
if (text.Contains(i))
255-
{
256-
text.Remove(text.IndexOf(i));
257-
f++;
258-
}
259-
}
260-
}
261-
else continue;
262-
263-
if (code.title == text) lst.Add(code);
264-
else if (code.title.Length < 3)
265-
{
266-
if (f >= 1) lst2.Add(code);
267-
}
268-
else if (f >= 3) lst2.Add(code);
247+
newCodes.Add(code);
269248
}
270-
271-
lst.Concat(lst2);
272-
return lst;
249+
return newCodes;
273250
}
274251
}
275252
}

0 commit comments

Comments
 (0)