title: Spring data mongodb: Text search for 'phrase OR words in phrase'
body: <p>I need to search documents inside a collection named <i>blog</i> which has text indexes defined for title, tags, summary and body:</p>
  
  <pre><code>@Document(collection="blog")
  public class Blog {
      @Id
      private String id;
      @TextIndexed(weight = 10)
      private String title;
      @TextIndexed(weight = 9)
      private String tags;
      @TextIndexed(weight = 8)
      private String summary;
      @TextIndexed(weight = 7)
      private String body;
      @TextScore
      private Float score;
  
      //getters and setters
  }
  </code></pre>
  
  <p>Now, I have a requirement to perform text search on <i>blog</i> collection according to the following criteria:</p>
  
  <ol>
  <li>Check the user input whether it contains more than one word.</li>
  <li>If searchKey is single word perform text search and return sorted response according the weight.</li>
  <li>If searchKey contains more than one word the perform search for full PHRASE OR any word within the PHRASE.</li>
  </ol>
  
  <p>For the 2nd case <i>TextCriteria</i> definition looks like:</p>
  
  <pre><code>TextCriteria criteria = TextCriteria.forDefaultLanguage().matching("SingleWord");
  </code></pre>
  
  <p>For the 3rd case, how to write criteria definition for the combination in single query:</p>
  
  <pre><code>query 1: db.articles.find( { $text: { $search: "\"coffee cake\"" } } ) //phrase search
  query 2: db.articles.find( { $text: { $search: "coffee cake" } } ) //word search
  </code></pre>
  
  <p>Can I perform search with </p>
  
  <pre><code>query 1 OR query 2 with sorted result based on score.
  </code></pre>
  
  <p>Score should be higher for results matching for full phrase.</p>