--HG--
branch : 1.x
This commit is contained in:
andrerod
2011-01-05 18:44:22 -08:00
7 changed files with 56 additions and 73 deletions

View File

@@ -1,4 +1,5 @@
using Lucene.Net.Documents; using System;
using Lucene.Net.Documents;
using System.Globalization; using System.Globalization;
using Lucene.Net.Util; using Lucene.Net.Util;
using Orchard.Indexing; using Orchard.Indexing;
@@ -18,23 +19,28 @@ namespace Lucene.Models {
public int ContentItemId { get { return int.Parse(GetString("id")); } } public int ContentItemId { get { return int.Parse(GetString("id")); } }
public int GetInt(string name) { public int GetInt(string name) {
return NumericUtils.PrefixCodedToInt(_doc.GetField(name).StringValue()); var field = _doc.GetField(name);
return field == null ? 0 : NumericUtils.PrefixCodedToInt(field.StringValue());
} }
public float GetFloat(string name) { public float GetFloat(string name) {
return float.Parse(_doc.GetField(name).StringValue(), CultureInfo.InvariantCulture); var field = _doc.GetField(name);
return field == null ? 0 : float.Parse(field.StringValue(), CultureInfo.InvariantCulture);
} }
public bool GetBoolean(string name) { public bool GetBoolean(string name) {
return bool.Parse(_doc.GetField(name).StringValue()); var field = _doc.GetField(name);
return field == null ? false : bool.Parse(field.StringValue());
} }
public string GetString(string name) { public string GetString(string name) {
return _doc.GetField(name).StringValue(); var field = _doc.GetField(name);
return field == null ? null : field.StringValue();
} }
public System.DateTime GetDateTime(string name) { public DateTime GetDateTime(string name) {
return DateTools.StringToDate(_doc.GetField(name).StringValue()); var field = _doc.GetField(name);
return field == null ? DateTime.MinValue : DateTools.StringToDate(field.StringValue());
} }
} }
} }

View File

