mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-01-19 17:51:45 +08:00
Adds ability to configure field indexing options (#8173)
This commit is contained in:
committed by
Sébastien Ros
parent
c491990a0e
commit
4d9a3ccaad
@@ -32,7 +32,8 @@ namespace Orchard.Indexing.Handlers {
|
||||
// part fields
|
||||
foreach ( var part in infosetPart.ContentItem.Parts ) {
|
||||
foreach ( var field in part.PartDefinition.Fields ) {
|
||||
if (!field.Settings.GetModel<FieldIndexing>().Included) {
|
||||
var indexingSettings = field.Settings.GetModel<FieldIndexing>();
|
||||
if (!indexingSettings.Included) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -62,16 +63,17 @@ namespace Orchard.Indexing.Handlers {
|
||||
|
||||
var typeCode = Type.GetTypeCode(t);
|
||||
|
||||
IDocumentIndex documentIndex = null;
|
||||
switch (typeCode) {
|
||||
case TypeCode.Empty:
|
||||
case TypeCode.Object:
|
||||
case TypeCode.DBNull:
|
||||
case TypeCode.String:
|
||||
case TypeCode.Char:
|
||||
context.DocumentIndex.Add(indexName, Convert.ToString(value)).RemoveTags().Analyze();
|
||||
documentIndex = context.DocumentIndex.Add(indexName, Convert.ToString(value));
|
||||
break;
|
||||
case TypeCode.Boolean:
|
||||
context.DocumentIndex.Add(indexName, Convert.ToBoolean(value));
|
||||
documentIndex = context.DocumentIndex.Add(indexName, Convert.ToBoolean(value));
|
||||
break;
|
||||
case TypeCode.SByte:
|
||||
case TypeCode.Int16:
|
||||
@@ -80,17 +82,35 @@ namespace Orchard.Indexing.Handlers {
|
||||
case TypeCode.UInt32:
|
||||
case TypeCode.Int64:
|
||||
case TypeCode.UInt64:
|
||||
context.DocumentIndex.Add(indexName, Convert.ToInt32(value));
|
||||
documentIndex = context.DocumentIndex.Add(indexName, Convert.ToInt32(value));
|
||||
break;
|
||||
case TypeCode.Single:
|
||||
case TypeCode.Double:
|
||||
case TypeCode.Decimal:
|
||||
context.DocumentIndex.Add(indexName, Convert.ToDouble(value));
|
||||
documentIndex = context.DocumentIndex.Add(indexName, Convert.ToDouble(value));
|
||||
break;
|
||||
case TypeCode.DateTime:
|
||||
context.DocumentIndex.Add(indexName, Convert.ToDateTime(value));
|
||||
documentIndex = context.DocumentIndex.Add(indexName, Convert.ToDateTime(value));
|
||||
break;
|
||||
}
|
||||
|
||||
if(documentIndex == null) {
|
||||
// Protection against none of the case statements above being matched
|
||||
return;
|
||||
}
|
||||
|
||||
if (indexingSettings.Stored) {
|
||||
documentIndex.Store();
|
||||
}
|
||||
|
||||
if (indexingSettings.Analyzed) {
|
||||
documentIndex.Analyze();
|
||||
}
|
||||
|
||||
if (indexingSettings.TagsRemoved) {
|
||||
documentIndex.RemoveTags();
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
$(".indexing-controlling-checkbox").change(function () {
|
||||
$("[data-indexing-controlled-by*='" + $(this).attr("name") + "']").toggle($(this).prop("checked"));
|
||||
}).trigger("change");
|
||||
12
src/Orchard.Web/Modules/Orchard.Indexing/Scripts/Web.config
Normal file
12
src/Orchard.Web/Modules/Orchard.Indexing/Scripts/Web.config
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<system.webServer>
|
||||
<staticContent>
|
||||
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" />
|
||||
</staticContent>
|
||||
<handlers accessPolicy="Script,Read">
|
||||
<!-- For any request to a file exists on disk, return it via native http module. AccessPolicy="Script" above is to allow for a managed 404 page. -->
|
||||
<add name="StaticFile" path="*" verb="*" modules="StaticFileModule" preCondition="integratedMode" resourceType="File" requireAccess="Read" />
|
||||
</handlers>
|
||||
</system.webServer>
|
||||
</configuration>
|
||||
@@ -66,13 +66,19 @@ namespace Orchard.Indexing.Settings {
|
||||
|
||||
public override IEnumerable<TemplateViewModel> PartFieldEditorUpdate(ContentPartFieldDefinitionBuilder builder, IUpdateModel updateModel) {
|
||||
var previous = builder.Current.Settings.GetModel<FieldIndexing>();
|
||||
|
||||
|
||||
var model = new FieldIndexing();
|
||||
updateModel.TryUpdateModel(model, "FieldIndexing", null, null);
|
||||
builder.WithSetting("FieldIndexing.Included", model.Included ? true.ToString() : null);
|
||||
builder.WithSetting("FieldIndexing.Stored", model.Stored.ToString());
|
||||
builder.WithSetting("FieldIndexing.Analyzed", model.Analyzed.ToString());
|
||||
builder.WithSetting("FieldIndexing.TagsRemoved", model.TagsRemoved.ToString());
|
||||
|
||||
// create indexing tasks only if settings have changed
|
||||
if (model.Included != previous.Included) {
|
||||
if (model.Included != previous.Included ||
|
||||
model.Stored != previous.Stored ||
|
||||
model.Analyzed != previous.Analyzed ||
|
||||
model.TagsRemoved != previous.TagsRemoved) {
|
||||
|
||||
// if a field setting has changed, all existing content items need to be re-indexed
|
||||
CreateIndexingTasks();
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
namespace Orchard.Indexing.Settings {
|
||||
public class FieldIndexing {
|
||||
public FieldIndexing() {
|
||||
Analyzed = true;
|
||||
TagsRemoved = true;
|
||||
}
|
||||
|
||||
public bool Included { get; set; }
|
||||
public bool Stored { get; set; }
|
||||
public bool Analyzed { get; set; }
|
||||
public bool TagsRemoved { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,30 @@
|
||||
@model Orchard.Indexing.Settings.FieldIndexing
|
||||
|
||||
@{
|
||||
Script.Include("FieldIndexing.js").AtFoot();
|
||||
}
|
||||
|
||||
<fieldset>
|
||||
<legend>@T("Indexing")</legend>
|
||||
<div>
|
||||
@Html.EditorFor(m=>m.Included)
|
||||
@Html.CheckBoxFor(m => m.Included, new { @class = "indexing-controlling-checkbox" })
|
||||
<label for="@Html.FieldIdFor(m => m.Included)" class="forcheckbox">@T("Include in the index")</label>
|
||||
@Html.ValidationMessageFor(m => m.Included)
|
||||
<span class="hint">@T("Check to add content of this field in the selected indexes.")</span>
|
||||
</div>
|
||||
<div data-indexing-controlled-by="@Html.NameFor(m => m.Included)">
|
||||
@Html.CheckBoxFor(m => m.Stored)
|
||||
<label for="@Html.FieldIdFor(m => m.Stored)" class="forcheckbox">@T("Store the value in the index so that it can be retrived")</label>
|
||||
@Html.ValidationMessageFor(m => m.Stored)
|
||||
</div>
|
||||
<div data-indexing-controlled-by="@Html.NameFor(m => m.Included)">
|
||||
@Html.CheckBoxFor(m => m.Analyzed)
|
||||
<label for="@Html.FieldIdFor(m => m.Analyzed)" class="forcheckbox">@T("Analyze and tokenize the value")</label>
|
||||
@Html.ValidationMessageFor(m => m.Analyzed)
|
||||
</div>
|
||||
<div data-indexing-controlled-by="@Html.NameFor(m => m.Included)">
|
||||
@Html.CheckBoxFor(m => m.TagsRemoved)
|
||||
<label for="@Html.FieldIdFor(m => m.TagsRemoved)" class="forcheckbox">@T("Remove HTML tags from the value that is indexed")</label>
|
||||
@Html.ValidationMessageFor(m => m.TagsRemoved)
|
||||
</div>
|
||||
</fieldset>
|
||||
Reference in New Issue
Block a user