示例#1
0
        /// <summary>
        /// 扫描数据库上下文并对所有已实现ILuceneIndexable的对象,并创建索引
        /// </summary>
        public void CreateIndex()
        {
            if (_indexer != null)
            {
                List <ILuceneIndexable> index      = new List <ILuceneIndexable>();
                PropertyInfo[]          properties = Context.GetType().GetProperties();
                foreach (PropertyInfo pi in properties)
                {
                    if (typeof(IEnumerable <ILuceneIndexable>).IsAssignableFrom(pi.PropertyType))
                    {
                        var entities = Context.GetType().GetProperty(pi.Name).GetValue(Context, null);
                        index.AddRange(entities as IEnumerable <ILuceneIndexable>);
                    }
                }

                if (index.Any())
                {
                    _indexer.CreateIndex(index);
                }
            }
        }
示例#2
0
        /// <summary>
        /// 创建指定数据表的索引
        /// </summary>
        public void CreateIndex(List <string> tables)
        {
            if (LuceneIndexer == null)
            {
                return;
            }

            var properties = Context.GetType().GetProperties();

            foreach (var pi in properties)
            {
                if (typeof(IQueryable <ILuceneIndexable>).IsAssignableFrom(pi.PropertyType) && tables.Contains(pi.Name))
                {
                    var entities = Context.GetType().GetProperty(pi.Name).GetValue(Context, null) as IQueryable <ILuceneIndexable>;
                    LuceneIndexer.CreateIndex(entities, false);
                }
            }
        }
示例#3
0
        /// <summary>
        /// 创建指定数据表的索引
        /// </summary>
        public void CreateIndex(List <string> tables)
        {
            if (LuceneIndexer == null)
            {
                return;
            }

            var index      = new List <ILuceneIndexable>();
            var properties = Context.GetType().GetProperties();

            foreach (var pi in properties)
            {
                if (typeof(IEnumerable <ILuceneIndexable>).IsAssignableFrom(pi.PropertyType) && tables.Contains(pi.Name))
                {
                    var entities = Context.GetType().GetProperty(pi.Name).GetValue(Context, null);
                    index.AddRange(entities as IEnumerable <ILuceneIndexable>);
                }
            }

            if (index.Any())
            {
                LuceneIndexer.CreateIndex(index);
            }
        }