mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Merge
--HG-- branch : dev
This commit is contained in:
@@ -216,5 +216,38 @@ namespace Orchard.Tests.Indexing {
|
|||||||
_provider.Store("default", _provider.New(1).Add("body", null));
|
_provider.Store("default", _provider.New(1).Add("body", null));
|
||||||
Assert.That(_provider.IsEmpty("default"), Is.False);
|
Assert.That(_provider.IsEmpty("default"), Is.False);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void IsDirtyShouldBeFalseForNewDocuments() {
|
||||||
|
IIndexDocument doc = _provider.New(1);
|
||||||
|
Assert.That(doc.IsDirty, Is.False);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void IsDirtyShouldBeTrueWhenIndexIsModified() {
|
||||||
|
IIndexDocument doc;
|
||||||
|
|
||||||
|
doc = _provider.New(1);
|
||||||
|
doc.Add("foo", "value");
|
||||||
|
Assert.That(doc.IsDirty, Is.True);
|
||||||
|
|
||||||
|
doc = _provider.New(1);
|
||||||
|
doc.Add("foo", false);
|
||||||
|
Assert.That(doc.IsDirty, Is.True);
|
||||||
|
|
||||||
|
doc = _provider.New(1);
|
||||||
|
doc.Add("foo", (float)1.0);
|
||||||
|
Assert.That(doc.IsDirty, Is.True);
|
||||||
|
|
||||||
|
doc = _provider.New(1);
|
||||||
|
doc.Add("foo", 1);
|
||||||
|
Assert.That(doc.IsDirty, Is.True);
|
||||||
|
|
||||||
|
doc = _provider.New(1);
|
||||||
|
doc.Add("foo", DateTime.Now);
|
||||||
|
Assert.That(doc.IsDirty, Is.True);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,13 +12,17 @@ namespace Orchard.Core.Indexing.Lucene {
|
|||||||
|
|
||||||
public List<AbstractField> Fields { get; private set; }
|
public List<AbstractField> Fields { get; private set; }
|
||||||
private AbstractField _previousField;
|
private AbstractField _previousField;
|
||||||
|
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
|
||||||
public DefaultIndexDocument(int documentId) {
|
public DefaultIndexDocument(int documentId) {
|
||||||
Fields = new List<AbstractField>();
|
Fields = new List<AbstractField>();
|
||||||
SetContentItemId(documentId);
|
SetContentItemId(documentId);
|
||||||
|
IsDirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsDirty { get; private set; }
|
||||||
|
|
||||||
public IIndexDocument Add(string name, string value) {
|
public IIndexDocument Add(string name, string value) {
|
||||||
return Add(name, value, false);
|
return Add(name, value, false);
|
||||||
}
|
}
|
||||||
@@ -35,36 +39,42 @@ namespace Orchard.Core.Indexing.Lucene {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_previousField = new Field(name, value, Field.Store.YES, Field.Index.ANALYZED);
|
_previousField = new Field(name, value, Field.Store.YES, Field.Index.ANALYZED);
|
||||||
|
IsDirty = true;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IIndexDocument Add(string name, DateTime value) {
|
public IIndexDocument Add(string name, DateTime value) {
|
||||||
AppendPreviousField();
|
AppendPreviousField();
|
||||||
_previousField = new Field(name, DateTools.DateToString(value, DateTools.Resolution.SECOND), Field.Store.YES, Field.Index.NOT_ANALYZED);
|
_previousField = new Field(name, DateTools.DateToString(value, DateTools.Resolution.SECOND), Field.Store.YES, Field.Index.NOT_ANALYZED);
|
||||||
|
IsDirty = true;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IIndexDocument Add(string name, int value) {
|
public IIndexDocument Add(string name, int value) {
|
||||||
AppendPreviousField();
|
AppendPreviousField();
|
||||||
_previousField = new NumericField(name, Field.Store.YES, true).SetIntValue(value);
|
_previousField = new NumericField(name, Field.Store.YES, true).SetIntValue(value);
|
||||||
|
IsDirty = true;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IIndexDocument Add(string name, bool value) {
|
public IIndexDocument Add(string name, bool value) {
|
||||||
AppendPreviousField();
|
AppendPreviousField();
|
||||||
_previousField = new Field(name, value.ToString().ToLower(), Field.Store.YES, Field.Index.NOT_ANALYZED);
|
_previousField = new Field(name, value.ToString().ToLower(), Field.Store.YES, Field.Index.NOT_ANALYZED);
|
||||||
|
IsDirty = true;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IIndexDocument Add(string name, float value) {
|
public IIndexDocument Add(string name, float value) {
|
||||||
AppendPreviousField();
|
AppendPreviousField();
|
||||||
_previousField = new NumericField(name, Field.Store.YES, true).SetFloatValue(value);
|
_previousField = new NumericField(name, Field.Store.YES, true).SetFloatValue(value);
|
||||||
|
IsDirty = true;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IIndexDocument Add(string name, object value) {
|
public IIndexDocument Add(string name, object value) {
|
||||||
AppendPreviousField();
|
AppendPreviousField();
|
||||||
_previousField = new Field(name, value.ToString(), Field.Store.NO, Field.Index.NOT_ANALYZED);
|
_previousField = new Field(name, value.ToString(), Field.Store.NO, Field.Index.NOT_ANALYZED);
|
||||||
|
IsDirty = true;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -155,7 +155,16 @@ namespace Orchard.Core.Indexing.Lucene {
|
|||||||
public IEnumerable<ISearchHit> Search() {
|
public IEnumerable<ISearchHit> Search() {
|
||||||
var query = CreateQuery();
|
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 {
|
try {
|
||||||
var sort = String.IsNullOrEmpty(_sort)
|
var sort = String.IsNullOrEmpty(_sort)
|
||||||
@@ -188,8 +197,17 @@ namespace Orchard.Core.Indexing.Lucene {
|
|||||||
|
|
||||||
public int Count() {
|
public int Count() {
|
||||||
var query = CreateQuery();
|
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 {
|
try {
|
||||||
var hits = searcher.Search(query, Int16.MaxValue);
|
var hits = searcher.Search(query, Int16.MaxValue);
|
||||||
Logger.Information("Search results: {0}", hits.scoreDocs.Length);
|
Logger.Information("Search results: {0}", hits.scoreDocs.Length);
|
||||||
|
|||||||
@@ -91,10 +91,12 @@ namespace Orchard.Core.Indexing.Services {
|
|||||||
handler.Indexing(context);
|
handler.Indexing(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateIndexDocuments.Add(context.IndexDocument);
|
if ( context.IndexDocument.IsDirty ) {
|
||||||
|
updateIndexDocuments.Add(context.IndexDocument);
|
||||||
|
|
||||||
foreach (var handler in _handlers) {
|
foreach ( var handler in _handlers ) {
|
||||||
handler.Indexed(context);
|
handler.Indexed(context);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
@@ -146,11 +148,14 @@ namespace Orchard.Core.Indexing.Services {
|
|||||||
handler.Indexing(context);
|
handler.Indexing(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateIndexDocuments.Add(context.IndexDocument);
|
if ( context.IndexDocument.IsDirty ) {
|
||||||
|
updateIndexDocuments.Add(context.IndexDocument);
|
||||||
foreach (var handler in _handlers) {
|
|
||||||
handler.Indexed(context);
|
foreach (var handler in _handlers) {
|
||||||
|
handler.Indexed(context);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
Logger.Warning(ex, "Unable to process indexing task #{0}", taskRecord.Id);
|
Logger.Warning(ex, "Unable to process indexing task #{0}", taskRecord.Id);
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ namespace Orchard.Search.Controllers {
|
|||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
_searchService.RebuildIndex();
|
_searchService.RebuildIndex();
|
||||||
|
_searchService.UpdateIndex();
|
||||||
|
|
||||||
return RedirectToAction("Index");
|
return RedirectToAction("Index");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ namespace Orchard.Search.Services
|
|||||||
searchProvider.DeleteIndex(SearchIndexName);
|
searchProvider.DeleteIndex(SearchIndexName);
|
||||||
|
|
||||||
searchProvider.CreateIndex(SearchIndexName); // or just reset the updated date and let the background process recreate the index
|
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."));
|
Services.Notifier.Information(T("The search index has been rebuilt."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,10 @@ namespace Orchard.Indexing {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
IIndexDocument Analyze(bool analyze);
|
IIndexDocument Analyze(bool analyze);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether some property have been added to this document, or otherwise if it's empty
|
||||||
|
/// </summary>
|
||||||
|
bool IsDirty { get; }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user