0
Lucene (버전 4.10.1)에서 첫 걸음을 내디뎠으며 현재 나의 목표는 100KB의 파일에서 텍스트 필드를 색인하는 것입니다. 텍스트가 문자열에 맞지 않기 때문에 파일의 텍스트를 바이트 배열에 넣었습니다. 그러나 Lucene 프로그램을 실행할 때 Fields with BytesRef values cannot be indexed
라고합니다.Lucene에서 큰 텍스트 필드를 색인하는 방법 4.10.1
그래서 질문입니다 : 큰 텍스트 필드를 어떻게 인덱스합니까? StringBuilder
그것을 해결
public class Main {
public static void main(String[] args) {
try {
Directory indexDir = FSDirectory.open(new File("testIndex"));
Analyzer analyzer = new StandardAnalyzer();
IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_4_10_1, analyzer);
IndexWriter indexWriter = new IndexWriter(indexDir, conf);
Path path = Paths.get("text.txt");
byte[] text = Files.readAllBytes(path);
Long startTime = System.currentTimeMillis();
for(int i = 0;i<100;i++) {
Document doc = new Document();
FieldType fieldType = new FieldType();
fieldType.setIndexed(true);
fieldType.setTokenized(true);
fieldType.setStored(true);
fieldType.setOmitNorms(true);
fieldType.setStoreTermVectors(false);
fieldType.setStoreTermVectorOffsets(false);
fieldType.setStoreTermVectorPayloads(false);
fieldType.setStoreTermVectorPositions(false);
Field title = new Field("text"+i, text, fieldType);
doc.add(title);
indexWriter.addDocument(doc);
}
Long endTime = System.currentTimeMillis();
Long elapsedTime = endTime - startTime;
System.out.println("Elapsed Time in Ms: "+elapsedTime);
indexWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}