title: Lucene.net - How do I extract small snippets of texts from each match?
body: <p><a href="http://quranx.com/Search?q=oh+people+of+heaven&amp;context=Quran" rel="nofollow">http://quranx.com/Search?q=oh+people+of+heaven&amp;context=Quran</a></p>
  
  <p>Could anyone tell me how I would change the following code to show snippets of text for each match result?  I've tried reading through examples etc but can only find relevant information for a newer version of Lucene for Java.  Lucene seems to be something of a black box of magic to me.</p>
  
  <pre class="lang-c# prettyprint-override"><code>public static IEnumerable&lt;SearchResult&gt; Search(
      string queryString, 
      out int totalResults,
      int maxResults = 100)
  {
      totalResults = 0;
      if (string.IsNullOrEmpty(queryString))
          return new List&lt;SearchResult&gt;();
  
      var query = new MultiFieldQueryParser(
          Lucene.Net.Util.Version.LUCENE_30,
          new string[] { "Body", "SecondaryReferences" },
          Analyzer
      ).Parse(queryString);
  
      var indexReader = DirectoryReader.Open(
          directory: Index,
          readOnly: true);
      var indexSearcher = new IndexSearcher(indexReader);
      var resultsCollector = TopScoreDocCollector.Create(
          numHits: maxResults,
          docsScoredInOrder: true
      );
      indexSearcher.Search(
          query: query,
          results: resultsCollector
      );
      totalResults = resultsCollector.TotalHits;
      var result = new List&lt;SearchResult&gt;();
      foreach (var scoreDoc in resultsCollector.TopDocs().ScoreDocs)
      {
          var snippets = new List&lt;SearchResultSnippet&gt;();
          var doc = indexSearcher.Doc(scoreDoc.Doc);
          var searchResult = new SearchResult(
              type: doc.Get("Type"),
              id: doc.Get("ID"),
              snippets: snippets
          );
          result.Add(searchResult);
      }
      return result;
  }
  </code></pre>