2011-03-08 53 views
0

我必须在NHibernate 3.0中使用lucene.net 2.9.2.2。我已经开始编辑这个旧代码:使用lucene.net构建索引2.9.2.2

public void BuildSearchIndex() 
{ 

    FSDirectory entityDirectory = null; 
    IndexWriter writer = null; 

    var entityType = typeof(MappedSequence); 

    var indexDirectory = new DirectoryInfo(GetIndexDirectory()); 

    if (indexDirectory.Exists) 
    { 
    indexDirectory.Delete(true); 
    } 

    try 
    { 
    entityDirectory = FSDirectory.GetDirectory(Path.Combine(indexDirectory.FullName, entityType.Name), true); 
    writer = new IndexWriter(entityDirectory, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29), true, IndexWriter.MaxFieldLength.UNLIMITED); 
    } 
    finally 
    { 
    if (entityDirectory != null) 
    { 
     entityDirectory.Close(); 
    } 

    if (writer != null) 
    { 
     writer.Close(); 
    } 
    } 

    IFullTextSession fullTextSession = Search.CreateFullTextSession(this.Session); 
    // Iterate through Suppliers and add them to Lucene's index 
    foreach (MappedSequence instance in Session.CreateCriteria(typeof(MappedSequence)).List<MappedSequence>()) 
    { 
    fullTextSession.Index(instance); 
    } 
} 

private string GetIndexDirectory() 
{ 
    INHSConfigCollection nhsConfigCollection = CfgHelper.LoadConfiguration(); 
    string property = nhsConfigCollection.DefaultConfiguration.Properties["hibernate.search.default.indexBase"]; 
    var fi = new FileInfo(property); 
    return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fi.Name); 
} 

构建索引。该行:

FSDirectory.GetDirectory(Path.Combine(indexDirectory.FullName, entityType.Name), true); 

仍然使用过时的代码。任何人都可以如此善良并指出必要的改变。谢谢。

基督教

PS

回答

0

尝试使用FSDirectory.Open(路径)来代替。

+0

对不起,getdirectory方法不采用版本。你能看看图像吗(见PS)?谢谢。 – cs0815 2011-03-08 14:20:13

+0

对不起,错误地回忆,并在思考错误的obsolte电话。修复了答案。 – 2011-03-08 15:06:12

+1

谢谢。 this:entityDirectory = FSDirectory.Open(new DirectoryInfo(Path.Combine(indexDirectory.FullName,entityType.Name)));工作正常。 – cs0815 2011-03-08 15:34:35