title: Phrase matching with Sitecore ContentSearch API
body: <p>I am using Sitecore 7.2 with a custom Lucene index and Linq.  I need to give additional (maximum) weight to exact matches.</p>
  
  <p>Example:
  A user searches for "somewhere over the rainbow"</p>
  
  <p>Results should include items which contain the word "rainbow", but items containing the exact and entire term "somewhere over the rainbow" should be given maximum weight.  They will displayed to users as the top results. i.e. An item containing the entire phrase should weigh more heavily than an item which contains the word "rainbow" 100 times.</p>
  
  <p>I may need to handle ranking logic outside of the ContentSearch API by collecting "phrase matches" separately from "wildcard matches", and that's fine.</p>
  
  <p>Here's my existing code, truncated for brevity.  The code works, but exact phrase matches are not treated as I described.</p>
  
  <pre><code>using (var context = ContentSearchManager.GetIndex("sitesearch-index").CreateSearchContext())
  {
      var pred = PredicateBuilder.False&lt;SearchResultItem&gt;();
      pred = pred
          .Or(i =&gt; i.Name.Contains(term)).Boost(1)
          .Or(i =&gt; i["Field 1"].Contains(term)).Boost(3)
          .Or(i =&gt; i["Field 2"].Contains(term)).Boost(1);
  
      IQueryable&lt;SearchResultItem&gt; query = context.GetQueryable&lt;SearchResultItem&gt;().Where(pred);
      var hits = query.GetResults().Hits;
      ...
  }
  </code></pre>
  
  <p>How can I perform exact phrase matching and is it possible with the Sitecore.ContentSearch.Linq API?</p>