Fix small bug in index provider

Also cleanup the API a bit
Also provide more detailled statistics about the search index on the
"Search Index Management" page.

--HG--
branch : dev
This commit is contained in:
Renaud Paquay
2010-07-11 12:11:38 -07:00
parent 2761c3520b
commit 5a7724e2e1
9 changed files with 65 additions and 37 deletions

View File

@@ -1,10 +1,17 @@
using System;
using System.Collections.Generic;
namespace Orchard.Indexing.Services {
public class IndexEntry {
public string IndexName { get; set; }
public int DocumentCount { get; set; }
public DateTime? LastUpdateUtc { get; set; }
public IEnumerable<string> Fields { get; set; }
}
public interface IIndexingService : IDependency {
bool HasIndexToManage { get; }
void RebuildIndex();
void UpdateIndex();
DateTime GetIndexUpdatedUtc();
IndexEntry GetIndexEntry();
}
}

View File

@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using Orchard.Localization;
using Orchard.Localization.Services;
using Orchard.UI.Notify;
@@ -22,10 +21,6 @@ namespace Orchard.Indexing.Services
public IOrchardServices Services { get; set; }
public Localizer T { get; set; }
public bool HasIndexToManage {
get { return _indexManager.HasIndexProvider(); }
}
void IIndexingService.RebuildIndex() {
if (!_indexManager.HasIndexProvider()) {
Services.Notifier.Warning(T("There is no search index to rebuild."));
@@ -50,10 +45,17 @@ namespace Orchard.Indexing.Services
Services.Notifier.Information(T("The search index has been updated."));
}
DateTime IIndexingService.GetIndexUpdatedUtc() {
return !HasIndexToManage
? DateTime.MinValue
: _indexManager.GetSearchIndexProvider().GetLastIndexUtc(SearchIndexName);
IndexEntry IIndexingService.GetIndexEntry() {
var provider = _indexManager.GetSearchIndexProvider();
if (provider == null)
return null;
return new IndexEntry {
IndexName = SearchIndexName,
DocumentCount = provider.NumDocs(SearchIndexName),
Fields = provider.GetFields(SearchIndexName),
LastUpdateUtc = provider.GetLastIndexUtc(SearchIndexName)
};
}
}
}

View File

@@ -59,14 +59,14 @@ namespace Orchard.Indexing.Services {
_indexProvider = _indexManager.GetSearchIndexProvider();
var updateIndexDocuments = new List<IDocumentIndex>();
DateTime lastIndexing;
DateTime? lastIndexUtc;
// Do we need to rebuild the full index (first time module is used, or rebuild index requested) ?
if (_indexProvider.IsEmpty(SearchIndexName)) {
Logger.Information("Rebuild index started");
// mark current last task, as we should process older ones (in case of rebuild index only)
lastIndexing = _indexingTaskManager.GetLastTaskDateTime();
lastIndexUtc = _indexingTaskManager.GetLastTaskDateTime();
// get every existing content item to index it
foreach (var contentItem in _contentManager.Query(VersionOptions.Published).List()) {
@@ -91,15 +91,15 @@ namespace Orchard.Indexing.Services {
}
else {
// retrieve last processed index time
lastIndexing = _indexProvider.GetLastIndexUtc(SearchIndexName);
lastIndexUtc = _indexProvider.GetLastIndexUtc(SearchIndexName);
}
_indexProvider.SetLastIndexUtc(SearchIndexName, _clock.UtcNow);
// retrieve not yet processed tasks
var taskRecords = lastIndexing == DateTime.MinValue
var taskRecords = lastIndexUtc == null
? _repository.Fetch(x => true).ToArray()
: _repository.Fetch(x => x.CreatedUtc > lastIndexing).ToArray();
: _repository.Fetch(x => x.CreatedUtc > lastIndexUtc).ToArray();
// nothing to do ?