분산 Lucene의 인덱스 데이터
분산 Lucene은 인덱스를 생성하고 디렉토리에 저장해야 하는 문서를 인덱스화하여 효율적인 검색을 가능하게 합니다. 첫 번째 단계는 초기화 인덱스를 저장하는 디렉토리. Lucene.NET과 달리 NCacheDirectory
캐시 이름과 인덱스 이름을 지정하여 디렉토리를 여는 데 사용됩니다.
주의 사항
이 기능은 다음에서도 사용할 수 있습니다. NCache Professional.
주의 사항
색인 디렉토리의 기본 경로는 다음과 같습니다. C : \ ProgramData \ncache\lucene-index\{CACHE_NAME}\데이터 Windows용 및 /사용자/공유/ncache/lucene-index/{CACHE_NAME}/데이터 Linux 용.
디렉토리가 초기화되면, IndexWriter
의 인스턴스를 제공하여 열립니다. NCacheDirectory
그리고 색인 작성기 구성. IndexWriter
Lucene.NET에서와 동일한 메커니즘으로 색인에 문서를 추가하고 인덱싱합니다. AddDocument
방법.
주의 사항
캐시 서버 간 문서 배포를 위해, NCache 자동으로 추가 TextField
와 DocKey
필드 및 사용자가 지정하지 않은 경우 문서에 자동 생성된 GUID 값.
인덱스에서 수행되는 모든 쓰기 작업은 동기식입니다. 따라서 해당 작업이 완료된 후에만 사용자에게 반환됩니다. 이는 분산 Lucene에 데이터 일관성과 무결성을 추가합니다.
중대한
라이터에 대한 쓰기 작업을 위해 다음을 호출해야 합니다. Commit
문서 디렉토리에 저장합니다. 커밋을 호출해야 합니다. 그렇지 않으면 쓰기 작업이 저장되지 않으며 추가된 문서에 대한 검색 작업에도 영향을 미칠 수 있습니다.
Lucene.NET과 달리 병렬 인덱싱을 위해 동일한 디렉토리에서 여러 작성기를 열 수 있습니다. 문서를 작성할 때, IndexWriter.Commit
문서를 유지하고 검색 가능하게 만들기 위해 호출됩니다. 일단 IndexWriter
데이터 인덱싱에 사용되며, IndexWriter.Dispose
사용 중인 리소스를 해제하려면 호출해야 합니다.
팁
다음을 사용하여 인스턴스에서 쓰기 작업 완료에 대한 정보를 얻을 수 있습니다. NCache 제공 Boolean
재산 IndexWriter.OperationsCompleted
.
사전 조건
- 모든 작업에 필요한 표준 전제 조건에 대해 알아보려면 NCache 클라이언트측 기능은 다음 페이지를 참조하세요. 클라이언트 측 API 전제 조건.
- 다음을 통해 Lucene 캐시를 만들고 시작했는지 확인하십시오. NCache 관리 센터 or 명령 행 인터페이스.
- 그 확인 클라이언트 알림 사용할 수 있습니다.
- 애플리케이션이 기본 Lucene DLL/참조를 사용하고 있지 않은지 확인하십시오.
- API 세부 정보는 다음을 참조하세요. NCache명부 담당, 분석기, WhiteSpace분석기, 인덱스 라이터, 색인 작성기 구성, 커밋, 문서 추가, 문서.
인덱싱 데이터
다음 예는 먼저 NCacheDirectory
캐시 이름을 다음과 같이 지정하여 루씬캐시 인덱스 이름은 다음과 같습니다. 제품 인덱스. 그러면 열립니다. IndexWriter
다음을 지정하여 지정된 디렉토리에서 공백분석기 데이터 분석을 위해.
경고
다음의 경우 인덱스 쓰기 작업이 허용되지 않습니다. 부분 클러스터.
// Specify the Distributed-Lucene cache name
string cache = "LuceneCache";
// Specify the index name to create the indexes
string indexName = "ProductIndex";
NCacheDirectory ncacheDirectory = null;
IndexWriter indexWriter = null;
//Initializing
// Create a directory and open it on the cache and the index path
ncacheDirectory = NCacheDirectory.Open(cache, indexName);
// Specify the analyzer used to analyze data
Analyzer analyzer = new WhitespaceAnalyzer(LuceneVersion.LUCENE_48);
// Create an indexWriterConfig which holds all the configurations to create an instance of the writer
IndexWriterConfig config = new IndexWriterConfig(LuceneVersion.
LUCENE_48, analyzer);
// Create an instance of the writer
indexWriter = new IndexWriter(ncacheDirectory, new IndexWriterConfig
(LuceneVersion.LUCENE_48, _analyzer));
// Indexing
// Add the products information that is to be indexed
Product[] products = FetchProductsFromDB();
foreach (var prod in products)
{
// Create a document and add fields to it
Document doc = new Document();
doc.Add(new TextField("ProductID", prod.ProductID.ToString(),
Field.Store.YES));
doc.Add(new TextField("ProductName", prod.ProductName, Field.Store.NO));
doc.Add(new TextField("Category", prod.Category, Field.Store.YES));
doc.Add(new TextField("Description", prod.Description, Field.Store.YES));
// Writer is created previously
indexWriter.AddDocument(doc);
}
// Calling commit on the writer saves all the write operations
indexWriter.Commit();
if(indexWriter.OperationsCompleted)
{
// All writing operations are complete
// Can proceed with other operations such as querying
}
// Dispose the indexWriter after indexing
if (indexWriter != null) indexWriter.Dispose();
// Dispose the ncacheDirectory
if (ncacheDirectory != null) ncacheDirectory.Dispose();
주의 사항
당신은 전화해야합니다 Dispose
마지막에 writer
그렇지 않으면 메모리에 상주하며 메모리 누수를 유발합니다.
추가 자료
NCache Distributed Lucene에 대한 샘플 애플리케이션을 제공합니다. GitHub의.
도 참조
.그물: Lucene.Net.인덱스 네임 스페이스.