public virtual void loadByConfig(SdNode c) { DdNode config = (DdNode)c; if (doFilter(c.title)) { return; } BookSearchModel b = new BookSearchModel(); DdNode cfg = config.s().search; b._dtype = cfg.dtype(); b.btype = cfg.btype(); b.name = c.title; b.url = c.url; b.logo = c.logo; b.updateTime = ""; b.newSection = ""; b.author = ""; b.status = ""; b.source = config.source.title; doAddItem(b); }
public async Task <IActionResult> FindByName([FromForm] BookSearchModel model) { try { if (this.ValidRoleForAction(_context, _auth, new string[] { "Student", "Teacher", "Editor", "Admin" })) { List <Book> foundx = await _context.GetAllBooks(); var found = foundx.Where(x => x.Name.ToLower().Contains(model.Name.ToLower())).ToList(); List <BookViewModel> result = found.Select(x => new BookViewModel(x)).ToList(); if (result.Count > 0) { return(Ok(result)); } else { return(NotFound("No book was found")); } } return(Forbid()); } catch (Exception ex) { var arguments = this.GetBaseData(_context, _auth); _logger.LogException(ex, arguments.Email, arguments.Path); return(BadRequest($"{ex.GetType().Name} was thrown.")); } }
/// <summary> /// Indexes the specified model. /// </summary> /// <param name="model">The model.</param> /// <param name="command">The command.</param> /// <returns></returns> public ActionResult Index(BookSearchModel model, PagingFilteringModel command) { PrepareBookModel(model); var request = new BookRequest() { Name = model.Name, Begin = model.Begin, DegreeId = model.DegreeId, End = model.End, GradeId = model.GradeId, Isbn = model.Isbn, PublisherId = model.PublisherId, SubjectId = model.SubjectId, TermId = model.TermId, Year = model.Year, PageIndex = command.PageIndex, PageSize = 10 }; var pageData = _bookService.GetBookPage(request); model.BookList = pageData; model.PagingFilteringModel.LoadPagedList(pageData); return(View(model)); }
public IEnumerable <Book> GetBook(BookSearchModel searchModel) { var result = books.AsQueryable(); if (searchModel != null) { if (!string.IsNullOrEmpty(searchModel.ISBN)) { result = result.Where(b => b.ISBN == searchModel.ISBN); } ; if (!string.IsNullOrEmpty(searchModel.Naslov)) { result = result.Where(b => b.Naslov == searchModel.Naslov); } if (!string.IsNullOrEmpty(searchModel.Opis)) { result = result.Where(b => b.Opis == searchModel.Opis); } if (!string.IsNullOrEmpty(searchModel.Oznaka)) { result = result.Where(b => b.Oznaka == searchModel.Oznaka); } if (!string.IsNullOrEmpty(searchModel.Izdajatelj)) { result = result.Where(b => b.Izdajatelj == searchModel.Izdajatelj); } } ; return(result); }
public SearchModel Result(string searchKey) { SearchModel model = new SearchModel(); List <AuthorSearchModel> authors = new List <AuthorSearchModel>(); List <BookSearchModel> books = new List <BookSearchModel>(); List <PublisherModel> publishers = new List <PublisherModel>(); List <CategoryTagAssigment> entity = _categoryTagAssignment.Search(searchKey); foreach (var item in entity) { AuthorSearchModel author = new AuthorSearchModel(); BookSearchModel book = new BookSearchModel(); PublisherModel publisher = new PublisherModel(); author.Id = item.AuthorId; author.Name = item.AuthorName + " " + item.AuthorSurname; book.Id = item.BookId; book.Name = item.BookName; publisher.Id = item.PublisherId; publisher.Name = item.PublisherName; authors.Add(author); books.Add(book); publishers.Add(publisher); } model.Authors = authors.GroupBy(x => x.Id).Select(x => x.First()).ToList(); model.Books = books.GroupBy(x => x.Id).Select(x => x.First()).ToList(); model.Publishers = publishers.GroupBy(x => x.Name).Select(x => x.First()).ToList(); return(model); }
private List <BookSearchModel> SearchBookContent(string searchWords) { List <BookSearchModel> bookSearchModelList = new List <BookSearchModel>(); //1.对搜索条件进行分词 Analyzer analyzer = new PanGuAnalyzer(); TokenStream tokenStream = analyzer.TokenStream("", new StringReader(searchWords)); Lucene.Net.Analysis.Token token = null; string indexPath = @"D:\lucenedir"; //string kw = "面向对象";//对用户输入的搜索条件进行拆分。 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 kw.Split(' '))//先用空格,让用户去分词,空格分隔的就是词“计算机 专业” //{ // query.Add(new Term("body", word)); //} //query.Add(new Term("body","语言"));--可以添加查询条件,两者是add关系.顺序没有关系. // query.Add(new Term("body", "大学生")); while ((token = tokenStream.Next()) != null) { query.Add(new Term("body", token.TermText())); } // query.Add(new Term("body", kw));//body中含有kw的文章 query.SetSlop(100);//多个查询条件的词之间的最大距离.在文章中相隔太远 也就无意义.(例如 “大学生”这个查询条件和"简历"这个查询条件之间如果间隔的词太多也就没有意义了。) //TopScoreDocCollector是盛放查询结果的容器 TopScoreDocCollector collector = TopScoreDocCollector.create(1000, true); searcher.Search(query, null, collector); //根据query查询条件进行查询,查询结果放入collector容器 ScoreDoc[] docs = collector.TopDocs(0, collector.GetTotalHits()).scoreDocs; //得到所有查询结果中的文档,GetTotalHits():表示总条数 TopDocs(300, 20);//表示得到300(从300开始),到320(结束)的文档内容. //可以用来实现分页功能 for (int i = 0; i < docs.Length; i++) { // //搜索ScoreDoc[]只能获得文档的id,这样不会把查询结果的Document一次性加载到内存中。降低了内存压力,需要获得文档的详细内容的时候通过searcher.Doc来根据文档id来获得文档的详细内容对象Document. int docId = docs[i].doc; //得到查询结果文档的id(Lucene内部分配的id) Document doc = searcher.Doc(docId); //找到文档id对应的文档详细信息 BookSearchModel searchModel = new BookSearchModel(); searchModel.Id = int.Parse(doc.Get("ID")); searchModel.Title = doc.Get("title"); searchModel.ContenDescription = SearchWordHighlight.CreateHightLight(searchWords, doc.Get("body")); //this.listBox1.Items.Add(doc.Get("number") + "\n");// 取出放进字段的值 //this.listBox1.Items.Add(doc.Get("body") + "\n"); //this.listBox1.Items.Add("-----------------------\n"); bookSearchModelList.Add(searchModel); } //将搜索的此插入词库之中 SearchDetails entity = new SearchDetails() { Id = Guid.NewGuid(), KeyWords = searchWords, SearchDateTime = DateTime.Now }; SearchDetailsService.AddEntity(entity); return(bookSearchModelList); }
public async Task <IActionResult> Search(BookSearchModel searchModel) { if (!string.IsNullOrWhiteSpace(searchModel.Author)) { searchModel.Author = searchModel.Author.Trim(); } if (!string.IsNullOrWhiteSpace(searchModel.Title)) { searchModel.Title = searchModel.Title.Trim(); } if (SessionValueExists("book-query")) { searchModel.Title = GetStringFromSession("book-query"); } if (SessionValueExists("wish")) { searchModel.Title = GetFromSession <string>("wish"); } if (Request.Headers["Referrer"].Contains("/Book/Search") && string.IsNullOrWhiteSpace(searchModel.Author) && string.IsNullOrWhiteSpace(searchModel.Title)) { ShowStatusMessage(MessageTypeEnum.error, "Please enter search terms.", "Search Error"); return(View(searchModel)); } if (!string.IsNullOrWhiteSpace(searchModel.Author) || !string.IsNullOrWhiteSpace(searchModel.Title)) { try { searchModel.Volumes = _googleBookService.Search(searchModel.Author, searchModel.Title); } catch (Exception e) { } } //TODO: add author to search if (!string.IsNullOrWhiteSpace(searchModel.Title)) { try { searchModel.ComicsVineResult = await _comicVineService.Search(searchModel.Title); } catch (Exception e) { } } ViewBag.Title = "Book Search"; return(View(searchModel)); }
public BookSearchModel PrepareBookSearchModel(BookSearchModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } //prepare page parameters model.SetGridPageSize(); return(model); }
public virtual IActionResult List(BookSearchModel searchModel) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCategories)) { return(AccessDeniedKendoGridJson()); } //prepare model var model = _bookModelFactory.PrepareBookListModel(searchModel); return(Json(model)); }
public async Task <IActionResult> SearchBookByName(BookSearchModel model) { if (ModelState.IsValid) { var result = await _dbContext.Books.Include(x => x.Image) .Include(x => x.Language) .Include(x => x.TagPosts).ThenInclude(t => t.Tag) .Include(x => x.Likes) .Where(x => x.Name.ToLower().Contains(model.Name.ToLower())) .Select(x => new BookViewModel(x)) .ToListAsync(); return(Json(result)); } return(Json("No books found...")); }
public virtual void loadByJson(SdNode c, params string[] jsons) { if (jsons == null || jsons.Length == 0) { return; } DdNode config = (DdNode)c; foreach (String json in jsons) //支持多个数据块加载 { ONode data = ONode.tryLoad(json); if (data.isArray) { foreach (ONode n in data) { String name = n.get("name").getString(); if (doFilter(name)) { continue; } BookSearchModel b = new BookSearchModel(); b.name = name; b.url = n.get("url").getString(); b.logo = n.get("logo").getString(); b.updateTime = n.get("updateTime").getString(); b.newSection = n.get("newSection").getString(); b.author = n.get("author").getString(); b.status = n.get("status").getString(); b.source = config.source.title; b.btag = n.get("btag").getString(); DdNode cfg = config.s().book(b.url); b._dtype = cfg.dtype(); b.btype = cfg.btype(); doAddItem(b); } } } }
public BookListModel PrepareBookListModel(BookSearchModel searchModel) { var books = _bookervice.GetAllBooks(searchModel.SearchBookName); var model = new BookListModel { Data = books.Select(book => { //fill in model values from the entity var bookModel = book.ToModel <BookModel>(); return(bookModel); }), Total = books.TotalCount }; return(model); }
public virtual void loadByJson(SdNode c, params string[] jsons) { if (jsons == null || jsons.Length == 0) return; DdNode config = (DdNode)c; foreach (String json in jsons) { //支持多个数据块加载 ONode data = ONode.tryLoad(json); if (data.isArray) { foreach (ONode n in data) { String name = n.get("name").getString(); if (doFilter(name)) { continue; } BookSearchModel b = new BookSearchModel(); b.name = name; b.url = n.get("url").getString(); b.logo = n.get("logo").getString(); b.updateTime = n.get("updateTime").getString(); b.newSection = n.get("newSection").getString(); b.author = n.get("author").getString(); b.status = n.get("status").getString(); b.source = config.source.title; b.btag = n.get("btag").getString(); DdNode cfg = config.s().book(b.url); b._dtype = cfg.dtype(); b.btype = cfg.btype(); doAddItem(b); } } } }
protected abstract void doAddItem(BookSearchModel item);
public BookModel PrepareBookModel(BookSearchModel model, bool excludeProperties = false) { throw new NotImplementedException(); }
// GET: Books public ActionResult Index() { string searchedTitle = Request.QueryString["Title"]; string searchedAuthor = Request.QueryString["Author"]; string searchedDateFrom = Request.QueryString["DateFrom"]; string searchedDateTo = Request.QueryString["DateTo"]; string searchedGenre = Request.QueryString["Genre"]; string searchedDescription = Request.QueryString["Description"]; // Filter the received Author from QueryString. If it is a starting point and/or nothing is selected, we pass empty value if (String.IsNullOrEmpty(searchedAuthor) || searchedAuthor.Contains("Selected")) { searchedAuthor = ""; } // if by hidden field multiple values are accumulated (because we may have or may not have clicked on any option) we cut only last value from it else if (searchedAuthor.Contains(',')) { searchedAuthor = searchedAuthor.Substring(searchedAuthor.LastIndexOf(',') + 1); } // Same goes to Genre Dropdown if (String.IsNullOrEmpty(searchedGenre) || searchedGenre.Contains("Selected")) { searchedGenre = ""; } else if (searchedGenre.Contains(',')) { searchedGenre = searchedGenre.Substring(searchedGenre.LastIndexOf(',') + 1); } // Populate Books from Database myBookList = new List <BookViewModel>(); foreach (var item in db.Books) { UpdateBorrowedBookQuantity(item.Id); } myBookList = GenerateBookList(); // Filter Authors and Genres with searched Data var authors = myBookList.SelectMany(x => x.Authors).Where(x => x.Name.Contains(searchedAuthor)); var genres = myBookList.SelectMany(x => x.Genres).Where(x => x.GenreName.Contains(searchedGenre)); // Filter myBookList (BookViewModel Object) based on input data from Search boxes myBookList = myBookList.Where(x => (!string.IsNullOrWhiteSpace(searchedTitle) ? x.Title.Contains(searchedTitle.ToLower()) : x.Title.Contains("")) && (!string.IsNullOrWhiteSpace(searchedAuthor) ? x.Authors.Intersect(authors).Any() : x.Authors.Any()) && (!string.IsNullOrWhiteSpace(searchedDateFrom) ? x.Year >= int.Parse(searchedDateFrom) : x.Year >= db.Books.Min(y => y.Year)) && (!string.IsNullOrWhiteSpace(searchedDateTo) ? x.Year <= int.Parse(searchedDateTo) : x.Year <= db.Books.Max(y => y.Year)) && (!string.IsNullOrWhiteSpace(searchedGenre) ? x.Genres.Intersect(genres).Any() : x.Genres.Any()) && (!string.IsNullOrWhiteSpace(searchedDescription) ? x.Description.Contains(searchedDescription.ToLower()) : x.Description.Contains("")) ).ToList(); // Check how many per cent of Total Quantity is actually available for each book and assign colours to rows respectively foreach (var item in myBookList) { var availability = item.TotalQuantity > 0 ? ((Convert.ToDouble(item.AvailableQuantity) / Convert.ToDouble(item.TotalQuantity))) : 0; if (availability == 0) { // Those Books of which none is available or none is in the Library at all item.Availability = 0; } else if (availability <= 0.25) { // Those books of which maximum 25% is available to Borrow item.Availability = 1; } else if (availability <= 0.75) { // Those books of which more than 25% but equal or less than 75% is available to Borrow item.Availability = 2; } else { // Those books of which more than 75% is available to Borrow item.Availability = 3; } } // Generate BookSearchModel object to contain recently searched data and those Books that correspond the Search results var myBookSearchModel = new BookSearchModel() { Id = 1, Title = !string.IsNullOrWhiteSpace(searchedTitle) ? searchedTitle : "", Authors = db.Authors.OrderBy(x => x.Name).ToList(), Author = !string.IsNullOrWhiteSpace(searchedAuthor) ? searchedAuthor : "", DateFrom = !string.IsNullOrWhiteSpace(searchedDateFrom) ? int.Parse(searchedDateFrom) : default(int?), DateTo = !string.IsNullOrWhiteSpace(searchedDateTo) ? int.Parse(searchedDateTo) : default(int?), Genres = db.Genres.OrderBy(x => x.Genre_Name).ToList(), Genre = !string.IsNullOrWhiteSpace(searchedGenre) ? searchedGenre : "", Description = !string.IsNullOrWhiteSpace(searchedDescription) ? searchedDescription : "", Books = myBookList }; return(View(myBookSearchModel)); }
public IEnumerable <Book> GetBook(BookSearchModel searchModel) { // Initialize new query from DB var result = from b in db.Books select b; if (searchModel != null) { if (!string.IsNullOrEmpty(searchModel.ISBN)) { var newquery = from b in db.Books where b.ISBN.StartsWith(searchModel.ISBN) select b; // Either find items and set them as result // Or find none and empty the result query result = newquery; } if (!string.IsNullOrEmpty(searchModel.Naslov)) { var newquery = from b in db.Books where b.Naslov.StartsWith(searchModel.Naslov) select b; // If there are any matches, append them uniquely to result query if (newquery != null) { result = result.Union(newquery); } } if (!string.IsNullOrEmpty(searchModel.Opis)) { var newquery = from b in db.Books where b.Opis.StartsWith(searchModel.Opis) select b; if (newquery != null) { result = result.Union(newquery); } } if (!string.IsNullOrEmpty(searchModel.Avtor)) { var newquery = from b in db.Books where b.Avtor.StartsWith(searchModel.Avtor) select b; if (newquery != null) { result = result.Union(newquery); } } if (!string.IsNullOrEmpty(searchModel.Oznaka)) { var newquery = from b in db.Books where b.Oznaka.StartsWith(searchModel.Oznaka) select b; if (newquery != null) { result = result.Union(newquery); } } if (!string.IsNullOrEmpty(searchModel.Izdajatelj)) { var newquery = from b in db.Books where b.Izdajatelj.StartsWith(searchModel.Izdajatelj) select b; if (newquery != null) { result = result.Union(newquery); } } if (!string.IsNullOrEmpty(searchModel.LetoIzdaje)) { try { var searchInt = Int32.Parse(searchModel.LetoIzdaje); var newquery = from b in db.Books where b.LetoIzdaje == searchInt select b; if (newquery != null) { result = result.Union(newquery); } } catch (FormatException) { Console.WriteLine("Wrong form of string to int"); } } } ; var orderedResult = from b in result orderby b.Naslov select b; return(orderedResult); }