public IActionResult Update(int id, Posts model, string Solr) { if (ModelState.IsValid) { var b = _db.Posts.Where(b => b.PostID == id).FirstOrDefault(); b.PostContent = model.PostContent; b.PostExcerpt = model.PostExcerpt; b.PostTitle = model.PostTitle; b.PostAuthor = model.PostAuthor; b.PostLocation = model.PostLocation; b.CategoryID = model.CategoryID; _db.Update(b); _db.SaveChanges(); if (Solr == "Yes") { var s = new PersonalWebsiteMVC.Models.SolrModel(); s.ID = model.PostID.ToString(); s.Title = model.PostTitle; s.Url = "http://www.douglasmcgregor.co.uk/Blog?q=" + model.PostID; s.Body = model.PostContent; _solr.Add(s); _solr.Commit(); } if (Solr == "No") { SolrQueryByField results = new SolrQueryByField("ID", model.PostID.ToString()); _solr.Delete(results.FieldValue); _solr.Commit(); } return(RedirectToAction("Index")); } return(View(model)); }
public async Task <IActionResult> Index() { Random generator = new Random(); int code = generator.Next(100000, 1000000); TempData["verifycode"] = code; if (ModelState.IsValid) { var email = registerVM.Email; try { #region register user _user = _userCollection.Find(e => e.Email == email).FirstOrDefault(); if (_user != null) { ModelState.AddModelError(string.Empty, "Email already exists"); return(View()); } _user = new Users() { FirstName = registerVM.FirstName, LastName = registerVM.LastName, Email = registerVM.Email, Password = AppUtility.Encrypt(registerVM.Password), RoleId = _userRoleCollection.Find(e => e.Role == AppUtility.EarnerRole).FirstOrDefault().RoleId.ToString(), CreatedDate = DateTime.Now, CreatedBy = AppUtility.DefaultCreatedBy, IsUserVerified = false }; _userCollection.InsertOne(_user); SolrUsersModel su = new SolrUsersModel(_user); _solr.Add(su); _solr.Commit(); #endregion } catch (Exception e) { ErrorMessage = "Please try again later."; _logger.LogError("RegisterError", e); return(RedirectToAction(nameof(Index))); } await _emailSender.SendEmailAsync(_user.Email, "Confirm your email", $"Your verification code is {code}. Please enter to confirm your email"); TempData["email"] = _user.Email; return(LocalRedirect("/Identity/Account/Verifycode")); } // If we got this far, something failed, redisplay form return(RedirectToAction(nameof(Index))); }
public IActionResult Update(PersonalWebsiteMVC.Models.SolrModel model) { var s = new PersonalWebsiteMVC.Models.SolrModel(); s.ID = model.ID; s.Title = model.Title; s.Url = model.Url; s.Body = model.Body; solr.Add(s); solr.Commit(); return(RedirectToAction("Index")); }
public void Add_then_query() { const string name = "Samsuñg SpinPoint P120 SP2514N - hárd drívè - 250 GB - ÁTÀ-133"; var guid = new Guid("{78D734ED-12F8-44E0-8AA3-8CA3F353998D}"); var p = new Product { Id = "SP2514N", Guid = guid, Name = name, // testing UTF Manufacturer = "Samsung Electronics Co. Ltd.", Categories = new[] { "electronics", "hard drive", }, Features = new[] { "7200RPM, 8MB cache, IDE Ultra ATA-133", "NoiseGuard, SilentSeek technology, Fluid Dynamic Bearing (FDB) motor", "áéíóúñç & two", // testing UTF @"ÚóÁ⌠╒""ĥÛē…<>ܐóジャストシステムは、日本で初めてユニコードベースのワードプロセ ッサーを開発しました。このことにより、10年以上も前から、日本のコンピューターユーザーはユニコード、特に日中韓の統合漢 字の恩恵を享受してきました。ジャストシステムは現在、”xfy”というJava環境で稼働する 先進的なXML関連製品の世界市場への展開を積極的に推進していますが、ユニコードを基盤としているために、”xfy”は初めから国際化されているのです。ジャストシステムは、ユニコードの普遍的な思想とアーキテクチャに 感謝するとともに、その第5版の刊行を心から歓迎します", @"control" + (char)0x07 + (char)0x01 + (char)0x0E + (char)0x1F + (char)0xFFFE, // testing control chars }, Prices = new Dictionary <string, decimal> { { "regular", 150m }, { "afterrebate", 100m }, }, Price = 92, PriceMoney = new Money(92m, "USD"), Popularity = 6, InStock = true, DynCategories = new Dictionary <string, ICollection <string> > { { "t", new[] { "something" } }, } }; solr.Delete(SolrQuery.All); solr.AddWithBoost(p, 2.2); solr.Commit(); solr.Query(new SolrQueryByField("name", @"3;Furniture")); var products = solr.Query(new SolrQueryByRange <decimal>("price", 10m, 100m).Boost(2)); Assert.AreEqual(1, products.Count); Assert.AreEqual(name, products[0].Name); Assert.AreEqual("SP2514N", products[0].Id); Assert.AreEqual(guid, products[0].Guid); Assert.AreEqual(92m, products[0].Price); Assert.IsNotNull(products[0].Prices); Assert.AreEqual(2, products[0].Prices.Count); Assert.AreEqual(150m, products[0].Prices["regular"]); Assert.AreEqual(100m, products[0].Prices["afterrebate"]); Assert.IsNotNull(products.Header); }
public Boolean Insert(Quote theQuote) { try { _ctx.Add(theQuote); _ctx.Commit(); return(true); } catch { return(false); } }
public void DeleteFromPublishedIndex(object id) { ISolrOperations <CmsSearchResultItemPublished> instancePublished = ServiceLocator.Current.GetInstance <ISolrOperations <CmsSearchResultItemPublished> >(); instancePublished.Delete(id.ToString()); instancePublished.Commit(); }
public void DeleteMediaFromIndex(string mediaId) { ISolrOperations <CmsSearchResultItem> instance = ServiceLocator.Current.GetInstance <ISolrOperations <CmsSearchResultItem> >(); instance.Delete(mediaId.StartsWith("media") ? mediaId.ToString((IFormatProvider)CultureInfo.InvariantCulture) : "media" + mediaId.ToString((IFormatProvider)CultureInfo.InvariantCulture)); instance.Commit(); }
void Provider_OnUpdateItem(object sender, EventArgs e) { Assert.ArgumentNotNull(sender, "sender"); Assert.ArgumentNotNull(e, "e"); Database database = SitecoreEventArgs.GetObject(e, 0) as Database; if ((database != null) && (database.Name == this.m_database.Name)) { ID iD = SitecoreEventArgs.GetID(e, 1); Assert.IsNotNull(iD, "ID is not passed to RemoveItem handler"); solr.Delete(IdHelper.NormalizeGuid(iD.ToString(), false)); // solr.Add(new SOLRItem()); solr.Commit(); solr.Optimize(); } }
public void Write(IEnumerable <IRow> rows) { var fullCount = 0; var batchCount = (uint)0; foreach (var part in rows.Partition(_context.Entity.InsertSize)) { var docs = new List <Dictionary <string, object> >(); foreach (var row in part) { batchCount++; fullCount++; docs.Add(_fields.ToDictionary(field => field.Alias.ToLower(), field => row[field])); } var response = _solr.AddRange(docs); _context.Increment(@by: batchCount); if (response.Status == 0) { _context.Debug(() => $"{batchCount} to output"); } else { _context.Error("ah!"); } batchCount = 0; } _solr.Commit(); if (fullCount > 0) { _context.Info($"{fullCount} to output"); } }
public void Setup() { solr = ServiceLocator.Current.GetInstance <ISolrOperations <Product> >(); solr.Delete(SolrQuery.All); solr.Commit(); var connection = ServiceLocator.Current.GetInstance <ISolrConnection>(); var files = Directory.GetFiles(DirectoryUtility.GetDirectoryXmlFile(), "*.xml"); foreach (var file in files) { connection.Post("/update", File.ReadAllText(file, Encoding.UTF8)); } solr.Commit(); }
public override void ProcessMessage(BasicDeliverEventArgs message) { try { iCount++; var pt = Newtonsoft.Json.JsonConvert.DeserializeObject <HistoryProductSorl>( Encoding.UTF8.GetString(message.Body)); if (pt != null) { _lstCacheList.Add(pt); if (_lstCacheList.Count > 2000) { _solr.AddRange(_lstCacheList); _lstCacheList.Clear(); _solr.Commit(); _log.Info("Added 1000 item"); } } } catch (Exception ex) { _log.Error(ex + Encoding.UTF8.GetString(message.Body)); } this.GetChannel().BasicAck(message.DeliveryTag, true); }
public void AutoTrackRepos(GitHubUser user) { ISolrOperations <CodeDoc> solr = ServiceLocator.Current.GetInstance <ISolrOperations <CodeDoc> >(); var repos = user.GitHubClient.Repository.GetAllPublic().Result; foreach (var repo in repos) { var commits = user.GitHubClient.Repository.Commit.GetAll(repo.Owner.Login, repo.Name).Result; foreach (var commit in commits) { if (commit.Author != null && commit.Author.Login != user.GitHubClient.User.Current().Result.Login) { continue; } var docsToAdd = GetDocumentsFromCommit(user, repo, commit); foreach (var doc in docsToAdd) { solr.Add(doc); } } Console.WriteLine("Finished tracking repository {0} for {1} to Solr", repo.Name, user.UUID); solr.Commit(); } }
public void InsertHashDataForTrack(IEnumerable <HashedFingerprint> hashes, IModelReference trackReference) { var dtos = hashes.Select(hash => GetSubFingerprintDto(trackReference, hash)) .ToList(); solr.AddRange(dtos); solr.Commit(); }
public ActionResult AddProduct() { var product = new Product { Id = new Random().Next().ToString(), InStock = true, Manufacturer = "Apple", Price = 50m, Weight = 20, Categories = new[] { "Computers", "Electronics" } }; solr.Add(product); solr.Commit(); return(Json(new { product }, JsonRequestBehavior.AllowGet)); }
private static void DeleteIndex <T>(ISolrOperations <T> solr) { Console.WriteLine("Clearing Index"); var solrQueryResults = solr.Query(new SolrQuery("*")); solr.Delete(solrQueryResults); solr.Commit(); }
/// <summary> /// removes a given user's repo from a channel /// </summary> /// <param name="user"></param> /// <param name="channel"></param> /// <param name="repository"></param> public void UntrackRepository(GitHubUser user, String repository) { ISolrOperations <CodeDoc> solr = ServiceLocator.Current.GetInstance <ISolrOperations <CodeDoc> >(); solr.Delete(new SolrQuery("channel:" + user.ChannelID) && new SolrQuery("repo:" + repository) && new SolrQuery("committer_name:" + user.UserID)); solr.Commit(); }
public void DeleteIndex() { try { Log.Info("Deletes intire index for reindexing"); SolrQuery sq = new SolrQuery("*:*"); _solr.Delete(sq); _solr.Commit(); } catch (SolrNet.Exceptions.SolrConnectionException) { Log.Error("Connection to solr failed"); } catch (Exception ex) { Log.Error("Error:" + ex.Message); } }
public virtual void Delete(TId id) { if (Equals(id, default(TId))) { return; } _solrOperations.Delete(id.ToString()); _solrOperations.Commit(); }
private int DeleteSubFingerprintsForTrack(IModelReference trackReference) { string trackId = SolrModelReference.GetId(trackReference); string readAll = string.Format("trackId:{0}", trackId); var results = solrForSubfingerprintsCore.Query(new SolrQuery(readAll)); var ids = results.Select(dto => dto.SubFingerprintId).ToList(); solrForSubfingerprintsCore.Delete(ids); solrForSubfingerprintsCore.Commit(); return(ids.Count); }
public async Task <IActionResult> Create(Users users) { if (ModelState.IsValid) { var claimsIdentity = (ClaimsIdentity)User.Identity; var claim = claimsIdentity.Claims.ToArray(); var loginUserEmail = claim[1].Value; var userName = claim[0].Value; var IsEmailExist = usersCollection.Find(e => e.Email == users.Email).ToList(); if (IsEmailExist.Count() > 0) { ModelState.AddModelError(string.Empty, "User with this email already exist"); CreateUser createUser = new CreateUser() { userRoles = userRoleCollection.Find(role => role.Role != AppUtility.IssuerRole).ToList() }; return(View(createUser)); } DateTime today = DateTime.Now; var password = AppUtility.Encrypt(users.Password); users.CreatedDate = today; users.CreatedBy = userName; users.Password = password; users.IsUserVerified = true; usersCollection.InsertOne(users); SolrUsersModel su = new SolrUsersModel(users); _solr.Add(su); _solr.Commit(); await _emailSender.SendEmailAsync(users.Email, "Congratulation, Now you can use DigiBadges", $"LoginId: {users.Email}<br/>Password: {users.Password}" ); return(RedirectToAction("Index")); } return(View()); }
public void AddQuery(Item item) { Startup.Init <SolrSitecoreItem>("http://localhost:8080/solr"); solr.Add(new SolrSitecoreItem() { Group = "", Name = item.Name, Url = item.Uri.ToString() }); solr.Commit(); }
public void ClearIndex() { ISolrOperations <CmsSearchResultItem> instance = ServiceLocator.Current.GetInstance <ISolrOperations <CmsSearchResultItem> >(); ISolrOperations <CmsSearchResultItemPublished> instancePublished = ServiceLocator.Current.GetInstance <ISolrOperations <CmsSearchResultItemPublished> >(); this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Info, "Clearing index", (Exception)null); instance.Delete((ISolrQuery) new SolrQuery("id:[* TO *]")); instance.Commit(); instancePublished.Delete((ISolrQuery) new SolrQuery("id:[* TO *]")); instancePublished.Commit(); }
public int Add(sys_menu entry) { using (LocalDB db = new LocalDB()) { StringBuilder sql = new StringBuilder(); sql.Append("INSERT INTO dbo.sys_menu \n"); sql.Append(" ( status , \n"); sql.Append(" pid , \n"); sql.Append(" title , \n"); sql.Append(" code , \n"); sql.Append(" menucode , \n"); sql.Append(" icon , \n"); sql.Append(" path , \n"); sql.Append(" menutype , \n"); sql.Append(" seq ,viewpath, \n"); sql.Append(" add_time \n"); sql.Append(" ) \n"); sql.Append("select @status , -- status - int \n"); sql.Append(" @pid , -- pid - int \n"); sql.Append(" @title , -- title - nvarchar(100) \n"); sql.Append(" @code , -- code - nvarchar(50) \n"); sql.Append(" @menucode , -- code - nvarchar(50) \n"); sql.Append(" @icon , -- icon - nvarchar(50) \n"); sql.Append(" @path , -- path - nvarchar(50) \n"); sql.Append(" @menutype , -- menutype - nvarchar(50) \n"); sql.Append(" @seq ,@viewpath, -- seq - nvarchar(50) \n"); sql.Append(" GETDATE() -- add_time - datetime \n"); sql.Append("where NOT EXISTS(select * from sys_menu where code=@code)\n select SCOPE_IDENTITY();\n"); int menuid = db.Current_Conn.ExecuteScalar <int>(sql.ToString(), entry); entry.id = menuid; entry.entitytype = "sys_menu"; if (menuid > 0) { solr.Add(entry); solr.Commit(); } return(menuid); } }
/// <summary> /// Tracks a provided repository for a channel and adds its documents to Solr. /// </summary> public void TrackRepository(GitHubUser user, List <Octokit.Repository> repositories) { ISolrOperations <CodeDoc> solr = ServiceLocator.Current.GetInstance <ISolrOperations <CodeDoc> >(); try { var clone_options = new CloneOptions(); clone_options.CredentialsProvider = (_url, _user, _cred) => new UsernamePasswordCredentials { Username = user.GitHubAccessToken, Password = String.Empty }; foreach (var repo in repositories) { string repo_path = GetTemporaryDirectory(); string git_url = repo.CloneUrl; LibGit2Sharp.Repository.Clone(git_url, repo_path, clone_options); List <CodeDoc> commit_files = ParseRepository(user, repo_path); solr.AddRange(commit_files); solr.Commit(); Directory.Delete(repo_path, true); Console.WriteLine(String.Format("Finished tracking {0} for {1} to Solr", repo.Name, user.UUID)); } } catch (RateLimitExceededException) { Console.WriteLine(String.Format("Rate limit exceeded for {0}. Stopping...", user.UUID)); } catch (AbuseException) { Console.WriteLine(String.Format("Abuse detection triggered for {0}. Stopping...", user.UUID)); } catch (Exception ex) { Console.WriteLine(String.Format("Error trying to track repository for {0}. Stopping...", user.UUID)); Console.WriteLine(ex.ToString()); } finally { solr.Commit(); } }
public void UpdateInternal(AbstractEvent e, T entity) { if (entity == null) { return; } if (entity.GetType() != typeof(T)) // strict check for type, e.g. no subtypes { return; } if (DeferAction(e.Session)) { Add(e.Session.Transaction, entity); } else { solr.Add(entity, AddParameters); if (Commit) { solr.Commit(); } } }
public void Write(IEnumerable <IRow> rows) { _originalConnectionLimit = ServicePointManager.DefaultConnectionLimit; ServicePointManager.DefaultConnectionLimit = _context.Connection.MaxDegreeOfParallelism * 2; try { Parallel.ForEach(rows.Partition(_context.Entity.InsertSize), _options, part => { var docs = new List <Dictionary <string, object> >(); foreach (var row in part) { Interlocked.Increment(ref _count); docs.Add(_fields.ToDictionary(field => field.Alias.ToLower(), field => row[field])); } var response = _solr.AddRange(docs); if (response.Status != 0) { _context.Error($"Couldn't add range of {docs.Count} document{docs.Count.Plural()} to SOLR."); } }); } catch (AggregateException ex) { foreach (var exception in ex.InnerExceptions) { _context.Error(exception.Message); _context.Error(exception.StackTrace); } return; } ServicePointManager.DefaultConnectionLimit = _originalConnectionLimit; if (_count > 0) { try { var commit = _solr.Commit(); if (commit.Status == 0) { _context.Entity.Inserts += Convert.ToUInt32(_count); _context.Info($"Committed {_count} documents in {TimeSpan.FromMilliseconds(commit.QTime)}"); } else { _context.Error($"Failed to commit {_count} documents. SOLR returned status {commit.Status}."); } } catch (SolrNetException ex) { _context.Error($"Failed to commit {_count} documents. {ex.Message}"); } } }
public int Add(sys_role entry) { using (LocalDB db = new LocalDB()) { StringBuilder sql = new StringBuilder(); sql.Append("INSERT INTO dbo.sys_role \n"); sql.Append(" ( status, code, title, add_time ) \n"); sql.Append("VALUES ( @status, -- status - int \n"); sql.Append(" @code, -- code - nvarchar(50) \n"); sql.Append(" @title, -- title - nvarchar(50) \n"); sql.Append(" GETDATE() -- add_time - datetime \n"); sql.Append(" );select SCOPE_IDENTITY();"); int roleid = db.Current_Conn.ExecuteScalar <int>(sql.ToString(), new { status = entry.status, code = entry.code, title = entry.title }); entry.id = roleid; solr.Add(entry); solr.Commit(); return(roleid); } }
private static void SetProgrammingFilestoDeleteTrue(ISolrOperations <FileIndex> solr) { var solrQueryResults = solr.Query(new SolrQuery("matched_functions:\"Programming Files\"")); foreach (var solrQueryResult in solrQueryResults) { var atomicUpdateSpecs = new List <AtomicUpdateSpec> { new AtomicUpdateSpec(FileIndex.Keys.Delete, AtomicUpdateType.Set, "true") }; solr.AtomicUpdate(solrQueryResult, atomicUpdateSpecs); } solr.Commit(); }
public void Write(IEnumerable <IRow> rows) { var fullCount = 0; foreach (var part in rows.Partition(_context.Entity.InsertSize)) { var batchCount = 0; foreach (var row in part) { var doc = _documents[batchCount]; foreach (var field in _fields) { doc[field.Alias] = row[field]; } batchCount++; fullCount++; } var response = _solr.AddRange(_documents.Take(batchCount)); if (response.Status == 0) { var count = batchCount; _context.Debug(() => $"{count} to output"); } else { _context.Error($"Couldn't add range of documents to SOLR."); } } if (fullCount > 0) { try { var commit = _solr.Commit(); if (commit.Status == 0) { _context.Entity.Inserts += System.Convert.ToUInt32(fullCount); _context.Info($"Committed {fullCount} documents in {TimeSpan.FromMilliseconds(commit.QTime)}"); } else { _context.Error($"Failed to commit {fullCount} documents. SOLR returned status {commit.Status}."); } } catch (SolrNetException ex) { _context.Error($"Failed to commit {fullCount} documents. {ex.Message}"); } } }
public ActionResponse Execute() { _context.Warn("Initializing"); List <CoreResult> cores = null; try { cores = _admin.Status(); } catch (Exception ex) { return(new ActionResponse() { Code = 500, Message = $"Count not access {_context.Connection.Url}: {ex.Message}" }); } var coreFolder = new DirectoryInfo(Path.Combine(_context.Connection.Folder, _context.Connection.Core)); if (!coreFolder.Exists) { coreFolder.Create(); // https://stackoverflow.com/questions/58744/copy-the-entire-contents-of-a-directory-in-c-sharp var sourceFolder = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "files\\solr")); foreach (string d in Directory.GetDirectories(sourceFolder.FullName, "*", SearchOption.AllDirectories)) { Directory.CreateDirectory(d.Replace(sourceFolder.FullName, coreFolder.FullName)); } foreach (string f in Directory.GetFiles(sourceFolder.FullName, "*.*", SearchOption.AllDirectories)) { File.Copy(f, f.Replace(sourceFolder.FullName, coreFolder.FullName), true); } } File.WriteAllText(Path.Combine(Path.Combine(coreFolder.FullName, "conf"), "schema.xml"), _engine.Render()); if (cores.Any(c => c.Name == _context.Connection.Core)) { _admin.Reload(_context.Connection.Core); } else { _admin.Create(_context.Connection.Core, _context.Connection.Core); } _solr.Delete(SolrQuery.All); _solr.Commit(); return(new ActionResponse()); }
private void UpdateSolrIndexForProject(IndexSettings settings, ISolrOperations<CodeDocument> solr, Project proj) { List<string> alldocs = null; //find out if directory exists before doing anything to the index if (!Directory.Exists(proj.Path)) { Console.WriteLine(DateTime.Now.ToString() + ": Directory for project " + proj.ProjectName + " did not exist, skipping"); return; } //find all of the files using (var csw = new ConsoleStopWatch("")) { alldocs = GetDocsForProject(proj, settings.DefaultIncludedPath, settings.DefaultExcludedPath); csw.Name = "Finding " + alldocs.Count.ToString() + " files for project " + proj.ProjectName; } using (var csw = new ConsoleStopWatch("Deleting all solr docs for project " + proj.ProjectName)) { solr.Delete(new SolrQuery("project:\"" + proj.ProjectName + "\"")); solr.Commit(); } //breakout the file list into chunks of DOCS_PER_POST for speed. One at a time is too slow, too many can cause solr memory and thread issues var fileChunks = Chunkify(alldocs.ToArray(), DOCS_PER_POST); using (var csw = new ConsoleStopWatch("Adding the documents to solr for project " + proj.ProjectName)) { //convert each to a solr document for (int i = 0; i < fileChunks.Length; i++) { var file = fileChunks[i]; var codedocs = MakeDocument(file, proj); //submit each to solr //Tweak to leverage new CommitIWithin option of SolrNet so that we do not need to pay the cost of a commit for each group. solr.AddRange(codedocs, new AddParameters { CommitWithin = 10000 }); } solr.Optimize(); } }