示例#1
0
        //临时数据代替表单提交
        private void InsertToIndex() {
            //创建一条临时数据
            Books book = new Books();
            book.Author = "痞子一毛";
            book.Title = "piziyimao";
            book.CategoryId = 1;
            book.ContentDescription = "不是所有痞子都叫一毛不是所有痞子都叫一毛不是所有痞子都叫一毛不是所有痞子都叫一毛";
            book.PublisherId = 1;
            book.ISBN = "124365";
            book.WordsCount = 1000000;
            book.UnitPrice = 88;
            book.CategoryId = 1;
            book.Clicks = 10;
            book.PublishDate = DateTime.Now;
            BooksManager bm = new BooksManager();
            //IndexManager.bookIndex.Add()数据新增 索引库更新测试

            //int insertId;
            //if((insertId = bm.Add(book)) > 0) {
            //    book.Id = insertId;
            //    IndexManager.bookIndex.Add(book);
            //}

            //IndexManager.bookIndex.Mod()数据修改 索引库更新测试
            book.Id = 10001;//数据库生成主键ID
            book.ContentDescription = "侬好哇, 记住不是所有痞子都叫一毛哟";
            bm.Update(book);
            IndexManager.bookIndex.Mod(book);
        }
示例#2
0
 /// <summary>
 /// 修改Books表信息时 添加修改索引(实质上是先删除原有索引 再新增修改后索引)请求至队列
 /// </summary>
 /// <param name="books"></param>
 public void Mod(Books books) {
     BookViewMode bvm = new BookViewMode();
     bvm.Id = books.Id;
     bvm.Title = books.Title;
     bvm.IT = IndexType.Modify;
     bvm.Content = books.ContentDescription;
     bookQueue.Enqueue(bvm);
 }
