Lucene의 RAMDirectory는 언제 사용해야합니까? 다른 스토리지 메커니즘에 비해 장점은 무엇입니까? 마지막으로 간단한 코드 예제는 어디에서 찾을 수 있습니까?RAMDirectory 사용
13
A
답변
16
인덱스 데이터를 영구 저장하지 않으려는 경우. 나는 이것을 테스트 목적으로 사용한다. RAMDirectory에 데이터를 추가하십시오. RAMDir에서 유닛 테스트를 수행하십시오.
예 :
public static void main(String[] args) {
try {
Directory directory = new RAMDirectory();
Analyzer analyzer = new SimpleAnalyzer();
IndexWriter writer = new IndexWriter(directory, analyzer, true);
또는 일이 RAMDirectory와 운동 보통 경우
public void testRAMDirectory() throws IOException {
Directory dir = FSDirectory.getDirectory(indexDir);
MockRAMDirectory ramDir = new MockRAMDirectory(dir);
// close the underlaying directory
dir.close();
// Check size
assertEquals(ramDir.sizeInBytes(), ramDir.getRecomputedSizeInBytes());
// open reader to test document count
IndexReader reader = IndexReader.open(ramDir);
assertEquals(docsToAdd, reader.numDocs());
// open search zo check if all doc's are there
IndexSearcher searcher = new IndexSearcher(reader);
// search for all documents
for (int i = 0; i < docsToAdd; i++) {
Document doc = searcher.doc(i);
assertTrue(doc.getField("content") != null);
}
// cleanup
reader.close();
searcher.close();
}
, 다른 사람과 것 거의 잘 작동. 즉 색인을 영구 저장하는 것입니다.
대체물은 FSDirectory입니다. 이 경우 파일 시스템 권한을 처리해야합니다 (RAMDirectory에는 유효하지 않습니다).
RAMDirectory에 비해 RAMDirectory의 뚜렷한 장점은 없습니다 (RAMDirectory가 FSDirectory보다 눈에 띄게 빨라진다는 점을 제외하고는). 둘 다 서로 다른 두 가지 요구를 처리합니다.
- RAMDirectory -> 기본 메모리
- FSDirectory -> 보조 메모리
& 하드 디스크를 RAM에 아주 유사한.
RAMDirectory가 메모리 제한을 초과하면 어떻게 될지 잘 모르겠습니다. System.SystemException 던져
: 나는
에서 OutOfMemoryException을 제외시켰다 것입니다.
내부적으로 파일을 정렬하기 위해 동시 처리 맵을 사용합니다. – Njax3SmmM2x2a0Zf7Hpd