@@ -3,30 +3,29 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using Orchard.Commands; using Orchard.Commands;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.ContentManagement.Aspects;
using Orchard.Indexing.Services;
using Orchard.Tasks.Indexing; using Orchard.Tasks.Indexing;
namespace Orchard.Indexing.Commands { namespace Orchard.Indexing.Commands {
public class IndexingCommands : DefaultOrchardCommandHandler { public class IndexingCommands : DefaultOrchardCommandHandler {
private readonly IEnumerable<IIndexNotifierHandler> _indexNotifierHandlers;
private readonly IIndexManager _indexManager; private readonly IIndexManager _indexManager;
private readonly IIndexingService _indexingService;
private readonly IIndexingTaskManager _indexingTaskManager; private readonly IIndexingTaskManager _indexingTaskManager;
private readonly IContentManager _contentManager; private readonly IContentManager _contentManager;
private const string SearchIndexName = "Search"; private const string SearchIndexName = "Search";
public IndexingCommands( public IndexingCommands(
IEnumerable<IIndexNotifierHandler> indexNotifierHandlers,
IIndexManager indexManager, IIndexManager indexManager,
IIndexingService indexingService,
IIndexingTaskManager indexingTaskManager, IIndexingTaskManager indexingTaskManager,
IContentManager contentManager) { IContentManager contentManager) {
_indexNotifierHandlers = indexNotifierHandlers;
_indexingTaskManager = indexingTaskManager; _indexingTaskManager = indexingTaskManager;
_contentManager = contentManager; _contentManager = contentManager;
_indexManager = indexManager; _indexManager = indexManager;
_indexingService = indexingService;
} }
[OrchardSwitch]
public string IndexName { get; set; }
[OrchardSwitch] [OrchardSwitch]
public string Query { get; set; } public string Query { get; set; }
@@ -34,48 +33,31 @@ namespace Orchard.Indexing.Commands {
public string ContentItem { get; set; } public string ContentItem { get; set; }
[CommandName("index update")] [CommandName("index update")]
[CommandHelp("index update [/IndexName:<index name>]\r\n\t" + "Updates the index with the specified <index name>, or the search index if not specified")] [CommandHelp("index update\r\n\t" + "Updates the search index")]
[OrchardSwitches("IndexName")]
public string Update() { public string Update() {
if ( !_indexManager.HasIndexProvider() ) { _indexingService.UpdateIndex();
throw new OrchardException(T("No index available"));
}
var indexName = String.IsNullOrWhiteSpace(IndexName) ? SearchIndexName : IndexName; return T("Index is now being updated...").Text;
foreach ( var handler in _indexNotifierHandlers ) {
handler.UpdateIndex(indexName);
}
return "Index is now being updated...";
} }
[CommandName("index rebuild")] [CommandName("index rebuild")]
[CommandHelp("index rebuild [/IndexName:<index name>]\r\n\t" + "Rebuilds the index with the specified <index name>, or the search index if not specified")] [CommandHelp("index rebuild \r\n\t" + "Rebuilds the search index")]
[OrchardSwitches("IndexName")]
public string Rebuild() { public string Rebuild() {
if ( !_indexManager.HasIndexProvider() ) { _indexingService.RebuildIndex();
throw new OrchardException(T("No index available")); _indexingService.UpdateIndex();
}
var indexName = String.IsNullOrWhiteSpace(IndexName) ? SearchIndexName : IndexName; return T("Index is now being rebuilt...").Text;
var searchProvider = _indexManager.GetSearchIndexProvider();
if ( searchProvider.Exists(indexName) )
searchProvider.DeleteIndex(indexName);
searchProvider.CreateIndex(indexName);
return "Index is now being rebuilt...";
} }
[CommandName("index search")] [CommandName("index search")]
[CommandHelp("index search /Query:<query> [/IndexName:<index name>]\r\n\t" + "Searches the specified <query> terms in the index with the specified <index name>, or in the search index if not specified")] [CommandHelp("index search /Query:<query>\r\n\t" + "Searches the specified <query> terms in the search index")]
[OrchardSwitches("Query,IndexName")] [OrchardSwitches("Query")]
public string Search() { public string Search() {
if ( !_indexManager.HasIndexProvider() ) { if ( !_indexManager.HasIndexProvider() ) {
throw new OrchardException(T("No index available")); throw new OrchardException(T("No index available"));
} }
var indexName = String.IsNullOrWhiteSpace(IndexName) ? SearchIndexName : IndexName; var searchBuilder = _indexManager.GetSearchIndexProvider().CreateSearchBuilder(SearchIndexName);
var searchBuilder = _indexManager.GetSearchIndexProvider().CreateSearchBuilder(indexName); var results = searchBuilder.Parse( new [] {"body", "title"}, Query).Search();
var results = searchBuilder.WithField("body", Query).WithField("title", Query).Search();
Context.Output.WriteLine("{0} result{1}\r\n-----------------\r\n", results.Count(), results.Count() > 0 ? "s" : ""); Context.Output.WriteLine("{0} result{1}\r\n-----------------\r\n", results.Count(), results.Count() > 0 ? "s" : "");
@@ -83,27 +65,28 @@ namespace Orchard.Indexing.Commands {
Context.Output.WriteLine("│ {0} │ {1,6} │", "Title" + new string(' ', 60 - "Title".Length), "Score"); Context.Output.WriteLine("│ {0} │ {1,6} │", "Title" + new string(' ', 60 - "Title".Length), "Score");
Context.Output.WriteLine("├──────────────────────────────────────────────────────────────┼────────┤"); Context.Output.WriteLine("├──────────────────────────────────────────────────────────────┼────────┤");
foreach ( var searchHit in results ) { foreach ( var searchHit in results ) {
var title = searchHit.GetString("title") ?? "- no title -"; var contentItem = _contentManager.Get(searchHit.ContentItemId);
var routable = contentItem.As<IRoutableAspect>();
var title = routable == null ? "- no title -" : routable.Title;
title = title.Substring(0, Math.Min(60, title.Length)); title = title.Substring(0, Math.Min(60, title.Length));
var score = searchHit.Score; var score = Math.Round(searchHit.Score, 2).ToString();
Context.Output.WriteLine("│ {0} │ {1,6} │", title + new string(' ', 60 - title.Length), score); Context.Output.WriteLine("│ {0} │ {1,6} │", title + new string(' ', 60 - title.Length), score);
} }
Context.Output.WriteLine("└──────────────────────────────────────────────────────────────┴────────┘"); Context.Output.WriteLine("└──────────────────────────────────────────────────────────────┴────────┘");
Context.Output.WriteLine(); Context.Output.WriteLine();
return "End of search results"; return T("End of search results").Text;
} }
[CommandName("index stats")] [CommandName("index stats")]
[CommandHelp("index stats [/IndexName:<index name>]\r\n\t" + "Displays some statistics about the index with the specified <index name>, or in the search index if not specified")] [CommandHelp("index stats\r\n\t" + "Displays some statistics about the search index")]
[OrchardSwitches("IndexName")] [OrchardSwitches("IndexName")]
public string Stats() { public string Stats() {
if ( !_indexManager.HasIndexProvider() ) { if ( !_indexManager.HasIndexProvider() ) {
throw new OrchardException(T("No index available")); throw new OrchardException(T("No index available"));
} }
var indexName = String.IsNullOrWhiteSpace(IndexName) ? SearchIndexName : IndexName;
Context.Output.WriteLine("Number of indexed documents: {0}", _indexManager.GetSearchIndexProvider().NumDocs(indexName)); return T("Number of indexed documents: {0}", _indexManager.GetSearchIndexProvider().NumDocs(SearchIndexName)).Text;
return "";
} }
[CommandName("index refresh")] [CommandName("index refresh")]
@@ -118,7 +101,7 @@ namespace Orchard.Indexing.Commands {
var contentItem = _contentManager.Get(contentItemId); var contentItem = _contentManager.Get(contentItemId);
_indexingTaskManager.CreateUpdateIndexTask(contentItem); _indexingTaskManager.CreateUpdateIndexTask(contentItem);
return "Content Item marked for reindexing"; return T("Content Item marked for reindexing").Text;
} }
[CommandName("index delete")] [CommandName("index delete")]
@@ -133,7 +116,7 @@ namespace Orchard.Indexing.Commands {
var contentItem = _contentManager.Get(contentItemId); var contentItem = _contentManager.Get(contentItemId);
_indexingTaskManager.CreateDeleteIndexTask(contentItem); _indexingTaskManager.CreateDeleteIndexTask(contentItem);
return "Content Item marked for deletion"; return T("Content Item marked for deletion").Text;
} }
} }

View File

@@ -5,8 +5,7 @@ using Orchard.UI.Notify;
namespace Orchard.Indexing.Services namespace Orchard.Indexing.Services
{ {
public class IndexingService : IIndexingService public class IndexingService : IIndexingService {
{
private const string SearchIndexName = "Search"; private const string SearchIndexName = "Search";
private readonly IIndexManager _indexManager; private readonly IIndexManager _indexManager;
private readonly IEnumerable<IIndexNotifierHandler> _indexNotifierHandlers; private readonly IEnumerable<IIndexNotifierHandler> _indexNotifierHandlers;

View File

@@ -101,7 +101,7 @@ namespace Orchard.Indexing.Services {
// retrieve not yet processed tasks // retrieve not yet processed tasks
var taskRecords = lastIndexUtc == null var taskRecords = lastIndexUtc == null
? _repository.Fetch(x => true).ToArray() ? _repository.Fetch(x => true).ToArray()
: _repository.Fetch(x => x.CreatedUtc > lastIndexUtc).ToArray(); : _repository.Fetch(x => x.CreatedUtc >= lastIndexUtc).ToArray(); // CreatedUtc and lastIndexUtc might be equal if a content item is created in a background task
// nothing to do ? // nothing to do ?

View File

@@ -104,12 +104,20 @@ namespace Orchard.Data {
private Hash ComputeHash() { private Hash ComputeHash() {
var hash = new Hash(); var hash = new Hash();
// Shell settings physical location
// The nhibernate configuration stores the physical path to the SqlCe database
// so we need to include the physical location as part of the hash key, so that
// xcopy migrations work as expected.
var pathName = GetPathName(_shellSettings.Name);
hash.AddString(_appDataFolder.MapPath(pathName).ToLowerInvariant());
// Shell settings data
hash.AddString(_shellSettings.DataProvider); hash.AddString(_shellSettings.DataProvider);
hash.AddString(_shellSettings.DataTablePrefix); hash.AddString(_shellSettings.DataTablePrefix);
hash.AddString(_shellSettings.DataConnectionString); hash.AddString(_shellSettings.DataConnectionString);
hash.AddString(_shellSettings.Name); hash.AddString(_shellSettings.Name);
// We need to hash the assemnly names, record names and property names // Assembly names, record names and property names
foreach (var tableName in _shellBlueprint.Records.Select(x => x.TableName)) { foreach (var tableName in _shellBlueprint.Records.Select(x => x.TableName)) {
hash.AddString(tableName); hash.AddString(tableName);
} }

View File

@@ -1,6 +1,5 @@
using System; using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Reflection; using System.Reflection;
using Autofac; using Autofac;
using Autofac.Core; using Autofac.Core;
@@ -8,7 +7,7 @@ using Module = Autofac.Module;
namespace Orchard.Localization { namespace Orchard.Localization {
public class LocalizationModule : Module { public class LocalizationModule : Module {
private readonly IDictionary<string, Localizer> _localizerCache; private readonly ConcurrentDictionary<string, Localizer> _localizerCache;
public LocalizationModule() { public LocalizationModule() {
_localizerCache = new ConcurrentDictionary<string, Localizer>(); _localizerCache = new ConcurrentDictionary<string, Localizer>();
@@ -26,14 +25,8 @@ namespace Orchard.Localization {
var scope = registration.Activator.LimitType.FullName; var scope = registration.Activator.LimitType.FullName;
registration.Activated += (sender, e) => { registration.Activated += (sender, e) => {
if (_localizerCache.ContainsKey(scope)) { var localizer = _localizerCache.GetOrAdd(scope, key => LocalizationUtilities.Resolve(e.Context, scope));
userProperty.SetValue(e.Instance, _localizerCache[scope], null); userProperty.SetValue(e.Instance, localizer, null);
}
else {
var localizer = LocalizationUtilities.Resolve(e.Context, scope);
_localizerCache.Add(scope, localizer);
userProperty.SetValue(e.Instance, localizer, null);
}
}; };
} }
} }

View File

@@ -11,7 +11,7 @@ using Module = Autofac.Module;
namespace Orchard.Logging { namespace Orchard.Logging {
public class LoggingModule : Module { public class LoggingModule : Module {
private readonly IDictionary<string, ILogger> _loggerCache; private readonly ConcurrentDictionary<string, ILogger> _loggerCache;
public LoggingModule() { public LoggingModule() {
_loggerCache = new ConcurrentDictionary<string, ILogger>(); _loggerCache = new ConcurrentDictionary<string, ILogger>();
@@ -63,14 +63,8 @@ namespace Orchard.Logging {
yield return (ctx, instance) => { yield return (ctx, instance) => {
string component = componentType.ToString(); string component = componentType.ToString();
if (_loggerCache.ContainsKey(component)) { var logger = _loggerCache.GetOrAdd(component, key => ctx.Resolve<ILogger>(new TypedParameter(typeof(Type), componentType)));
propertyInfo.SetValue(instance, _loggerCache[component], null); propertyInfo.SetValue(instance, logger, null);
}
else {
var propertyValue = ctx.Resolve<ILogger>(new TypedParameter(typeof(Type), componentType));
_loggerCache.Add(component, propertyValue);
propertyInfo.SetValue(instance, propertyValue, null);
}
}; };
} }
} }