여러 용어로 구성된 문자열로 Lucene 4.5로 만든 색인에 대해 StringField를 쿼리하려고합니다.Lucene 4.5. 복수 용어 쿼리에 대한 StringField 검색
다음 코드 스니 j/의사 코드를 사용하여 Document 오브젝트를 작성한다고 가정 해보십시오.
Directory dir = FSDirectory.open(new File(indexPath));
Analyzer analyzer = new EnglishAnalyzer(Version.LUCENE_45);
IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_45, analyzer);
iwc.setOpenMode(OpenMode.CREATE);
IndexWriter writer = (dir, iwc);
Document doc = new Document();
Field title = new StringField("Title", minQuery, Field.Store.YES);
doc.add(title);
writer.addDocument(doc);
지금 내가 가서 다음 쿼리 코드를 (다시 내가 사용하고 실제 코드의 단지 스케치입니다)를 사용하여 위의 생성 인덱스를 조회한다고 가정
IndexReader reader = DirectoryReader.open(FSDirectory.open(new File(indexPath)));
BM25Similarity bm25sim = new BM25Similarity();
IndexSearcher searcher = new IndexSearcher(reader);
searcher.setSimilarity(bm25sim);
Analyzer analyzer = new EnglishAnalyzer(Version.LUCENE_45);
QueryParser parser = new QueryParser(Version.LUCENE_45, "Content", analyzer);
Query query = parser.parse("Title:\"washington dc\"");
TopDocs result = searcher.search(query, 1);
나는 코드를 실행하면 내가 (쿼리 1) 선언문 searcher.search의 대응에 다음과 같은 예외를 가지고 위 :
Exception in thread "main" java.lang.IllegalStateException: field "Title" was
indexed without position data; cannot run PhraseQuery (term=washington)
나는 주위를 둘러 보았다 한 나는이 문제를 극복 할 수있는 방법을 찾을 수 없습니다. Lucene의 이전 버전에서 Field.Index.ANALYZED 옵션을 필드 생성에 추가 할 수있는 것처럼 보이지만 제 경우에는 그렇게 할 수 없었습니다.
아이디어가 있으십니까?
매력처럼 작동합니다. 고마워요! –