Skip to content

Commit

Permalink
Better defaults for SearchController (#4493)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienros committed Oct 7, 2019
1 parent 77fd03b commit 2067a6e
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,29 +64,22 @@ public async Task<IActionResult> Index(string id, string q, PagerParameters page

if (!_luceneIndexProvider.Exists(indexName))
{
return NotFound();
}

if (string.IsNullOrWhiteSpace(q))
{
return View(new SearchIndexViewModel
{
Pager = pager,
IndexName = id,
ContentItems = Enumerable.Empty<ContentItem>()
});
Logger.LogInformation("Couldn't execute search. The search index doesn't exist.");
return BadRequest("Search is not configured.");
}

var luceneSettings = await _luceneIndexingService.GetLuceneSettingsAsync();

if (luceneSettings == null || luceneSettings?.DefaultSearchFields == null)
{
Logger.LogInformation("Couldn't execute search. No Lucene settings was defined.");
return BadRequest("Search is not configured.");
}

if (string.IsNullOrWhiteSpace(q))
{
return View(new SearchIndexViewModel
{
HasMoreResults = false,
Query = q,
Pager = pager,
IndexName = id,
ContentItems = Enumerable.Empty<ContentItem>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public override IDisplayResult Edit(LuceneSettings section, BuildEditorContext c
return Initialize<LuceneSettingsViewModel>("LuceneSettings_Edit", model =>
{
model.SearchIndex = section.SearchIndex;
model.SearchFields = String.Join(", ", section.DefaultSearchFields ?? new string[0]);
model.SearchFields = String.Join(", ", section.DefaultSearchFields ?? Array.Empty<string>());
model.SearchIndexes = _luceneIndexProvider.List();
}).Location("Content:2").OnGroup("search");
}
Expand Down
5 changes: 4 additions & 1 deletion src/OrchardCore.Modules/OrchardCore.Lucene/LuceneSettings.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
using System.Collections.Generic;
using Lucene.Net.Util;
using OrchardCore.Contents.Indexing;

namespace OrchardCore.Lucene
{
public class LuceneSettings
{
public static readonly string[] FullTextField = new string[] { IndexingConstants.FullTextKey };

public static string StandardAnalyzer = "standardanalyzer";

public static LuceneVersion DefaultVersion = LuceneVersion.LUCENE_48;

public string SearchIndex { get; set; }

public string[] DefaultSearchFields { get; set; } = new string[0];
public string[] DefaultSearchFields { get; set; } = FullTextField;

/// <summary>
/// Gets the list of indices and their settings.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Contents.Core\OrchardCore.Contents.Core.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Deployment.Abstractions\OrchardCore.Deployment.Abstractions.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.Admin.Abstractions\OrchardCore.Admin.Abstractions.csproj" />
<ProjectReference Include="..\..\OrchardCore\OrchardCore.ContentManagement.GraphQL\OrchardCore.ContentManagement.GraphQL.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ else
<label asp-for="SearchFields">@T["Default searched fields"]</label>
<input asp-for="SearchFields" class="form-control" />
<span asp-validation-for="SearchFields"></span>
<span class="hint">@T["A comma separated list of fields to use for search pages. (e.g., Content.ContentItem.DisplayText.Analyzed, Content.BodyAspect.Body)"]</span>
<span class="hint">@T["A comma separated list of fields to use for search pages. The default value is <code>Content.ContentItem.FullText</code>."]</span>
</fieldset>

0 comments on commit 2067a6e

Please sign in to comment.