Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can perform substring search across multiple fields using following approach:</p> <p><strong>( 1 )</strong></p> <pre><code>public class IdeaByBodyOrTitle : AbstractIndexCreationTask&lt;Idea&gt; { public IdeaByBodyOrTitle() { Map = ideas =&gt; from idea in ideas select new { idea.Title, idea.Body }; } } </code></pre> <p>on <a href="http://ravendb.net/docs/client-api/querying/static-indexes/configuring-index-options" rel="nofollow noreferrer">this site</a> you can check, that:</p> <blockquote> <p>"By default, RavenDB uses a custom analyzer called LowerCaseKeywordAnalyzer for all content. (...) The default values for each field are FieldStorage.No in Stores and FieldIndexing.Default in Indexes."</p> </blockquote> <p>So by default, if you check the index terms inside the raven client, it looks following:</p> <pre><code>Title Body ------------------ ----------------- "the idea title 1" "the idea body 1" "the idea title 2" "the idea body 2" </code></pre> <p>Based on that, wildcard query can be constructed:</p> <pre><code>var wildquery = string.Format("*{0}*", QueryParser.Escape(query)); </code></pre> <p>which is then used with the <code>.In</code> and <code>.Where</code> constructions (using OR operator inside):</p> <pre><code>var ideas = session.Query&lt;User, UsersByDistinctiveMarks&gt;() .Where(x =&gt; x.Title.In(wildquery) || x.Body.In(wildquery)); </code></pre> <p><strong>( 2 )</strong></p> <p>Alternatively, you can use pure lucene query:</p> <pre><code>var ideas = session.Advanced.LuceneQuery&lt;Idea, IdeaByBodyOrTitle&gt;() .Where("(Title:" + wildquery + " OR Body:" + wildquery + ")"); </code></pre> <p><strong>( 3 )</strong></p> <p>You can also use <code>.Search</code> expression, but you have to construct your index differently if you want to search across multiple fields:</p> <pre><code>public class IdeaByBodyOrTitle : AbstractIndexCreationTask&lt;Idea, IdeaByBodyOrTitle.IdeaSearchResult&gt; { public class IdeaSearchResult { public string Query; public Idea Idea; } public IdeaByBodyOrTitle() { Map = ideas =&gt; from idea in ideas select new { Query = new object[] { idea.Title, idea.Body }, idea }; } } var result = session.Query&lt;IdeaByBodyOrTitle.IdeaSearchResult, IdeaByBodyOrTitle&gt;() .Search(x =&gt; x.Query, wildquery, escapeQueryOptions: EscapeQueryOptions.AllowAllWildcards, options: SearchOptions.And) .As&lt;Idea&gt;(); </code></pre> <p><strong>summary:</strong></p> <p>Also have in mind that <code>*term*</code> is rather expensive, especially the leading wildcard. In this <a href="http://daniellang.net/searching-on-string-properties-in-ravendb/" rel="nofollow noreferrer">post</a> you can find more info about it. There is said, that leading wildcard forces lucene to do a full scan on the index and thus can drastically slow down query-performance. Lucene internally stores its indexes (actually the terms of string-fields) sorted alphabetically and "reads" from left to right. That’s the reason why it is fast to do a search for a trailing wildcard and slow for a leading one. </p> <p>So alternatively <code>x.Title.StartsWith("something")</code> can be used, but this obviously do not search across all substrings. If you need fast search, you can change the Index option for the fields you want to search on to be Analyzed but it again will not search across all substrings.</p> <p>If there is a <strong><em>spacebar inside of the substring query</em></strong>, please check this <a href="https://stackoverflow.com/questions/12298468/search-by-substring-with-spacebar-in-ravendb">question</a> for possible solution. For making suggestions check <a href="http://architects.dzone.com/articles/how-do-suggestions-ravendb" rel="nofollow noreferrer">http://architects.dzone.com/articles/how-do-suggestions-ravendb</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload