public LibrarySearchResultRecord Try2Hit(string keyword, int page)
        {
            var cacheKeyword = LibrarySearchResultRecord.GenCacheKeyword(keyword, page);
            var result       = try2Hit(cacheKeyword);

            return(result);
        }
Beispiel #2
0
 public void Push(LibrarySearchResultRecord result)
 {
     var cacheKeyword = LibrarySearchResultRecord.GenCacheKeyword(result.Keyword, result.CurrentPage);
     if(try2Hit(cacheKeyword) == null)
     {
         mQueue.Enqueue(result);
     }
 }
        public void Push(LibrarySearchResultRecord result)
        {
            var cacheKeyword = LibrarySearchResultRecord.GenCacheKeyword(result.Keyword, result.CurrentPage);

            if (try2Hit(cacheKeyword) == null)
            {
                mQueue.Enqueue(result);
            }
        }
Beispiel #4
0
        private LibrarySearchResponse(HttpRequestBase request, LibrarySearchResultRecord result)
            : base(result.User)
        {
            var keyword   = result.Keyword;
            var books     = result.Books;
            var converter = new UrlToAbsConverter(request);

            this.Articles = new List <Article>()
            {
                new Article
                {
                    Title       = new StringXmlCDataSection(String.Format("搜索 {0} 的结果: {1}/{2}页", keyword, result.CurrentPage, result.PageCount)),
                    Description = new StringXmlCDataSection(keyword),
                    PicUrl      = new StringXmlCDataSection(converter.Convert("/Content/images/lib.jpg")),
                    Url         = new StringXmlCDataSection(converter.Convert("/Home/About")),
                }
            };
            if (books != null && books.Count > 0)
            {
                var bookArticles = from book in books
                                   select new Article
                {
                    Title = new StringXmlCDataSection(String.Format("[{0} 馆藏:{1}/{2}] {3} ({4})",
                                                                    book.Index, book.Available, book.Total, book.Title, book.Author)),
                    Description = new StringXmlCDataSection(keyword),
                    PicUrl      = book.Available > 0 ?
                                  new StringXmlCDataSection(converter.Convert("/Content/Images/green_circle.png")) :
                                  new StringXmlCDataSection(converter.Convert("/Content/Images/red_circle.png")),
                    Url = new StringXmlCDataSection(getDetailUrl(converter, book.Url))
                };
                this.Articles.AddRange(bookArticles);
                this.Articles.Add(new Article
                {
                    Title  = new StringXmlCDataSection(CMD),
                    PicUrl = new StringXmlCDataSection(converter.Convert("/Content/Images/frog.jpg")),
                    Url    = new StringXmlCDataSection(converter.Convert("/Home/About"))
                });
            }
            else
            {
                this.Articles.Add(new Article
                {
                    Title  = new StringXmlCDataSection("没有匹配项"),
                    PicUrl = new StringXmlCDataSection(converter.Convert("/Content/Images/frog.jpg")),
                    Url    = new StringXmlCDataSection(converter.Convert("/Home/About"))
                });
            }
        }
 private LibrarySearchResponse(HttpRequestBase request, LibrarySearchResultRecord result)
     : base(result.User)
 {
     var keyword = result.Keyword;
     var books = result.Books;
     var converter = new UrlToAbsConverter(request);
     this.Articles = new List<Article>()
         {
             new Article
             {
                 Title = new StringXmlCDataSection(String.Format("搜索 {0} 的结果: {1}/{2}页", keyword, result.CurrentPage, result.PageCount)),
                 Description = new StringXmlCDataSection(keyword),
                 PicUrl = new StringXmlCDataSection(converter.Convert("/Content/images/lib.jpg")),
                 Url = new StringXmlCDataSection(converter.Convert("/Home/About")),
             }
         };
     if (books != null && books.Count > 0)
     {
         var bookArticles = from book in books
                            select new Article
                            {
                                Title = new StringXmlCDataSection(String.Format("[{0} 馆藏:{1}/{2}] {3} ({4})",
                                    book.Index, book.Available, book.Total, book.Title, book.Author)),
                                Description = new StringXmlCDataSection(keyword),
                                PicUrl = book.Available > 0 ?
                                    new StringXmlCDataSection(converter.Convert("/Content/Images/green_circle.png")) :
                                    new StringXmlCDataSection(converter.Convert("/Content/Images/red_circle.png")),
                                Url = new StringXmlCDataSection(getDetailUrl(converter, book.Url))
                            };
         this.Articles.AddRange(bookArticles);
         this.Articles.Add(new Article
         {
             Title = new StringXmlCDataSection(CMD),
             PicUrl = new StringXmlCDataSection(converter.Convert("/Content/Images/frog.jpg")),
             Url = new StringXmlCDataSection(converter.Convert("/Home/About"))
         });
     }
     else
     {
         this.Articles.Add(new Article
         {
             Title = new StringXmlCDataSection("没有匹配项"),
             PicUrl = new StringXmlCDataSection(converter.Convert("/Content/Images/frog.jpg")),
             Url = new StringXmlCDataSection(converter.Convert("/Home/About"))
         });
     }
 }
