title: Index multiple authors per book using Lucene.NET
body: <p>I'm using Lucene.NET to build a search index of 10 million+ books. I am using this to index a book:</p>
  
  <pre><code>Document doc = new Document();
  
  doc.Add(new Field("id", bookID, Field.Store.YES, Field.Index.NO));
  
  doc.Add(new Field("publisher", publisherName, Field.Store.YES, Field.Index.NOT_ANALYZED));
  
  doc.Add(new Field("title", bookTitle, Field.Store.YES, Field.Index.ANALYZED));
  </code></pre>
  
  <p><strong>Search by Publisher:</strong></p>
  
  <p>Since I've indexed book publishers with <code>Index.NOT_ANALYZED</code>, I can use the high-performance <a href="https://stackoverflow.com/a/24075955/1294758">TermsFilter</a> to do the equivalent of: </p>
  
  <blockquote>
    <p>SELECT * FROM books WHERE publisher="O'Reilly Media"</p>
  </blockquote>
  
  <p><strong>Search by Title:</strong></p>
  
  <p>And of course since I've indexed the book titles using the <code>Index.ANALYZED</code> option, I can use the standard QueryParser to do the equivalent of:</p>
  
  <blockquote>
    <p>SELECT * FROM books WHERE title LIKE "%skating%"</p>
  </blockquote>
  
  <p><strong>Search by Author:</strong></p>
  
  <p>However now I need to search by author. I need something like:</p>
  
  <blockquote>
    <p>SELECT * FROM books WHERE title LIKE "%skating%" AND authors CONTAIN "Jack Black"</p>
  </blockquote>
  
  <p>So how do I go about doing that? I have both author names and author IDs stored per book. How can I index that into the Lucene Document and then quickly search for all books by author? I don't want to use SQL since I need to combine the search keywords with the author filter, so Lucene must do the author filtering for me. </p>
  
  <p>The most obvious solution is:</p>
  
  <pre><code>doc.Add(new Field("authors", "Jack Black; Joan White", Field.Store.YES, Field.Index.ANALYZED));
  </code></pre>
  
  <p>But this would incorrectly return books where the name of one author is similar/within the name of another author, eg:</p>
  
  <ul>
  <li>Book 1 : Authors : Jack D Black, Bob A Smith</li>
  <li>Book 2 : Authors : D Black</li>
  </ul>
  
  <p>So at this point searching for "D Black" would incorrectly return Book 1 and Book 2, instead of just Book 2. I need to therefore index the whole author name or ID (using <code>Index.NOT_ANALYZED</code>), but I need multiple of such fields per book. Is this possible?</p>
  
  <pre><code>// can I add the same field multiple times into a document?
  doc.Add(new Field("author", "Jack D Black", Field.Store.YES, Field.Index.NOT_ANALYZED));
  doc.Add(new Field("author", "Bob A Smith", Field.Store.YES, Field.Index.NOT_ANALYZED));
  </code></pre>
  
  <p>Or I could add the author IDs, such that the analyzer takes each number as an independent word:</p>
  
  <pre><code>doc.Add(new Field("authors", "125;1885;23", Field.Store.YES, Field.Index.ANALYZED));
  </code></pre>
  
  <p>And then use a regular Lucene search to find all books with the author "125"... Would this work or would this also list books with the author "1254"?</p>