public Boolean Update(Quote theQuote) { try { _ctx.Add(theQuote); _ctx.Commit(); _ctx.Optimize(); return(true); } catch { return(false); } }
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 int IndexItems(List <CmsSearchResultItem> items) { var itemsPublished = Mapper.Map <List <CmsSearchResultItem>, List <CmsSearchResultItemPublished> >(items); ISolrOperations <CmsSearchResultItem> instance = ServiceLocator.Current.GetInstance <ISolrOperations <CmsSearchResultItem> >(); ISolrOperations <CmsSearchResultItemPublished> instancePublished = ServiceLocator.Current.GetInstance <ISolrOperations <CmsSearchResultItemPublished> >(); int int32 = Convert.ToInt32(Math.Ceiling(Convert.ToDecimal(items.Count) / new Decimal(100))); for (int index = 0; index < int32; ++index) { this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, string.Format("Indexing items {0} to {1}", (object)(100 * index), (object)(100 * (index + 1))), (Exception)null); List <CmsSearchResultItem> list = items.Skip <CmsSearchResultItem>(100 * index).Take <CmsSearchResultItem>(100 * (index + 1)).ToList <CmsSearchResultItem>(); List <CmsSearchResultItemPublished> listPublished = itemsPublished.Skip <CmsSearchResultItemPublished>(100 * index).Take <CmsSearchResultItemPublished>(100 * (index + 1)).ToList <CmsSearchResultItemPublished>(); instance.AddRange((IEnumerable <CmsSearchResultItem>)list); instancePublished.AddRange((IEnumerable <CmsSearchResultItemPublished>)listPublished); this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, "Indexing documents in collection", (Exception)null); foreach (CmsSearchResultItem searchResultItem in list.Where <CmsSearchResultItem>((Func <CmsSearchResultItem, bool>)(item => item.Documents.Any <string>()))) { foreach (string document in searchResultItem.Documents) { this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, "Finding media for document " + document, (Exception)null); ICmsMedia cmsMedia = this.cmsIndexer.ResolveMedia(document); if (cmsMedia != null) { this.log.AddLogentry(SolisSearch.Log.Enum.LogLevel.Debug, "Indexing media item " + cmsMedia.Name, (Exception)null); this.IndexRichText(document, cmsMedia.Id, searchResultItem.Acl, searchResultItem.Languages, searchResultItem.StartPublish, searchResultItem.EndPublish, searchResultItem.Id); } } } } instance.Commit(); instance.Optimize(); instancePublished.Commit(); instancePublished.Optimize(); return(items.Count); }
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(); } }