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을 제외시켰다 것입니다.
관련 문제
- 1. javax.xml.xpath 사용. scala.xml 사용
- 2. 사용
- 3. 사용
- 4. 사용
- 5. 사용
- 6. 사용
- 7. 사용
- 8. 사용
- 9. 사용
- 10. 사용
- 11. 사용
- 12. 사용
- 13. 사용
- 14. 사용
- 15. 사용
- 16. 사용
- 17. 사용
- 18. 사용
- 19. f # 키워드 사용 및 사용
- 20. 점 표기법 사용/사용 안함?
- 21. 함수 사용 vslt에서 템플릿 사용?
- 22. 쿼리에서 별칭 사용 및 사용
- 23. 새로운 사용/삭제의 올바른 사용
- 24. 알림 사용/사용 안 함
- 25. 배포자에게 사용 패턴 - 사용 패턴?
- 26. DI의 사용 패턴/사용 사례 또는 사용 시작시기
- 27. 로컬로 Mercurial 사용 Subversion 서버에서만 사용
- 28. MySQL - IF 사용 ... 쿼리 내 ELSE 사용
- 29. 요소 규칙 사용 및 사용 안 함
- 30. HTML 표 사용 가능 너비의 100 % 사용
내부적으로 파일을 정렬하기 위해 동시 처리 맵을 사용합니다. – Njax3SmmM2x2a0Zf7Hpd