private bool UpdateIndex(string indexName, string settingsFilename, IndexSettings indexSettings) { var addToIndex = new List <IDocumentIndex>(); // Rebuilding the inde logger.Value.Info("Rebuilding index"); indexingStatus = IndexingStatus.Rebuilding; foreach (var contentProvider in contentProviders) { addToIndex.AddRange(contentProvider.GetDocuments(id => indexProvider.New(id))); } // save current state of the index indexSettings.LastIndexedUtc = DateTime.UtcNow; appDataFolder.CreateFile(settingsFilename, indexSettings.ToXml()); if (addToIndex.Count == 0) { // nothing more to do indexingStatus = IndexingStatus.Idle; return(false); } // save new and updated documents to the index indexProvider.Store(indexName, addToIndex); logger.Value.InfoFormat("Added documents to index: {0}", addToIndex.Count); return(true); }
/// <summary> /// Creates a IDocumentIndex instance for a specific content item id. If the content /// item is no more published, it returns null. /// </summary> private IDocumentIndex ExtractDocumentIndex(ContentItem contentItem) { // ignore deleted or unpublished items if (contentItem == null || (!contentItem.IsPublished() && !contentItem.HasDraft())) { return(null); } var documentIndex = _indexProvider.New(contentItem.Id); // call all handlers to add content to index _contentManager.Index(contentItem, documentIndex); return(documentIndex); }
/// <summary> /// Creates a IDocumentIndex instance for a specific content item id. If the content /// item is no more published, it returns null. /// </summary> private IDocumentIndex ExtractDocumentIndex(ContentItem contentItem) { // ignore deleted or unpublished items if (contentItem == null || !contentItem.IsPublished()) { return(null); } // skip items from types which are not indexed var settings = GetTypeIndexingSettings(contentItem); if (!settings.Included) { return(null); } var documentIndex = _indexProvider.New(contentItem.Id); // call all handlers to add content to index _contentManager.Index(contentItem, documentIndex); return(documentIndex); }
public void IndexProviderShouldOverwriteAlreadyExistingIndex() { _provider.CreateIndex("default"); _provider.Store("default", _provider.New(1).Add("body", null)); Assert.That(_provider.IsEmpty("default"), Is.False); _provider.CreateIndex("default"); Assert.That(_provider.IsEmpty("default"), Is.True); }
public void SearchTermsShouldBeFoundInMultipleFields() { _provider.CreateIndex("default"); _provider.Store("default", _provider.New(42) .Add("title", "title1 title2 title3").Analyze() .Add("date", new DateTime(2010, 05, 28, 14, 13, 56, 123)) ); Assert.IsNotNull(_provider.CreateSearchBuilder("default").Get(42)); Assert.IsNotNull(_provider.CreateSearchBuilder("default").WithField("title", "title1").Search().FirstOrDefault()); Assert.IsNotNull(_provider.CreateSearchBuilder("default").WithField("title", "title2").Search().FirstOrDefault()); Assert.IsNotNull(_provider.CreateSearchBuilder("default").WithField("title", "title3").Search().FirstOrDefault()); Assert.IsNull(_provider.CreateSearchBuilder("default").WithField("title", "title4").Search().FirstOrDefault()); }