【发布时间】:2012-05-03 16:00:06
【问题描述】:
我在使用 Lucene 索引 IList 时遇到了一些无聊的问题,我无法解决。
我的实体包含 IList,我像这样应用 IndexedEmbedded 属性:
[ScriptIgnore] //will not serialize
[IndexedEmbedded(Depth = 1, Prefix = "BookAdditionalInfos_"]
public virtual IList<BookAdditionalInfo> BookAdditionalInfos { get; set; }
另外,一些其他属性使用 Field 属性进行索引:
[Field(Index.Tokenized, Store = Store.Yes)]
在为索引标记实体后,我必须对 1200 万行进行初始索引(使用批处理)。在我开始索引名为 BookAdditionalInfos 的 IList 之前,一切都很完美。没有这个 IndexedEmbedded 属性(或没有索引这个 IList)一切正常,每个带有 Field 属性的属性标记都将被索引。
我正在使用 Fluent NHibernate。
可能是什么问题?
谢谢
编辑:我也查看了http://ayende.com/blog/3992/nhibernate-search,但没有任何结果
问题是:当我尝试为 IList 编制索引时,索引会永远占用并且不会编制任何索引。没有索引这个 IList(或没有指定 IndexedEmbedded 到 IList)索引是可以的,我得到了索引结果。
EDIT(初始索引功能):
public void BuildInitialBookSearchIndex()
{
FSDirectory directory = null;
IndexWriter writer = null;
var type = typeof(Book);
var info = new DirectoryInfo(GetIndexDirectory());
//if (info.Exists)
//{
// info.Delete(true);
//}
try
{
directory = FSDirectory.GetDirectory(Path.Combine(info.FullName, type.Name), true);
writer = new IndexWriter(directory, new StandardAnalyzer(), true);
}
finally
{
if (directory != null)
{
directory.Close();
}
if (writer != null)
{
writer.Close();
}
}
var fullTextSession = Search.CreateFullTextSession(Session);
var currentIndex = 0;
const int batchSize = 5000;
while (true)
{
var entities = Session
.CreateCriteria<Book>()
.SetFirstResult(currentIndex)
.SetMaxResults(batchSize)
.List();
using (var tx = Session.BeginTransaction())
{
foreach (var entity in entities)
{
fullTextSession.Index(entity);
}
currentIndex += batchSize;
Session.Flush();
tx.Commit();
Session.Clear();
}
if (entities.Count < batchSize)
break;
}
}
【问题讨论】:
-
有什么问题?是否抛出异常?
-
不抛出异常。上面的问题提供了我用于索引 1200 万行的初始索引函数。我猜这个函数有问题,当 IList 被标记为 IndexedEmbedded
-
我很困惑,当您说问题时,您是什么意思,没有抛出异常,OK。它需要永远吗?它是否错误地索引了该字段?
-
普雷斯科特,谢谢您的回复。问题是:当我尝试索引 IList 时,索引会永远占用并且不会索引任何内容。没有索引这个 IList(或没有指定 IndexedEmbedded 到 IList)索引是可以的,我得到了索引结果。
标签: nhibernate search lucene.net