/// <summary> /// 创建索引 /// </summary> public void CreateIndex <T, TKey>(T[] indexObjects, Expression <Func <T, TKey> > keySelector, LuceneIndexBehavior <T> behavior = null) { if (LuceneIndexer == null) { return; } var index = new List <ILuceneIndexable>(); var properties = typeof(T).GetProperties(); foreach (var obj in indexObjects) { index.Add(new LuceneIndexable <T, TKey>(obj, keySelector.Compile()(obj), behavior)); } if (index.Any()) { LuceneIndexer.CreateIndex(index); } }
/// <summary> /// 搜索引擎 /// </summary> /// <param name="directory"></param> /// <param name="analyzer"></param> /// <param name="memoryCache"></param> public SearchEngineImp(Directory directory, Analyzer analyzer, ICache cache) { this.analyzer = analyzer; LuceneIndexer = new LuceneIndexer(directory, analyzer); LuceneIndexSearcher = new LuceneIndexSearcher(directory, analyzer, cache); }
/// <summary> /// 删除索引 /// </summary> public void DeleteIndex() { LuceneIndexer?.DeleteAll(); }