mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-19 10:07:55 +08:00
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:
@@ -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);
|
||||
|
@@ -43,6 +43,7 @@ namespace Orchard.Search.Controllers {
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
_searchService.RebuildIndex();
|
||||
_searchService.UpdateIndex();
|
||||
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
@@ -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."));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user