title: LINQ to Entities Searching text properties for multiple keywords
body: <p>For a website I'm doing we're using LINQ to Entities. I have been charged with adding search functionality  to the site. I'm trying to figure out the most elegant way to search for multiple keywords (user entered) on a single field in the database. Allow me to give an example.</p>
  
  <p>Table columns:</p>
  
  <pre><code>Name, Description
  </code></pre>
  
  <p>Example row:</p>
  
  <pre><code>"Cookie monster", "Fluffy, likes cookies and blue"
  </code></pre>
  
  <p>User search (delimiter doesn't matter):</p>
  
  <pre><code>"blue fluffy" 
  </code></pre>
  
  <p>Currently I am using the following:</p>
  
  <pre><code>    public List&lt;SesameCharacters&gt; SearchByKeywords(string keywords)
      {
          List&lt;SesameCharacters&gt; output = new List&lt;SesameCharacters&gt;();
          string[] k = keywords.ToLower().Split(' ');
          using (SesameStreet_Entities entities = new SesameStreet_Entities())
          {
              IQueryable&lt;SesameCharacters&gt; filter = entities.SesameCharacters;
  
              foreach (string keyword in k)
                  filter = ForceFilter(filter, keyword);
  
              output = filter.ToList();
          }
          return output;
      }
  
      private IQueryable&lt;SesameCharacters&gt; ForceFilter(IQueryable&lt;SesameCharacters&gt; filter, string keyword)
      {
          return filter.Where(p =&gt; p.Description.ToLower().Contains(keyword));
      }
  </code></pre>
  
  <p>This currently works as expected but I imagine it is not the best solution to the problem.  Am I missing something glaringly obvious?</p>
  
  <p><em>NOTE:</em> This is <code>AND</code> matching.</p>