본문 바로가기

IT-Consultant

루씬에서 데이터를 파일에 어떻게 저장하는가?

루씬에서 파일저장할때 버클리 DB를 사용한다고 알고 있었으나, 소스 분석해보니 버클리 DB를 사용하지는 않았다. 버클리 DB를 사용할 수 있긴 하지만 별도 작업을 해줘야 한다.
기본적으로 사용하는 파일은 java.io.RandomAccessFile 클래스를 이용해서 만든다.
실제 소스를 보면 directory와 file name을 주면 파일이 생성된다.
  /** Creates a new, empty file in the directory with the given name.
      Returns a stream writing this file. */
  public IndexOutput createOutput(String name) throws IOException {

    File file = new File(directory, name);
    if (file.exists() && !file.delete())          // delete existing, if any
      throw new IOException("Cannot overwrite: " + file);

    return new FSIndexOutput(file);
  }

파일 생성부분을 알아보았고, 실제 파일에 쓸때 어떻게 하는지 알아보자.
createOutput으로 stream을 얻어서 writeInt, writeLog등으로 파일에 쓰게 된다.
    output = directory.createOutput(segment + (isIndex ? ".tii" : ".tis"));
    output.writeInt(FORMAT);                      // write format
    output.writeLong(0);                          // leave space for size
    output.writeInt(indexInterval);             // write indexInterval
    output.writeInt(skipInterval);              // write skipInterval

'IT-Consultant' 카테고리의 다른 글

루씬 색인 파일 종류  (0) 2007.06.10
루씬에서 데이터를 파일에 어떻게 저장하는가?  (0) 2007.06.10
색인구조  (0) 2007.06.09
국립중앙도서관, 국회도서관 통합검색하기  (0) 2007.05.28
Lesson 3  (0) 2007.05.22