London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!

Search query to find a word thats could be in inside multiple properties

Vote:
0

I have three properties 

  • First name
  • Last name
  • Username

User can search for a word that can be in all three properties. I have had this two queries to achieve the desired result

searchTermFilters = searchTermFilters
    .For(term)
    .InFields(x => x.Firstname, x => x.Surname, x => x.Username);
searchTermFilters = searchTermFilters
                .OrFilter(x => x.Firstname.AnyWordBeginsWith(term))
                .OrFilter(x => x.Surname.AnyWordBeginsWith(term))
                .OrFilter(x => x.Username.AnyWordBeginsWith(term));

The issue is that for both of them it matches exactly. I want something like .Contains in Linq. Any insights?

#194873
Jul 05, 2018 11:12
Vote:
0

Hi Mohsin,

You could try below

   query = query.For(term, q =>
                    {
                        q.Query = $"*{term}*";
                    }).InField(s => s.Name);



#195088
Jul 13, 2018 3:47
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.