title: What is the difference between Field and StringField in Lucene?
body: <p>I am searching for exactly matched document titles in lucene index. To accomplish that, I have the following two alternative approach to create fields for documents which will be indexed.</p>
  
  <p>Approach 1:</p>
  
  <pre><code>FieldType _contentFieldType = new FieldType();
  _contentFieldType.setIndexed(true);
  _contentFieldType.setStored(true);
  
  Document doc = new Document();
  doc.add(new Field("content", getContent(), _contentFieldType));
  writer.addDocument(doc);
  </code></pre>
  
  <p>Approach 2:</p>
  
  <pre><code>Document doc = new Document();
  doc.add(new StringField("content", getContent(), Store.YES));
  writer.addDocument(doc);
  </code></pre>
  
  <p>Then i am creating query using <code>TermQuery</code> and searching in the lucene index but i don't get any result if i use the first approach. Second appoach is working fine for me.</p>
  
  <pre><code>Query query = new TermQuery(new Term(searchQuery.fields().get(0), searchQuery.queryText()));
  indexSearcher.search(query, Math.max(1, collector.getTotalHits()));
  </code></pre>
  
  <p>Example of document titles: Document titles are actually topic of the document, a hierarchical path of topics.</p>
  
  <pre><code>Top/Arts/Animation/Audio
  Top/Arts/Animation/Collectibles
  Top/Arts/Animation/Stop-Motion
  Top/Arts/Animation/Festivals
  Top/Arts/Animation/News_and_Media
  Top/Arts/Animation/Chats_and_Forums
  Top/Arts/Animation/Training
  Top/Arts/Animation/Voice_Actors
  Top/Arts/Animation/Artists
  </code></pre>
  
  <p>Say, i want to search for <code>Top/Arts/Animation/Training</code>. I need exact string matching, so i have used <code>TermQuery</code>.</p>
  
  <p>I read documentation and learned about Field and StringField. So, StringField is indexed but not analyzed if <code>Store.Yes</code> is passed as parameter. But my question is, since i am using both <code>setIndexed(true)</code> and <code>setStored(true)</code> for <code>Field</code> in approach 1, why i am not getting similar result from approach 1? Is it because some additional things are executed if i use Field or is it because of the use of TermQuery? What is the main thing that is making this two approaches different? Please help me to understand the difference in them.</p>
  
  <p>Thanks!</p>