mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Shifting SearchSettingsPart
This commit is contained in:
@@ -43,7 +43,7 @@ namespace Orchard.Search.Controllers {
|
||||
try {
|
||||
|
||||
searchHits = _searchService.Query(searchText, pager.Page, pager.PageSize,
|
||||
Services.WorkContext.CurrentSite.As<SearchSettingsPart>().Record.FilterCulture,
|
||||
Services.WorkContext.CurrentSite.As<SearchSettingsPart>().FilterCulture,
|
||||
searchSettingsPart.SearchIndex,
|
||||
searchSettingsPart.SearchedFields,
|
||||
searchHit => searchHit);
|
||||
|
@@ -57,7 +57,7 @@ namespace Orchard.Search.Controllers {
|
||||
try {
|
||||
|
||||
searchHits = _searchService.Query(q, pager.Page, pager.PageSize,
|
||||
Services.WorkContext.CurrentSite.As<SearchSettingsPart>().Record.FilterCulture,
|
||||
Services.WorkContext.CurrentSite.As<SearchSettingsPart>().FilterCulture,
|
||||
searchSettingPart.SearchIndex,
|
||||
searchSettingPart.SearchedFields,
|
||||
searchHit => searchHit);
|
||||
|
@@ -8,10 +8,14 @@ using Orchard.ContentManagement.Handlers;
|
||||
namespace Orchard.Search.Handlers {
|
||||
[UsedImplicitly]
|
||||
public class SearchSettingsPartHandler : ContentHandler {
|
||||
public SearchSettingsPartHandler(IRepository<SearchSettingsPartRecord> repository) {
|
||||
public SearchSettingsPartHandler() {
|
||||
T = NullLocalizer.Instance;
|
||||
Filters.Add(new ActivatingFilter<SearchSettingsPart>("Site"));
|
||||
Filters.Add(StorageFilter.For(repository));
|
||||
|
||||
OnInitializing<SearchSettingsPart>((context, part) => {
|
||||
part.FilterCulture = false;
|
||||
part.SearchedFields = new [] {"body, title"};
|
||||
});
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
|
@@ -1,28 +1,13 @@
|
||||
using System.Linq;
|
||||
using Orchard.ContentManagement.MetaData;
|
||||
using Orchard.Data;
|
||||
using Orchard.ContentManagement.MetaData;
|
||||
using Orchard.Data.Migration;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Indexing;
|
||||
using Orchard.Search.Models;
|
||||
|
||||
namespace Orchard.Search {
|
||||
public class SearchDataMigration : DataMigrationImpl {
|
||||
private readonly IRepository<SearchSettingsPartRecord> _searchSettingsPartRecordRepository;
|
||||
|
||||
public SearchDataMigration(IRepository<SearchSettingsPartRecord> searchSettingsPartRecordRepository) {
|
||||
_searchSettingsPartRecordRepository = searchSettingsPartRecordRepository;
|
||||
}
|
||||
|
||||
public int Create() {
|
||||
|
||||
SchemaBuilder.CreateTable("SearchSettingsPartRecord", table => table
|
||||
.ContentPartRecord()
|
||||
.Column<bool>("FilterCulture")
|
||||
.Column<string>("SearchedFields", c => c.Unlimited())
|
||||
.Column<string>("SearchIndex")
|
||||
);
|
||||
|
||||
ContentDefinitionManager.AlterTypeDefinition("SearchForm",
|
||||
cfg => cfg
|
||||
.WithPart("SearchFormPart")
|
||||
@@ -36,14 +21,9 @@ namespace Orchard.Search {
|
||||
|
||||
public int UpdateFrom1() {
|
||||
SchemaBuilder.AlterTable("SearchSettingsPartRecord", table => table
|
||||
.AddColumn<string>("SearchIndex")
|
||||
.AddColumn<string>("SearchIndex", c => c.WithDefault("Search"))
|
||||
);
|
||||
|
||||
var settings = _searchSettingsPartRecordRepository.Table.FirstOrDefault();
|
||||
if (settings != null) {
|
||||
settings.SearchIndex = "Search";
|
||||
}
|
||||
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
@@ -2,20 +2,20 @@
|
||||
using Orchard.ContentManagement;
|
||||
|
||||
namespace Orchard.Search.Models {
|
||||
public class SearchSettingsPart : ContentPart<SearchSettingsPartRecord> {
|
||||
public class SearchSettingsPart : ContentPart {
|
||||
public string[] SearchedFields {
|
||||
get { return Record.SearchedFields.Split(new[] {',', ' '}, StringSplitOptions.RemoveEmptyEntries); }
|
||||
set { Record.SearchedFields = String.Join(", ", value); }
|
||||
get { return (Retrieve<string>("SearchedFields") ?? "").Split(new[] {',', ' '}, StringSplitOptions.RemoveEmptyEntries); }
|
||||
set { Store("SearchedFields", String.Join(", ", value)); }
|
||||
}
|
||||
|
||||
public bool FilterCulture {
|
||||
get { return Record.FilterCulture; }
|
||||
set { Record.FilterCulture = value; }
|
||||
get { return this.Retrieve(x => x.FilterCulture); }
|
||||
set { this.Store(x => x.FilterCulture, value); }
|
||||
}
|
||||
|
||||
public string SearchIndex {
|
||||
get { return Record.SearchIndex; }
|
||||
set { Record.SearchIndex = value; }
|
||||
get { return this.Retrieve(x => x.SearchIndex); }
|
||||
set { this.Store(x => x.SearchIndex, value); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,17 +0,0 @@
|
||||
using Orchard.ContentManagement.Records;
|
||||
using Orchard.Data.Conventions;
|
||||
|
||||
namespace Orchard.Search.Models {
|
||||
public class SearchSettingsPartRecord : ContentPartRecord {
|
||||
public SearchSettingsPartRecord() {
|
||||
FilterCulture = false;
|
||||
SearchedFields = "body, title";
|
||||
}
|
||||
|
||||
public virtual bool FilterCulture { get; set; }
|
||||
|
||||
[StringLengthMax]
|
||||
public virtual string SearchedFields { get; set; }
|
||||
public virtual string SearchIndex { get; set; }
|
||||
}
|
||||
}
|
@@ -77,7 +77,6 @@
|
||||
<Compile Include="Migrations.cs" />
|
||||
<Compile Include="Drivers\SearchSettingsPartDriver.cs" />
|
||||
<Compile Include="Models\SearchSettingsPart.cs" />
|
||||
<Compile Include="Models\SearchSettingsPartRecord.cs" />
|
||||
<Compile Include="Routes.cs" />
|
||||
<Compile Include="Handlers\SearchSettingsPartHandler.cs" />
|
||||
<Compile Include="Services\ISearchService.cs" />
|
||||
|
@@ -1,5 +1,5 @@
|
||||
@using Orchard.Search.ViewModels
|
||||
@model Orchard.Search.ViewModels.SearchSettingsViewModel
|
||||
@model SearchSettingsViewModel
|
||||
@{
|
||||
Script.Require("jQuery");
|
||||
|
||||
|
@@ -135,7 +135,17 @@ namespace Upgrade.Controllers {
|
||||
});
|
||||
|
||||
_upgradeService.ExecuteReader("DROP TABLE " + _upgradeService.GetPrefixedTableName("Orchard_Messaging_MessageSettingsPartRecord"), null);
|
||||
|
||||
|
||||
// SearchSettingsPartRecord
|
||||
_upgradeService.ExecuteReader("SELECT * FROM " + _upgradeService.GetPrefixedTableName("Orchard_Search_SearchSettingsPartRecord"),
|
||||
(reader, connection) => {
|
||||
site.As<InfosetPart>().Store("SearchSettingsPart", "SearchedFields", (string)reader["SearchedFields"]);
|
||||
site.As<InfosetPart>().Store("SearchSettingsPart", "FilterCulture", (bool)reader["FilterCulture"]);
|
||||
site.As<InfosetPart>().Store("SearchSettingsPart", "SearchIndex", (string)reader["SearchIndex"]);
|
||||
});
|
||||
|
||||
_upgradeService.ExecuteReader("DROP TABLE " + _upgradeService.GetPrefixedTableName("Orchard_Search_SearchSettingsPartRecord"), null);
|
||||
|
||||
_orchardServices.Notifier.Information(T("Site Settings migrated successfully"));
|
||||
|
||||
return View();
|
||||
|
Reference in New Issue
Block a user