private void GetSearchResults(string searchKeyword) { string indexName = StringUtil.GetString(IndexName, CommonText.get("Search Index")); // Decode the search string query string string searchStr = searchKeyword; // Category is provided if a visitor wants to see all the results for a given area of the site string categoryStr = Server.UrlDecode(WebUtil.GetQueryString("categoryStr")); baseURL = string.Format("{0}?searchStr={1}&categoryStr=", LinkManager.GetItemUrl(Sitecore.Context.Item), searchStr); // Be sure we have an empty search string at very least (avoid null) if (searchKeyword == null) { searchKeyword = string.Empty; } // If the visitor provided no criteria, don't bother searching if (searchKeyword == string.Empty) { lblSearchString.Text = CommonText.get("search criteria") + CommonText.get("search no criteria"); } else { // Remind the visitor what they provided as search criteria lblSearchString.Text = CommonText.get("search criteria") + searchKeyword; // Display the search results gvSearchResults.DataSourceID = objDSResultContent.UniqueID; gvSearchResults.DataBind(); } }
protected void txtCriteria_TextChanged(object sender, EventArgs e) { if (txtCriteria.Text != CommonText.get("search")) { performSearch(); } }
protected void btnSearch_Click(object sender, ImageClickEventArgs e) { if (txtCriteria.Text != CommonText.get("search")) { performSearch(); } }
protected void Page_Load(object sender, EventArgs e) { masterDB = Factory.GetDatabase("master"); if (!IsPostBack) { txtCriteria.Text = CommonText.get("search"); } }
protected void Page_Load(object sender, EventArgs e) { int pageSize = 10; //default page size searchKeyword = Server.UrlDecode(WebUtil.GetQueryString("searchStr")); if (!IsPostBack) { txtKeywords.Text = searchKeyword; if (int.TryParse(CommonText.get("Search Result Page Size"), out pageSize)) { gvSearchResults.PageSize = pageSize; } GetSearchResults(searchKeyword); } }
public List <Item> GetSearchResultsUsingQuery(string searchString) { //Getting index from the web.config List <Item> returnValues = new List <Item>(); SearchIndexName = StringUtil.GetString(SearchIndexName, CommonText.get("Search Index"));; ISearchIndex searchIndex = null; try { searchIndex = ContentSearchManager.GetIndex(SearchIndexName); } catch (Exception ex) { Log.Error(ex.Message, ex); return(null); } using (var context = searchIndex.CreateSearchContext()) { IQueryable <SearchUIResultItem> q = context.GetQueryable <SearchUIResultItem>(); List <SearchResults <SearchUIResultItem> > LstResults = new List <SearchResults <SearchUIResultItem> >(); // //Query approach q = BuildSearchQuery(searchString, q); LstResults.Add(q.GetResults()); List <string> uniqueIds = new List <string>(); foreach (var results in LstResults) { var sitecoreItem = results.Hits.Select(x => x.Document); foreach (var item in sitecoreItem) { Item item1 = item.GetItem(); if (item1 != null && !uniqueIds.Contains(item1.ID.ToString())) { returnValues.Add(item1); uniqueIds.Add(item1.ID.ToString()); } } } return(returnValues); } }