示例#3
0
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List <PZYM.Shop.Model.Books> DataTableToList(DataTable dt)
        {
            List <PZYM.Shop.Model.Books> modelList = new List <PZYM.Shop.Model.Books>();
            int rowsCount = dt.Rows.Count;

            if (rowsCount > 0)
            {
                PZYM.Shop.Model.Books model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new PZYM.Shop.Model.Books();
                    if (dt.Rows[n]["Id"].ToString() != "")
                    {
                        model.Id = int.Parse(dt.Rows[n]["Id"].ToString());
                    }
                    model.Title  = dt.Rows[n]["Title"].ToString();
                    model.Author = dt.Rows[n]["Author"].ToString();
                    if (dt.Rows[n]["PublisherId"].ToString() != "")
                    {
                        model.PublisherId = int.Parse(dt.Rows[n]["PublisherId"].ToString());
                    }
                    if (dt.Rows[n]["PublishDate"].ToString() != "")
                    {
                        model.PublishDate = DateTime.Parse(dt.Rows[n]["PublishDate"].ToString());
                    }
                    model.ISBN = dt.Rows[n]["ISBN"].ToString();
                    if (dt.Rows[n]["WordsCount"].ToString() != "")
                    {
                        model.WordsCount = int.Parse(dt.Rows[n]["WordsCount"].ToString());
                    }
                    if (dt.Rows[n]["UnitPrice"].ToString() != "")
                    {
                        model.UnitPrice = decimal.Parse(dt.Rows[n]["UnitPrice"].ToString());
                    }
                    model.ContentDescription = dt.Rows[n]["ContentDescription"].ToString();
                    model.AurhorDescription  = dt.Rows[n]["AurhorDescription"].ToString();
                    model.EditorComment      = dt.Rows[n]["EditorComment"].ToString();
                    model.TOC = dt.Rows[n]["TOC"].ToString();
                    if (dt.Rows[n]["CategoryId"].ToString() != "")
                    {
                        model.CategoryId = int.Parse(dt.Rows[n]["CategoryId"].ToString());
                    }
                    if (dt.Rows[n]["Clicks"].ToString() != "")
                    {
                        model.Clicks = int.Parse(dt.Rows[n]["Clicks"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return(modelList);
        }
示例#4
0
        /// <summary>
        /// 从索引库中检索关键字
        /// </summary>
        private void SearchFromIndexData()
        {
            string        indexPath = Context.Server.MapPath("~/IndexData");
            FSDirectory   directory = FSDirectory.Open(new DirectoryInfo(indexPath), new NoLockFactory());
            IndexReader   reader    = IndexReader.Open(directory, true);
            IndexSearcher searcher  = new IndexSearcher(reader);

            //--------------------------------------这里配置搜索条件
            //PhraseQuery query = new PhraseQuery();
            //foreach(string word in Common.SplitContent.SplitWords(Request.QueryString["SearchKey"])) {
            //    query.Add(new Term("content", word));//这里是 and关系
            //}
            //query.SetSlop(100);

            //关键词Or关系设置
            BooleanQuery queryOr = new BooleanQuery();
            TermQuery    query   = null;

            foreach (string word in Common.SplitContent.SplitWords(Request.QueryString["SearchKey"]))
            {
                query = new TermQuery(new Term("content", word));
                queryOr.Add(query, BooleanClause.Occur.SHOULD);//这里设置 条件为Or关系
            }
            //--------------------------------------
            TopScoreDocCollector collector = TopScoreDocCollector.create(1000, true);

            //searcher.Search(query, null, collector);
            searcher.Search(queryOr, null, collector);


            ScoreDoc[] docs = collector.TopDocs(0, 10).scoreDocs;//取前十条数据  可以通过它实现LuceneNet搜索结果分页
            List <PZYM.Shop.Model.Books> bookResult = new List <PZYM.Shop.Model.Books>();

            for (int i = 0; i < docs.Length; i++)
            {
                int      docId = docs[i].doc;
                Document doc   = searcher.Doc(docId);

                PZYM.Shop.Model.Books book = new PZYM.Shop.Model.Books();
                book.Title = doc.Get("title");
                book.ContentDescription = Common.SplitContent.HightLight(Request.QueryString["SearchKey"], doc.Get("content"));
                book.Id = Convert.ToInt32(doc.Get("id"));
                bookResult.Add(book);
            }
            Repeater1.DataSource = bookResult;
            Repeater1.DataBind();
        }
示例#5
0
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List <PZYM.Shop.Model.Books> DataTableToList(DataTable dt)
        {
            List <PZYM.Shop.Model.Books> modelList = new List <PZYM.Shop.Model.Books>();
            int rowsCount = dt.Rows.Count;

            if (rowsCount > 0)
            {
                PZYM.Shop.Model.Books model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new PZYM.Shop.Model.Books();
                    if (dt.Rows[n]["Id"].ToString() != "")
                    {
                        model.Id = int.Parse(dt.Rows[n]["Id"].ToString());
                    }
                    if (dt.Rows[n]["Description"].ToString() != "")
                    {
                        model.Description = dt.Rows[n]["Description"].ToString();
                    }
                    if (dt.Rows[n]["CreativeHTML"].ToString() != "")
                    {
                        model.CreativeHTML = dt.Rows[n]["CreativeHTML"].ToString();
                    }
                    if (dt.Rows[n]["MenuId"].ToString() != "")
                    {
                        model.MenuId = Convert.ToInt32(dt.Rows[n]["MenuId"]);
                    }
                    if (dt.Rows[n]["ImageUrl"].ToString() != "")
                    {
                        model.ImageUrl = dt.Rows[n]["ImageUrl"].ToString();
                    }
                    if (dt.Rows[n]["FileName"].ToString() != "")
                    {
                        model.FileName = dt.Rows[n]["FileName"].ToString();
                    }
                    if (dt.Rows[n]["FilePath"].ToString() != "")
                    {
                        model.FilePath = dt.Rows[n]["FilePath"].ToString();
                    }
                    modelList.Add(model);
                }
            }
            return(modelList);
        }
示例#6
0
        /// <summary>
        /// 从索引库中检索关键字
        /// </summary>
        private void SearchFromIndexData() {
            string indexPath = Context.Server.MapPath("~/IndexData");
            FSDirectory directory = FSDirectory.Open(new DirectoryInfo(indexPath), new NoLockFactory());
            IndexReader reader = IndexReader.Open(directory, true);
            IndexSearcher searcher = new IndexSearcher(reader);

            //--------------------------------------这里配置搜索条件
            //PhraseQuery query = new PhraseQuery();
            //foreach(string word in Common.SplitContent.SplitWords(Request.QueryString["SearchKey"])) {
            //    query.Add(new Term("content", word));//这里是 and关系
            //}
            //query.SetSlop(100);

            //关键词Or关系设置
            BooleanQuery queryOr = new BooleanQuery();
            TermQuery query = null;
            foreach(string word in Common.SplitContent.SplitWords(Request.QueryString["SearchKey"])) {
                query = new TermQuery(new Term("content", word));
                queryOr.Add(query, BooleanClause.Occur.SHOULD);//这里设置 条件为Or关系
            }
            //--------------------------------------
            TopScoreDocCollector collector = TopScoreDocCollector.create(1000, true);
            //searcher.Search(query, null, collector);
            searcher.Search(queryOr, null, collector);


            ScoreDoc[] docs = collector.TopDocs(0, 10).scoreDocs;//取前十条数据  可以通过它实现LuceneNet搜索结果分页
            List<PZYM.Shop.Model.Books> bookResult = new List<PZYM.Shop.Model.Books>();
            for(int i = 0; i < docs.Length; i++) {
                int docId = docs[i].doc;
                Document doc = searcher.Doc(docId);

                PZYM.Shop.Model.Books book = new PZYM.Shop.Model.Books();
                book.Title = doc.Get("title");
                book.ContentDescription = Common.SplitContent.HightLight(Request.QueryString["SearchKey"], doc.Get("content"));
                book.Id = Convert.ToInt32(doc.Get("id"));
                bookResult.Add(book);
            }
            Repeater1.DataSource = bookResult;
            Repeater1.DataBind();
        }
示例#7
0
        private void SearchFromIndexData(HttpContext context)
        {
            string        indexPath = context.Server.MapPath("~/IndexData");
            FSDirectory   directory = FSDirectory.Open(new DirectoryInfo(indexPath), new NoLockFactory());
            IndexReader   reader    = IndexReader.Open(directory, true);
            IndexSearcher searcher  = new IndexSearcher(reader);

            //--------------------------------------这里配置搜索条件
            //PhraseQuery query = new PhraseQuery();
            //foreach(string word in Common.SplitContent.SplitWords(Request.QueryString["SearchKey"])) {
            //    query.Add(new Term("content", word));//这里是 and关系
            //}
            //query.SetSlop(100);

            //关键词Or关系设置
            BooleanQuery queryOr = new BooleanQuery();
            TermQuery    query   = null;

            foreach (string word in Common.SplitContent.SplitWords(context.Request["SearchKey"]))
            {
                query = new TermQuery(new Term("CreativeHTML", word));
                queryOr.Add(query, BooleanClause.Occur.SHOULD); //这里设置 条件为Or关系
                query = new TermQuery(new Term("Description", word));
                queryOr.Add(query, BooleanClause.Occur.SHOULD); //这里设置 条件为Or关系
            }
            //--------------------------------------
            TopScoreDocCollector collector = TopScoreDocCollector.create(1000, true);

            //searcher.Search(query, null, collector);
            searcher.Search(queryOr, null, collector);

            int PageIndex = int.Parse(Convert.ToString(context.Request["PageIndex"]));
            int PageSize  = int.Parse(Convert.ToString(context.Request["PageSize"]));

            ScoreDoc[] docs = collector.TopDocs((PageIndex - 1) * PageSize, PageIndex * PageSize).scoreDocs;//取前十条数据  可以通过它实现LuceneNet搜索结果分页
            List <PZYM.Shop.Model.Books> bookResult = new List <PZYM.Shop.Model.Books>();
            DataTable dt = new DataTable();

            dt.TableName = "ds";
            dt.Columns.Add("Id", typeof(int));
            dt.Columns.Add("Description", typeof(string));
            dt.Columns.Add("CreativeHTML", typeof(string));
            dt.Columns.Add("MenuId", typeof(int));
            for (int i = 0; i < docs.Length; i++)
            {
                int      docId             = docs[i].doc;
                Document doc               = searcher.Doc(docId);
                PZYM.Shop.Model.Books book = new PZYM.Shop.Model.Books();
                book.Description  = Common.SplitContent.HightLight(context.Request["SearchKey"], doc.Get("Description"));
                book.CreativeHTML = Common.SplitContent.HightLight(context.Request["SearchKey"], doc.Get("CreativeHTML"));
                book.Id           = Convert.ToInt32(doc.Get("Id"));
                //bookResult.Add(book);
                DataRow dr = dt.NewRow();
                dr["Description"]  = book.Description;
                dr["CreativeHTML"] = book.CreativeHTML;
                //string CreativeHTML = book.CreativeHTML;
                //Regex objRegex = new Regex("/<[^>]*>/g", RegexOptions.IgnoreCase);
                //dr["CreativeHTML"]  = objRegex.Replace(book.CreativeHTML, "");
                dr["Id"]     = book.Id;
                dr["MenuId"] = Convert.ToInt32(doc.Get("MenuId"));
                dt.Rows.Add(dr);
            }
            JsonModel jsonModel = null;
            int       RowCount  = 0;
            PagedDataModel <Dictionary <string, object> > pagedDataModel = null;

            if (dt == null)
            {
                jsonModel = new JsonModel()
                {
                    status = "no",
                    errMsg = "无数据"
                };
            }
            RowCount = dt.Rows.Count;
            if (RowCount <= 0)
            {
                jsonModel = new JsonModel()
                {
                    status = "no",
                    errMsg = "无数据"
                };
            }
            List <Dictionary <string, object> > list = new List <Dictionary <string, object> >();

            list = DataTableToList(dt);
            int PageCount = (int)Math.Ceiling(RowCount * 1.0 / PageSize);

            pagedDataModel = new PagedDataModel <Dictionary <string, object> >()
            {
                PageCount = PageCount,
                PagedData = list,
                PageIndex = PageIndex,
                PageSize  = PageSize,
                RowCount  = RowCount
            };
            //将分页数据实体封装到JSON标准实体中
            jsonModel = new JsonModel()
            {
                errNum  = 0,
                errMsg  = "success",
                retData = pagedDataModel
            };
            System.Web.Script.Serialization.JavaScriptSerializer jss = new System.Web.Script.Serialization.JavaScriptSerializer();
            context.Response.Write("{\"result\":" + jss.Serialize(jsonModel) + "}");
        }
示例#8
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(PZYM.Shop.Model.Books model)
 {
     return(dal.Update(model));
 }
示例#9
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int  Add(PZYM.Shop.Model.Books model)
 {
     return(dal.Add(model));
 }
示例#10
0
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<PZYM.Shop.Model.Books> DataTableToList(DataTable dt)
		{
			List<PZYM.Shop.Model.Books> modelList = new List<PZYM.Shop.Model.Books>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				PZYM.Shop.Model.Books model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new PZYM.Shop.Model.Books();
					if(dt.Rows[n]["Id"].ToString()!="")
					{
						model.Id=int.Parse(dt.Rows[n]["Id"].ToString());
					}
					model.Title=dt.Rows[n]["Title"].ToString();
					model.Author=dt.Rows[n]["Author"].ToString();
					if(dt.Rows[n]["PublisherId"].ToString()!="")
					{
						model.PublisherId=int.Parse(dt.Rows[n]["PublisherId"].ToString());
					}
					if(dt.Rows[n]["PublishDate"].ToString()!="")
					{
						model.PublishDate=DateTime.Parse(dt.Rows[n]["PublishDate"].ToString());
					}
					model.ISBN=dt.Rows[n]["ISBN"].ToString();
					if(dt.Rows[n]["WordsCount"].ToString()!="")
					{
						model.WordsCount=int.Parse(dt.Rows[n]["WordsCount"].ToString());
					}
					if(dt.Rows[n]["UnitPrice"].ToString()!="")
					{
						model.UnitPrice=decimal.Parse(dt.Rows[n]["UnitPrice"].ToString());
					}
					model.ContentDescription=dt.Rows[n]["ContentDescription"].ToString();
					model.AurhorDescription=dt.Rows[n]["AurhorDescription"].ToString();
					model.EditorComment=dt.Rows[n]["EditorComment"].ToString();
					model.TOC=dt.Rows[n]["TOC"].ToString();
					if(dt.Rows[n]["CategoryId"].ToString()!="")
					{
						model.CategoryId=int.Parse(dt.Rows[n]["CategoryId"].ToString());
					}
					if(dt.Rows[n]["Clicks"].ToString()!="")
					{
						model.Clicks=int.Parse(dt.Rows[n]["Clicks"].ToString());
					}
					modelList.Add(model);
				}
			}
			return modelList;
		}