Skip to content

Commit

Permalink
Merge pull request #6034 from Mostafa-Moafi/Issue6033
Browse files Browse the repository at this point in the history
Add MaximumPageSize const property for limit page size
  • Loading branch information
valadas authored May 21, 2024
2 parents 56665a9 + 907ff3f commit 1e04695
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace DotNetNuke.Web.InternalServices
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Data;
using DotNetNuke.Entities.Controllers;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Definitions;
using DotNetNuke.Entities.Tabs;
Expand All @@ -37,7 +38,6 @@ public class SearchServiceController : DnnApiController
private const string ModuleTitleCacheKey = "SearchModuleTabTitle_{0}";
private const CacheItemPriority ModuleTitleCachePriority = CacheItemPriority.Normal;
private const int ModuleTitleCacheTimeOut = 20;

private static readonly Regex GroupedBasicViewRegex = new Regex("userid(/|\\|=)(\\d+)", RegexOptions.IgnoreCase | RegexOptions.Compiled);

private int htmlModuleDefitionId;
Expand Down Expand Up @@ -125,13 +125,19 @@ public HttpResponseMessage Search(string search, string culture, int pageIndex,
var moduleDefids = GetSearchModuleDefIds(settings, contentSources);
var portalIds = this.GetSearchPortalIds(settings, -1);
var userSearchTypeId = SearchHelper.Instance.GetSearchTypeByName("user").SearchTypeId;
var maximumPageSize = HostController.Instance.GetInteger("Search_MaxResultPerPage", 100);

var more = false;
var totalHits = 0;
var results = new List<GroupedDetailView>();
if (portalIds.Any() && searchTypeIds.Any() &&
(!string.IsNullOrEmpty(cleanedKeywords) || tags.Any()))
{
if (pageSize > maximumPageSize)
{
pageSize = maximumPageSize;
}

var query = new SearchQuery
{
KeyWords = cleanedKeywords,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class BasicSearchSettingsPanelBody extends Component {
basicSearchSettings: undefined,
error: {
minlength: false,
maxlength: false
maxlength: false,
maxresult: false
},
triedToSubmit: false
};
Expand Down Expand Up @@ -72,6 +73,13 @@ class BasicSearchSettingsPanelBody extends Component {
error["minlength"] = false;
}

if (!re.test(basicSearchSettings[key]) && key === "MaxResultPerPage") {
error["maxresult"] = true;
}
else if (re.test(basicSearchSettings[key]) && key === "MaxResultPerPage") {
error["maxresult"] = false;
}

if (key === "MaxWordLength" && (!re.test(basicSearchSettings[key])
|| parseInt(basicSearchSettings["MinWordLength"]) >= parseInt(basicSearchSettings["MaxWordLength"]))) {
error["maxlength"] = true;
Expand Down Expand Up @@ -153,50 +161,94 @@ class BasicSearchSettingsPanelBody extends Component {
const {state} = this;
if (this.isHost()) {
if (state.basicSearchSettings) {
const columnOne = <div className="left-column" key="columnOneSearchSettingsPanel">
<InputGroup>
<Label
tooltipMessage={resx.get("lblIndexWordMinLength.Help")}
label={resx.get("lblIndexWordMinLength")}
extra={
<Tooltip
messages={[resx.get("GlobalSetting")]}
type="global"
style={{ float: "left", position: "static" }}
/>}
/>
<SingleLineInputWithError
inputStyle={{ margin: "0" }}
withLabel={false}
error={state.error.minlength && state.triedToSubmit}
errorMessage={resx.get("valIndexWordMinLengthRequired.Error")}
value={state.basicSearchSettings.MinWordLength}
onChange={this.onSettingChange.bind(this, "MinWordLength")}
style={{ width: "100%" }}
/>
</InputGroup>
<InputGroup>
<Label
tooltipMessage={resx.get("lblIndexWordMaxLength.Help")}
label={resx.get("lblIndexWordMaxLength")}
extra={
<Tooltip
messages={[resx.get("GlobalSetting")]}
type="global"
style={{ float: "left", position: "static" }}
/>}
/>
<SingleLineInputWithError
inputStyle={{ margin: "0" }}
withLabel={false}
error={state.error.maxlength && state.triedToSubmit}
errorMessage={resx.get("valIndexWordMaxLengthRequired.Error")}
value={state.basicSearchSettings.MaxWordLength}
onChange={this.onSettingChange.bind(this, "MaxWordLength")}
style={{ width: "100%" }}
/>
</InputGroup>
</div>;
const columnOne = (
<div
className="left-column"
key="columnOneSearchSettingsPanel"
>
<InputGroup>
<Label
tooltipMessage={resx.get("lblIndexWordMinLength.Help")}
label={resx.get("lblIndexWordMinLength")}
extra={
<Tooltip
messages={[resx.get("GlobalSetting")]}
type="global"
style={{ float: "left", position: "static" }}
/>
}
/>
<SingleLineInputWithError
inputStyle={{ margin: "0" }}
withLabel={false}
error={state.error.minlength && state.triedToSubmit}
errorMessage={resx.get(
"valIndexWordMinLengthRequired.Error"
)}
value={state.basicSearchSettings.MinWordLength}
onChange={this.onSettingChange.bind(
this,
"MinWordLength"
)}
style={{ width: "100%" }}
/>
</InputGroup>
<InputGroup>
<Label
tooltipMessage={resx.get("lblIndexWordMaxLength.Help")}
label={resx.get("lblIndexWordMaxLength")}
extra={
<Tooltip
messages={[resx.get("GlobalSetting")]}
type="global"
style={{ float: "left", position: "static" }}
/>
}
/>
<SingleLineInputWithError
inputStyle={{ margin: "0" }}
withLabel={false}
error={state.error.maxlength && state.triedToSubmit}
errorMessage={resx.get(
"valIndexWordMaxLengthRequired.Error"
)}
value={state.basicSearchSettings.MaxWordLength}
onChange={this.onSettingChange.bind(
this,
"MaxWordLength"
)}
style={{ width: "100%" }}
/>
</InputGroup>
<InputGroup>
<Label
tooltipMessage={resx.get("lblMaxResultPerPage.Help")}
label={resx.get("lblMaxResultPerPage")}
extra={
<Tooltip
messages={[resx.get("GlobalSetting")]}
type="global"
style={{ float: "left", position: "static" }}
/>
}
/>
<SingleLineInputWithError
inputStyle={{ margin: "0" }}
withLabel={false}
error={state.error.maxresult && state.triedToSubmit}
errorMessage={resx.get(
"valMaxResultPerPageRequired.Error"
)}
value={state.basicSearchSettings.MaxResultPerPage}
onChange={this.onSettingChange.bind(
this,
"MaxResultPerPage"
)}
style={{ width: "100%" }}
/>
</InputGroup>
</div>
);
const columnTwo = <div className="right-column" key="columnTwoSearchSettingsPanel">
<DropdownWithError
style={{ maxWidth: "100%" }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ public class UpdateBasicSearchSettingsRequest
{
public int MinWordLength { get; set; }

public int MaxWordLength { get; set; }

public int MaxWordLength { get; set; }

public int MaxResultPerPage { get; set; }

public bool AllowLeadingWildcard { get; set; }

public string SearchCustomAnalyzer { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1659,6 +1659,7 @@ public HttpResponseMessage GetBasicSearchSettings()
settings.DescriptionBoost = HostController.Instance.GetInteger(SearchDescriptionBoostSetting, DefaultSearchDescriptionBoost);
settings.AuthorBoost = HostController.Instance.GetInteger(SearchAuthorBoostSetting, DefaultSearchAuthorBoost);
settings.SearchIndexPath = Path.Combine(Globals.ApplicationMapPath, HostController.Instance.GetString("SearchFolder", @"App_Data\Search"));
settings.MaxResultPerPage = HostController.Instance.GetInteger("Search_MaxResultPerPage", 100);

SearchStatistics searchStatistics = this.GetSearchStatistics();
if (searchStatistics != null)
Expand Down Expand Up @@ -1714,12 +1715,25 @@ public HttpResponseMessage UpdateBasicSearchSettings(UpdateBasicSearchSettingsRe
string.Format(Localization.GetString("valIndexWordMaxLengthRequired.Error", Components.Constants.Constants.LocalResourcesFile)));
}

if (request.MaxResultPerPage == Null.NullInteger || request.MaxResultPerPage == 0)
{
return this.Request.CreateErrorResponse(
HttpStatusCode.BadRequest,
string.Format(Localization.GetString("valMaxResultPerPageRequired.Error", Components.Constants.Constants.LocalResourcesFile)));
}

var oldMinLength = HostController.Instance.GetInteger("Search_MinKeyWordLength", 3);
if (request.MinWordLength != oldMinLength)
{
HostController.Instance.Update("Search_MinKeyWordLength", request.MinWordLength.ToString());
}

var oldMaxResultPerPage = HostController.Instance.GetInteger("Search_MaxResultPerPage", 100);
if (request.MaxResultPerPage != oldMaxResultPerPage)
{
HostController.Instance.Update("Search_MaxResultPerPage", request.MaxResultPerPage.ToString());
}

var oldMaxLength = HostController.Instance.GetInteger("Search_MaxKeyWordLength", 255);
if (request.MaxWordLength != oldMaxLength)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1500,4 +1500,13 @@
<data name="plShowQuickModuleAddMenu.Text" xml:space="preserve">
<value>Show Quick Module Add Menu</value>
</data>
</root>
<data name="lblMaxResultPerPage" xml:space="preserve">
<value>Maximum Result Per Page</value>
</data>
<data name="lblMaxResultPerPage.Help" xml:space="preserve">
<value>Maximum result per page in search service</value>
</data>
<data name="valMaxResultPerPageRequired.Error" xml:space="preserve">
<value>Maximum result per page is required. Integer must be greater than 0.</value>
</data>
</root>

0 comments on commit 1e04695

Please sign in to comment.