title: Exact Phrase search using Lucene?
body: <p>I am using SpanTerm Query for searching exact phrase in lucene. But it doesnt seem to work. Here is my code.</p>
  
  <p>Indexing</p>
  
  <pre><code>IndexWriter writer = new IndexWriter(dir, new StandardAnalyzer(Version.LUCENE_30), false,IndexWriter.MaxFieldLength.UNLIMITED);  
  doc.add(new Field("contents", sb.toString(), Field.Store.YES, Field.Index.ANALYZED,Field.TermVector.WITH_POSITIONS_OFFSETS));
  doc.add(new Field("imageid", imageDocument.getImageId(), Field.Store.YES, Field.Index.NOT_ANALYZED));
  doc.add(new Field("title", imageDocument.getTitle(), Field.Store.YES, Field.Index.ANALYZED));
  doc.add(new Field("country", imageDocument.getCountry(), Field.Store.YES, Field.Index.NOT_ANALYZED));
  write.addDocument(doc);
  </code></pre>
  
  <p>Searching</p>
  
  <pre><code>String sentence = searchParameters.get("searchExactWord");
  String[] words = sentence.split(" ");
  String queryNoWord = "";
  int i = 0;
  SpanTermQuery [] clause = new SpanTermQuery[words.length];
  for (String word : words)
  {
      clause[i] = new SpanTermQuery(new Term("contents",word));
      i++;
  }
  SpanNearQuery query = new SpanNearQuery(clause, 0, true);
  booleanQuery.add(query, BooleanClause.Occur.MUST);
  </code></pre>
  
  <p>Please guide me if I am doing it wrong???</p>
  
  <p>Prateek</p>