Thursday, January 1, 2015

PhraseQuery in lucene: PhraseQuery not searching on capitalized text such as ABC

Indexed text: I am learning ABC.
  •  Suppose You indexed above text as TextField and using StandardAnalyzer for indexwriter
  • doc.add(new TextField("fieldName", "I am learning ABC", Field.Strore.YES));
  • You are trying to search with PhraseQuery like
  • PhraseQuery pq=new PhraseQuery();
            pq.add(new Term("fieldName", "learning"));
            pq.add(new Term("fieldName", "ABC"));
            pq.setSlop(0);
  • Search will not contain above document, because when textfield is indexed with the help of StandardAnalyzer terms are converted to lowercase and then indexed.


No comments:

Post a Comment