This is a migrated thread and some comments may be shown as answers.

build free text search linq query

1 Answer 172 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Tys
Top achievements
Rank 1
Tys asked on 15 Apr 2012, 02:48 AM

I have a textbox that takes free text as input for a search and I have a LINQ query that I want to extend with this type of search.

The input could be something like "big blue car" and that should result in a query that searches for titles that contain all these words.

There is also an option to switch to "any word" instead of "all words".

What is the best/easiest way to add this to my LINQ query?

The query now looks like

from b in books
where b
.InStore == true && b.Price > 10 && title.Contains()...at this point i want to add the text search.
select b

And i think i have to do something like this:

var searchTerms = input.Split(' ');
from b in books
where b
.InStore == true && b.Price > 10
&& (searchTerms.All(x => b.Title.Contains(x)))
select b

But i keep getting this error : Must specify parameter on right side of operation.

1 Answer, 1 is accepted

Sort by
0
Thomas
Telerik team
answered on 17 Apr 2012, 02:59 PM
Hello Tys,

please see this blog post that gives you some options and code that can be tweaked for your case.

Regards,
Thomas
the Telerik team
Share your passion about the Telerik Open Access by voting for Telerik's powerful ORM tool here >>
Tags
General Discussions
Asked by
Tys
Top achievements
Rank 1
Answers by
Thomas
Telerik team
Share this question
or