Beispiel #6
0
        public LibrarySearchResultRecord SearchBooksFor(HttpSessionStateBase session, LibrarySearchOption option, out object error)
        {
            error = null;
            var user    = option.User;
            var keyword = option.Keyword;
            var page    = option.Page;
            LibrarySearchResultRecord cached;

            if ((cached = mResultCache.Try2Hit(keyword, page)) != null)
            {
                ApplicationLogger.GetLogger().Info("(" + session.SessionID + ")" + keyword + " " + page + " hited");
                option.PageCount = cached.PageCount;
                return(cached);
            }
            option = option == null ? DEFAULT : option;
            LibrarySearchResult result;

            if (Search(option, out result))
            {
                cached = new LibrarySearchResultRecord
                {
                    Keyword     = keyword,
                    User        = user,
                    Books       = result.Books,
                    PageCount   = result.PageCount,
                    CurrentPage = option.Page
                };
                //记录查询结果的总页数
                option.PageCount = result.PageCount;
                mResultCache.Push(cached);
                ApplicationLogger.GetLogger().Info("(" + session.SessionID + ")" +
                                                   "push cache: " + keyword + " " + page + " current cache count: " + mResultCache.Count);
                return(cached);
            }
            else
            {
                return(null);
            }
        }
 public static LibrarySearchResponse Create(HttpRequestBase request, LibrarySearchResultRecord result)
 {
     return new LibrarySearchResponse(request, result);
 }
Beispiel #8
0
 public static LibrarySearchResponse Create(HttpRequestBase request, LibrarySearchResultRecord result)
 {
     return(new LibrarySearchResponse(request, result));
 }
Beispiel #9
0
 public LibrarySearchResultRecord SearchBooksFor(HttpSessionStateBase session, LibrarySearchOption option, out object error)
 {
     error = null;
     var user = option.User;
     var keyword = option.Keyword;
     var page = option.Page;
     LibrarySearchResultRecord cached;
     if ((cached = mResultCache.Try2Hit(keyword, page)) != null)
     {
         ApplicationLogger.GetLogger().Info("(" + session.SessionID + ")" + keyword + " " + page + " hited");
         option.PageCount = cached.PageCount;
         return cached;
     }
     option = option == null ? DEFAULT : option;
     LibrarySearchResult result;
     if (Search(option, out result))
     {
         cached = new LibrarySearchResultRecord
                     {
                         Keyword = keyword,
                         User = user,
                         Books = result.Books,
                         PageCount = result.PageCount,
                         CurrentPage = option.Page
                     };
         //记录查询结果的总页数
         option.PageCount = result.PageCount;
         mResultCache.Push(cached);
         ApplicationLogger.GetLogger().Info("(" + session.SessionID + ")" +
             "push cache: " + keyword + " " + page + " current cache count: " + mResultCache.Count);
         return cached;
     }
     else
     {
         return null;
     }
 }