title: Substring search in RavenDB
body: <p>I have a set of objects of type <code>Idea</code></p>
  
  <pre><code>public class Idea
  {
      public string Title { get; set; }
      public string Body { get; set; }
  }
  </code></pre>
  
  <p>I want to search this objects by substring. For example when I have object of title "<em>idea</em>", I want it to be found when I enter any substring of "<em>idea</em>": <em>i, id, ide, idea, d, de, dea, e, ea, a</em>.</p>
  
  <p>I'm using RavenDB for storing data. The search query looks like that:</p>
  
  <pre><code>var ideas = session
                .Query&lt;IdeaByBodyOrTitle.IdeaSearchResult, IdeaByBodyOrTitle&gt;()
                .Where(x =&gt; x.Query.Contains(query))
                .As&lt;Idea&gt;()
                .ToList();
  </code></pre>
  
  <p>while the index is following:</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.SplitSubstrings().Concat(idea.Body.SplitSubstrings()).Distinct().ToArray() },
                                 idea
                             };
          Indexes.Add(x =&gt; x.Query, FieldIndexing.Analyzed);
      }
  }
  </code></pre>
  
  <p><code>SplitSubstrings()</code> is an extension method which returns all distinct substrings of given string:</p>
  
  <pre><code>static class StringExtensions
  {
      public static string[] SplitSubstrings(this string s)
      {
          s = s ?? string.Empty;
          List&lt;string&gt; substrings = new List&lt;string&gt;();
          for (int i = 0; i &lt; s.Length; i++)
          {                
              for (int j = 1; j &lt;= s.Length - i; j++)
              {
                  substrings.Add(s.Substring(i, j));
              }
          }            
          return substrings.Select(x =&gt; x.Trim()).Where(x =&gt; !string.IsNullOrEmpty(x)).Distinct().ToArray();
      }
  }
  </code></pre>
  
  <p>This is not working. Particularly because RavenDB is not recognizing <code>SplitSubstrings()</code> method, because it is in my custom assembly. How to make this work, basically how to force RavenDB to recognize this method ? Besides that, is my approach appropriate for this kind of searching (searching by substring) ?</p>
  
  <p>EDIT</p>
  
  <p>Basically, I want to build auto-complete feature on this search, so it need to be fast.</p>
  
  <p><img src="https://i.stack.imgur.com/CcFLG.jpg" alt="enter image description here"></p>
  
  <p>Btw: I'm using RavenDB - Build #960</p>