Пример #1
0
        public ActionResult Index(string keyWords, int page = 1)
        {
            SearchViewModel viewModel=new SearchViewModel();
            try
            {
                int totalHit = 0;
                IndexManager indexManager =
                    new IndexManager(Server.MapPath(IndexPath),
                        Server.MapPath(DictPath));
                viewModel.resultList = indexManager.SearchFromIndexDataByPage(keyWords, page, 20, out totalHit);
                viewModel.TotalHit = totalHit;

                viewModel.AllCount = totalHit;
                viewModel.PageIndex = page;
                viewModel.PageStep = 10;
                viewModel.PageSize = 20;
                viewModel.Keywords = keyWords;
                if (viewModel.AllCount % viewModel.PageSize == 0)
                {
                    viewModel.PageCount = viewModel.AllCount / viewModel.PageSize;
                }
                else
                {
                    viewModel.PageCount = viewModel.AllCount / viewModel.PageSize + 1;
                }
            }
            catch (Exception e)
            {
                LogService.Log("搜索失败---"+e.Message,e.ToString());
            }
            return View(viewModel);
        }
Пример #2
0
        public ActionResult SiteSerach(FormCollection form)
        {
            PublicConfig serachConfig = null;
            try
            {
                DateTime LastUpdateTime;
                string result = string.Empty;
                const string http = "http://{0}/";
                string baseroot = string.Format(http, Request.Url.Authority);
                // Use related url instead of full url, becuase always link to PC site when view search result in wechat client.
                //string baseroot = "/";

                serachConfig = GetConfig();

                LastUpdateTime = serachConfig.LastUpdatedTime;
                IndexManager indexManager =
                    new IndexManager(Server.MapPath(IndexPath), Server.MapPath(DictPath));

                List<MetaSource> sourceList = new List<MetaSource>();
                MetaSource source = null;

                int newAddIndex = 0;

                #region 活动

                ActivityService activityService=new ActivityService();
                List<Activity> activities = activityService.QueryActivities(
                    new QueryActivityCriteria
                    {
                        QueryType = 6,
                        LastUpdatedTime = LastUpdateTime,
                        PageSize = int.MaxValue,
                        StartRowIndex = 1,

                    });
                if (activities != null && activities.Count > 0)
                {
                    foreach (Activity n in activities)
                    {
                        source = new MetaSource()
                        {
                            ResourceId = n.Id,
                            Title = n.Title,
                            Time = n.CreatedTime.Value.ToShortDateString(),
                            CreatedTime = n.CreatedTime.Value,
                            ResultType = SearchResultType.Activity,
                            ProvinceId = n.Province,
                            CityId = n.City,
                            AreaId = n.Area
                        };
                        source.Url = GenFullUrl(baseroot, n.Id, "activity");
                        source.Imgs = string.Empty;
                        if (n.ImgUrls != null && n.ImgUrls.Length > 0)
                        {
                            foreach (var img in n.ImgUrls)
                            {
                                source.Imgs = source.Imgs + split + img;
                            }
                            source.Imgs = source.Imgs.TrimStart(split.ToCharArray());
                        }
                        // 过滤内容
                        source.Content = ParseTags(n.ContentStyle);
                        source.CheckFields(baseroot);
                        sourceList.Add(source);
                        newAddIndex++;
                    }
                }

                #endregion

                #region 资源

                ResourceManager resourceManager = new ResourceManager();
                var resources = resourceManager.GetResourcesByTime(LastUpdateTime);
                if (resources != null && resources.Count > 0)
                {
                    foreach (Witbird.SHTS.DAL.New.Resource n in resources)
                    {
                        source = new MetaSource()
                        {
                            ResourceId = n.Id,
                            Title = n.Title,
                            Time = n.LastUpdatedTime.ToShortDateString(),
                            CreatedTime = n.LastUpdatedTime,
                            // 资源存储类型为场地1, 演员2,设备3,其他4
                            ResultType = (SearchResultType)(n.ResourceType - 1),
                            ProvinceId = n.ProvinceId,
                            CityId = n.CityId,
                            AreaId = n.AreaId
                        };
                        source.Url = GenFullUrl(baseroot, n.Id, "Resource");
                        source.Imgs = string.Empty;
                        if (n.ImgUrls != null && n.ImgUrls.Length > 0)
                        {
                            foreach (var img in n.ImgUrls)
                            {
                                source.Imgs = source.Imgs + split + img;
                            }
                            source.Imgs = source.Imgs.TrimStart(split.ToCharArray());
                        }
                        // 过滤内容
                        source.Content = ParseTags(n.Description);
                        source.CheckFields(baseroot);
                        sourceList.Add(source);
                    }
                }

                #endregion

                #region 需求

                DemandManager demandManager = new DemandManager();
                var demands = demandManager.QueryDemandsByTime(LastUpdateTime);
                if (demands != null && demands.Count > 0)
                {
                    foreach (Demand n in demands)
                    {
                        source = new MetaSource()
                        {
                            ResourceId = n.Id,
                            Title = n.Title,
                            Time = n.InsertTime.ToShortDateString(),
                            CreatedTime = n.InsertTime,
                            ResultType = SearchResultType.Demand,
                            ProvinceId = n.Province,
                            CityId = n.City,
                            AreaId = n.Area
                        };
                        source.Url = GenFullUrl(baseroot, n.Id, "Demand");
                        source.Imgs = string.Empty;
                        // 过滤内容
                        source.Content = ParseTags(n.Description);
                        source.CheckFields(baseroot);
                        sourceList.Add(source);
                    }
                }

                #endregion

                indexManager.AddIndexByData(sourceList);
                serachConfig.LastUpdatedTime=DateTime.Now;
                UpdateConfig(serachConfig);
            }
            catch (Exception e)
            {
                LogService.Log("Cretae Serach index", e.ToString());
            }
            return View(serachConfig);
        }