title: TextSearch engine in MongoDb
body: <p>I'm trying to create a search feature in my application using c# Driver for MongoDb.</p>
  
  <p>When user search for a list of words I want to display first the exact match (if it exists) followed by the most interesting posts.</p>
  
  <p>I've a text-index like this:</p>
  
  <pre><code>collection.CreateIndex(IndexKeys&lt;Post&gt;.Text(p =&gt; p.BodyPlainText));
  </code></pre>
  
  <p>I started this way:</p>
  
  <pre><code>var textSearchQueryExact = Query.Matches("BodyPlainText", searchString);
  var textSearchQueryFullText = Query.Text(searchString);
  var textSearchQuery = Query.Or(textSearchQueryFullText, textSearchQueryExact);
  </code></pre>
  
  <p>This generates the following query:</p>
  
  <pre><code>{  "$or" : [ { "$text" : { "$search" : "My example text" } }, { "BodyPlainText" : /My example text/ }] }
  </code></pre>
  
  <p>But it doesn't works! Zero results and, in MongoVUE, I recieve no explain. If I remove one of the two query filters it works, while with both doesn't.</p>
  
  <p>I also find this restriction in Mongo documentation:</p>
  
  <pre><code>"To use a $text query in an $or expression, all clauses in the $or array must be indexed."
  </code></pre>
  
  <p>but the propery is the same and it is indexed.</p>
  
  <p>What I miss?</p>
  
  <p>Is this the right way to achieve the result I want?</p>
  
  <p><strong>Update</strong></p>
  
  <p>Using only textSearch query with this syntax:</p>
  
  <pre><code>{ "$text" : { "$search" : "il ricorrente lamentava che mentre" } }
  </code></pre>
  
  <p>give me the wrong result due to stem and stop word elaboration (I think):</p>
  
  <p><img src="https://i.stack.imgur.com/b5yqp.jpg" alt="enter image description here"></p>