Exemple #1
0
        public BaseApiResponse SearchGoodses([FromBody] SearchGoodsesRequest request)
        {
            request.CheckNotNull(nameof(request));
            var goodses = _goodsQueryService.Goodses().Where(x => x.Name.Contains(request.Name));

            return(new GoodsAlisesResponse
            {
                Goodses = goodses.Select(x => new GoodsAlis
                {
                    Id = x.Id,
                    Name = x.Name,
                    Pic = x.Pics.Split("|", true).Length > 0 ? x.Pics.Split("|", true)[0] : "",
                    Price = x.Price
                }).ToList()
            });
        }
Exemple #2
0
        public void CreateSearchIndex()
        {
            //路径判断
            if (!System.IO.Directory.Exists(SearchIndexPath))
            {
                System.IO.Directory.CreateDirectory(SearchIndexPath);
            }

            Directory   indexDirectory = FSDirectory.Open(new System.IO.DirectoryInfo(SearchIndexPath));
            var         analyzer       = new PanGuAnalyzer();
            IndexWriter writer         = null;

            try
            {
                //重新创建索引
                bool isCreate = true;// !IndexReader.IndexExists(indexDirectory);
                writer = new IndexWriter(indexDirectory, analyzer, isCreate, IndexWriter.MaxFieldLength.UNLIMITED);

                //所有的上架已审核的商品
                var goodses = _goodsQueryService.Goodses().Where(
                    g => g.IsPublished && g.Status == GoodsStatus.Verifyed);

                //开始添加索引
                foreach (var goods in goodses)
                {
                    AddIndex(writer, goods);
                }
                writer.Optimize();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (analyzer != null)
                {
                    analyzer.Close();
                }
                if (writer != null)
                {
                    writer.Dispose();
                }
                if (indexDirectory != null)
                {
                    indexDirectory.Dispose();
                }
            }
        }