<commit_before>﻿using System;
using System.Collections.Specialized;
using System.Linq;
using Sdl.Web.Common.Logging;
using Sdl.Web.Common.Models;
using Sdl.Web.Modules.Search.Models;
using Sdl.Web.Modules.Search.Providers;
using Sdl.Web.Mvc.Configuration;

namespace Sdl.Web.Modules.Search.Controllers
{
    public class SearchController : BaseEntityController
    {
        protected ISearchProvider SearchProvider { get; set; }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="searchProvider">The Search Provider to use. Set using Dependency Injection (ISearchProvider interface must be defined in Unity.config)</param>
        public SearchController(ISearchProvider searchProvider)
        {
            SearchProvider = searchProvider;
        }

        /// <summary>
        /// Enrich the SearchQuery View Model with request querystring parameters and populate the results using a configured Search Provider,.
        /// </summary>
        protected override ViewModel EnrichModel(ViewModel model)
        {
            using (new Tracer(model))
            {
                base.EnrichModel(model);

                SearchQuery searchQuery = model as SearchQuery;
                if (searchQuery == null || !searchQuery.GetType().IsGenericType)
                {
                    throw new DxaSearchException(String.Format("Unexpected View Model: '{0}'. Expecting type SearchQuery<T>.", model));
                }

                NameValueCollection queryString = Request.QueryString;
                // Map standard query string parameters
                searchQuery.QueryText = queryString["q"];
                searchQuery.Start = queryString.AllKeys.Contains("start") ? Convert.ToInt32(queryString["start"]) : 1;
                // To allow the Serch Provider to use additional query string parameters:
                searchQuery.QueryStringParameters = queryString;

                Type searchItemType = searchQuery.GetType().GetGenericArguments()[0];
                SearchProvider.ExecuteQuery(searchQuery, searchItemType, WebRequestContext.Localization);

                return searchQuery;
            }
        }
    }
}<commit_msg>TSI-82 Fixed issue that first search result was skipped because Solr's start index is 0 based.<commit_after>﻿using System;
using System.Collections.Specialized;
using System.Linq;
using Sdl.Web.Common.Logging;
using Sdl.Web.Common.Models;
using Sdl.Web.Modules.Search.Models;
using Sdl.Web.Modules.Search.Providers;
using Sdl.Web.Mvc.Configuration;

namespace Sdl.Web.Modules.Search.Controllers
{
    public class SearchController : BaseEntityController
    {
        protected ISearchProvider SearchProvider { get; set; }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="searchProvider">The Search Provider to use. Set using Dependency Injection (ISearchProvider interface must be defined in Unity.config)</param>
        public SearchController(ISearchProvider searchProvider)
        {
            SearchProvider = searchProvider;
        }

        /// <summary>
        /// Enrich the SearchQuery View Model with request querystring parameters and populate the results using a configured Search Provider,.
        /// </summary>
        protected override ViewModel EnrichModel(ViewModel model)
        {
            using (new Tracer(model))
            {
                base.EnrichModel(model);

                SearchQuery searchQuery = model as SearchQuery;
                if (searchQuery == null || !searchQuery.GetType().IsGenericType)
                {
                    throw new DxaSearchException(String.Format("Unexpected View Model: '{0}'. Expecting type SearchQuery<T>.", model));
                }

                NameValueCollection queryString = Request.QueryString;
                // Map standard query string parameters
                searchQuery.QueryText = queryString["q"];
                searchQuery.Start = queryString.AllKeys.Contains("start") ? Convert.ToInt32(queryString["start"]) : 0;
                // To allow the Serch Provider to use additional query string parameters:
                searchQuery.QueryStringParameters = queryString;

                Type searchItemType = searchQuery.GetType().GetGenericArguments()[0];
                SearchProvider.ExecuteQuery(searchQuery, searchItemType, WebRequestContext.Localization);

                return searchQuery;
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.08832035595105674, 'fraction_numerical': 0.0028921023359288096, 'mean_word_length': 2.3402674591381873, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4146900', 'n_tokens_mistral': 1106, 'n_tokens_neox': 1049, 'n_words': 285}