Beispiel #1
0
 public IList <SearchResult> EFShowSearchResult(string searchstring)
 {
     using (var db = new Sova())
     {
         //var conn = (MySqlConnection)db.Database.GetDbConnection();
         //conn.Open();
         //var cmd = new MySqlCommand("call weightingsearch(@searchstring)", conn);
         //cmd.Parameters.Add("@searchstring", DbType.String).Value = searchstring;
         //var reader = cmd.ExecuteReader();
         //var result = new List<SearchResult>();
         //while(reader.HasRows && reader.Read())
         //{
         //    result.Add(new SearchResult
         //    {
         //        id = reader.GetInt32(0),
         //        Title = reader.GetString(2),
         //        body = reader.GetString(3)
         //    });
         //}
         //return result;
         var result = db.Set <SearchResult>()
                      .FromSql("call weightingsearch('" + searchstring + "')");
         foreach (var data in result)
         {
             Console.WriteLine($"{data.id} {data.title} {data.body}");
         }
         return(result.ToList());
     }
 }
Beispiel #2
0
 public IList <Cloud> EFShowWordCloud(string word)
 {
     using (var db = new Sova())
     {
         var result = db.Set <Cloud>()
                      .FromSql("call resultwordweightranking('" + word + "')");
         foreach (var data in result)
         {
             Console.WriteLine($"{data.word} {data.wordrank}");
         }
         return(result
                .ToList());
     }
 }
Beispiel #3
0
 public IList <PostDetail> EFShowPostDetail(int postid)
 {
     using (var db = new Sova())
     {
         var queryString = "call selectpostdetails(" + postid.ToString() + ");";
         Console.WriteLine(queryString);
         var result = db.Set <PostDetail>()
                      .FromSql(queryString);
         foreach (var data in result)
         {
             Console.WriteLine($"{data.id} {data.title} {data.body}");
         }
         return(result
                .ToList());
     }
 }
Beispiel #4
0
 public IList <SearchResult> EFShowSearchResult(string searchstring, int page, int pagesize)
 {
     using (var db = new Sova())
     {
         if (searchstring != null)
         {
             var conn = (MySqlConnection)db.Database.GetDbConnection();
             conn.Open();
             var cmd = new MySqlCommand("insert into `history`(`searchstring`) VALUES (@searchstring);", conn);
             cmd.Parameters.Add("@searchstring", DbType.String).Value = searchstring;
             cmd.ExecuteNonQuery();
         }
         //var reader = cmd.ExecuteReader();
         //var result = new List<SearchResult>();
         //while(reader.HasRows && reader.Read())
         //{
         //    result.Add(new SearchResult
         //    {
         //        id = reader.GetInt32(0),
         //        Title = reader.GetString(2),
         //        body = reader.GetString(3)
         //    });
         //}
         //return result;
         var result = db.Set <SearchResult>()
                      .FromSql("call weightingsearch('" + searchstring + "')");
         foreach (var data in result)
         {
             Console.WriteLine($"{data.id} {data.title} {data.body}");
         }
         return(result
                .Skip(page * pagesize)
                .Take(pagesize)
                .ToList());
     }
 }