Ok guys, that doesn't make sense ...
I have this method:
string[] searchTerms = ui_txtSearch.Text.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
List<Company> results = Company.List();
for (int i = 0; i < searchTerms.Length; i++)
{
results = (from comp in results
where comp.Name.Contains(searchTerms[i]
select comp).ToList();
}
Now the general idea is that from the list of companies I want everything that contains all the keywords in the search expression provided in my text box on ui.
My problem is that it is “Contains” (highlighted above in **) ... if I say “Company” in the line “Name” and I look for “Co.”, I expect this as a result, because it is the name will be but it is not ...
any ideas?
EDIT:
Ok, I found that the problem was case sensitive, so I reorganized the code:
string[] searchTerms = ui_txtSearch.Text.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
List<Company> results = Company.List();
for (int i = 0; i < searchTerms.Length; i++)
{
results = (
from comp in results
where comp.Name.ToLower().IndexOf(searchTerms[i].ToLower()) > -1
select comp
).ToList();
}
To answer some of your feedback below:
- "Test Company 1", , "test" "company" "1" , , "".
, ???... ?
...
, , ... , , , ?
:)
2:
, , ( ) :
string[] searchTerms = ui_txtSearch.Text.ToLower().Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
List<Company> results;
results = (
from comp in Company.List()
where searchTerms.All(s => comp.Name.ToLower().IndexOf(s) > -1)
select comp
).ToList();
:)