Prevents the index to be accessed when it is rebuilt

Also call UpdateIndex() to take the rebuilt index into account immediately

--HG--
branch : dev
This commit is contained in:
Sebastien Ros
2010-06-08 11:51:37 -07:00
parent 9574529898
commit 598d39006f
3 changed files with 22 additions and 2 deletions

View File

@@ -155,7 +155,16 @@ namespace Orchard.Core.Indexing.Lucene {
public IEnumerable<ISearchHit> Search() {
var query = CreateQuery();
var searcher = new IndexSearcher(_directory, true);
IndexSearcher searcher;
try {
searcher = new IndexSearcher(_directory, true);
}
catch {
// index might not exist if it has been rebuilt
Logger.Information("Attempt to read a none existing index");
return Enumerable.Empty<ISearchHit>();
}
try {
var sort = String.IsNullOrEmpty(_sort)
@@ -188,8 +197,17 @@ namespace Orchard.Core.Indexing.Lucene {
public int Count() {
var query = CreateQuery();
IndexSearcher searcher;
try {
searcher = new IndexSearcher(_directory, true);
}
catch {
// index might not exist if it has been rebuilt
Logger.Information("Attempt to read a none existing index");
return 0;
}
var searcher = new IndexSearcher(_directory, true);
try {
var hits = searcher.Search(query, Int16.MaxValue);
Logger.Information("Search results: {0}", hits.scoreDocs.Length);

View File

@@ -43,6 +43,7 @@ namespace Orchard.Search.Controllers {
return new HttpUnauthorizedResult();
_searchService.RebuildIndex();
_searchService.UpdateIndex();
return RedirectToAction("Index");
}

View File

@@ -63,6 +63,7 @@ namespace Orchard.Search.Services
searchProvider.DeleteIndex(SearchIndexName);
searchProvider.CreateIndex(SearchIndexName); // or just reset the updated date and let the background process recreate the index
Services.Notifier.Information(T("The search index has been rebuilt."));
}