/// <summary> /// Perform search. /// </summary> protected void Search() { if (StopProcessing) { // Do nothing } else { // Get query strings string searchText = QueryHelper.GetString("searchtext", ""); bool searchTextIsNotEmptyOrRequired = (!SearchTextRequired || !String.IsNullOrEmpty(searchText)); bool searchAllowed = SearchOnEachPageLoad || QueryHelper.Contains("searchtext"); if ((searchTextIsNotEmptyOrRequired || !SearchHelper.SearchOnlyWhenContentPresent) && searchAllowed) { string searchMode = QueryHelper.GetString("searchMode", ""); SearchModeEnum searchModeEnum = CMS.ISearchEngine.SearchHelper.GetSearchModeEnum(searchMode); // Get current culture string culture = CultureCode; if (string.IsNullOrEmpty(culture)) { culture = ValidationHelper.GetString(ViewState["CultureCode"], CMSContext.PreferredCultureCode); } // Get default culture string defaultCulture = CultureHelper.GetDefaultCulture(CMSContext.CurrentSiteName); // Resolve path string path = Path; if (!string.IsNullOrEmpty(path)) { path = CMSContext.ResolveCurrentPath(Path); } if (CMSContext.ViewMode == ViewModeEnum.LiveSite) { // Log on site keywords if (AnalyticsHelper.JavascriptLoggingEnabled(CMSContext.CurrentSiteName)) { ScriptHelper.RegisterWebServiceCallFunction(Page); string script = "WebServiceCall('" + URLHelper.GetAbsoluteUrl("~/CMSPages/WebAnalyticsService.asmx") + "','LogSearch', '{\"keyword\":\"" + ScriptHelper.GetString(ScriptHelper.GetString(searchText, false), false) + "\"}')"; ScriptHelper.RegisterStartupScript(Page, typeof(string), "logSearch", script, true); } else { AnalyticsHelper.LogOnSiteSearchKeywords(CMSContext.CurrentSiteName, CMSContext.CurrentAliasPath, culture, searchText, 0, 1); } } // Prepare search text searchText = SearchHelper.CombineSearchCondition(searchText, SearchCondition + FilterSearchCondition, searchModeEnum, SearchOptions, DocumentTypes, culture, defaultCulture, CombineWithDefaultCulture); // Get positions and ranges for search method int startPosition = 0; int numberOfProceeded = 100; int displayResults = 100; if (pgr.PageSize != 0 && pgr.GroupSize != 0) { startPosition = (pgr.CurrentPage - 1) * pgr.PageSize; numberOfProceeded = (((pgr.CurrentPage / pgr.GroupSize) + 1) * pgr.PageSize * pgr.GroupSize) + pgr.PageSize; displayResults = pgr.PageSize; } if ((MaxResults > 0) && (numberOfProceeded > MaxResults)) { numberOfProceeded = MaxResults; } // Combine regular search sort with filter sort string srt = ValidationHelper.GetString(SearchSort, String.Empty).Trim(); string filterSrt = ValidationHelper.GetString(FilterSearchSort, String.Empty).Trim(); if (!String.IsNullOrEmpty(filterSrt)) { if (!String.IsNullOrEmpty(srt)) { srt += ", "; } srt += filterSrt; } // Prepare parameters SearchParameters parameters = new SearchParameters() { SearchFor = searchText, SearchSort = SearchHelper.GetSort(srt), Path = path, ClassNames = DocumentTypes, CurrentCulture = culture, DefaultCulture = defaultCulture, CombineWithDefaultCulture = CombineWithDefaultCulture, CheckPermissions = CheckPermissions, SearchInAttachments = SearchInAttachments, User = (UserInfo)CMSContext.CurrentUser, SearchIndexes = Indexes, StartingPosition = startPosition, DisplayResults = displayResults, NumberOfProcessedResults = numberOfProceeded, NumberOfResults = 0, AttachmentWhere = AttachmentsWhere, AttachmentOrderBy = AttachmentsOrderBy, BlockFieldOnlySearch = BlockFieldOnlySearch, }; // Search DataSet results = SearchHelper.Search(parameters); int numberOfResults = parameters.NumberOfResults; if ((MaxResults > 0) && (numberOfResults > MaxResults)) { numberOfResults = MaxResults; } // Fill repeater with results repSearchResults.DataSource = results; repSearchResults.PagerForceNumberOfResults = numberOfResults; this.PagerForceNumberOfResults = numberOfResults; repSearchResults.DataBind(); // Call page binding event if (OnPageBinding != null) { OnPageBinding(this, null); } // Show now results found ? if (numberOfResults == 0) { if (ShowParsingErrors) { Exception searchError = SearchHelper.LastSmartSearchError; if (searchError != null) { ShowError(GetString("smartsearch.searcherror") + " " + searchError.Message); } } lblNoResults.Text = NoResultsText; lblNoResults.Visible = true; } } else { Visible = false; } // Invoke search completed event if (OnSearchCompleted != null) { OnSearchCompleted(Visible); } } }
/// <summary> /// Perform search. /// </summary> protected override void OnPreRender(EventArgs e) { // Check whether current request is not postback if (!RequestHelper.IsPostBack()) { // Get current search text from query string string searchText = QueryHelper.GetString("searchtext", ""); // Check whether search text is defined if (!string.IsNullOrEmpty(searchText)) { // Get current search mode from query string string searchMode = QueryHelper.GetString("searchmode", ""); SearchModeEnum searchModeEnum = ISearchHelper.GetSearchModeEnum(searchMode); // Get current index id int indexId = QueryHelper.GetInteger("indexId", 0); // Get current index info object SearchIndexInfo sii = SearchIndexInfoProvider.GetSearchIndexInfo(indexId); // Check whether index info exists if (sii != null) { // Keep search text in search textbox //txtSearchFor.Text = searchText; searchText = SearchHelper.CombineSearchCondition(searchText, null, searchModeEnum, SearchOptionsEnum.FullSearch, null, null, null, false); // Get positions and ranges for search method int startPosition = 0; int numberOfProceeded = 100; int displayResults = 100; if (pgrSearch.PageSize != 0 && pgrSearch.GroupSize != 0) { startPosition = (pgrSearch.CurrentPage - 1) * pgrSearch.PageSize; numberOfProceeded = (((pgrSearch.CurrentPage / pgrSearch.GroupSize) + 1) * pgrSearch.PageSize * pgrSearch.GroupSize) + pgrSearch.PageSize; displayResults = pgrSearch.PageSize; } // Prepare parameters SearchParameters parameters = new SearchParameters() { SearchFor = searchText, SearchSort = null, Path = null, ClassNames = null, CurrentCulture = "##ALL##", DefaultCulture = null, CombineWithDefaultCulture = false, CheckPermissions = false, SearchInAttachments = false, User = (UserInfo)CMSContext.CurrentUser, SearchIndexes = sii.IndexName, StartingPosition = startPosition, DisplayResults = displayResults, NumberOfProcessedResults = numberOfProceeded, NumberOfResults = 0, AttachmentWhere = null, AttachmentOrderBy = null, }; // Search DataSet results = SearchHelper.Search(parameters); // Fill repeater with results repSearchResults.DataSource = results; repSearchResults.PagerForceNumberOfResults = parameters.NumberOfResults; repSearchResults.DataBind(); // Show now results found ? if (parameters.NumberOfResults == 0) { lblNoResults.Text = "<br />" + GetString("srch.results.noresults"); lblNoResults.Visible = true; Exception searchError = SearchHelper.LastSmartSearchError; if (searchError != null) { pnlError.Visible = true; lblError.Text = GetString("smartsearch.searcherror") + " " + searchError.Message; } } } } } base.OnPreRender(e); }