public virtual ActionResult Search() { try { Stream req = Request.InputStream; req.Seek(0, System.IO.SeekOrigin.Begin); string json = new StreamReader(req).ReadToEnd(); SearchParameters searchParams = JsonConvert.DeserializeObject <SearchParameters>(json); IQSearchClient <SearchResultSet, SearchResult> search = new IQSearchClient <SearchResultSet, SearchResult>(); search.WithResultFilter(new SearchResultFilter { StartOfRange = searchParams.StartIndex, EndOfRange = searchParams.StartIndex + searchParams.Count, IsHighlightingEnabled = true }); var fields = new List <string>(); var values = new List <object>(); if (searchParams.PublicationId != null) { fields.Add("publicationId"); values.Add(new DefaultTermValue(searchParams.PublicationId.Value.ToString())); } fields.Add("dynamic.FISHDITADLVRREMOTESTATUS.lng.element"); fields.Add($"content.{CultureInfo.GetCultureInfo(searchParams.Language).EnglishName.ToLower()}"); values.Add(new DefaultTermValue("VDITADLVRREMOTESTATUSONLINE")); string searchQuery = searchParams.SearchQuery; Match match = RegexpDoubleQuotes.Match(searchQuery); if (match.Success) { searchQuery = match.Groups[1].Value; } values.Add(new DefaultTermValue(searchQuery, TermTypes.Exact)); var results = search.WithResultFilter(new SearchResultFilter { StartOfRange = searchParams.StartIndex, EndOfRange = searchParams.StartIndex + searchParams.Count, IsHighlightingEnabled = true }).Search(new Delivery.IQQuery.Model.Search.SearchQuery().GroupedAnd(fields, values).Compile()); var resultSet = new SearchResultSetWrapped(results) { Hits = results.Hits, Count = searchParams.Count.Value, StartIndex = searchParams.StartIndex.Value }; return(Json(resultSet)); } catch (Exception) { Response.StatusCode = 405; return(new EmptyResult()); } }
public virtual ActionResult Search() { try { var req = Request.InputStream; req.Seek(0, System.IO.SeekOrigin.Begin); string json; using (var reader = new StreamReader(Request.InputStream)) json = reader.ReadToEnd(); SearchParameters searchParams = JsonConvert.DeserializeObject <SearchParameters>(json); string lang = GetLanguage(searchParams); ICriteria criteria; if (cjk.Contains(lang)) { string queryString = GetSearchQueryString(searchParams); string pubId = GetPublicationId(searchParams); if (pubId != null) { var q = new SearchQuery().GroupStart() .Field(PUBLICATION_ONLINE_STATUS_FIELD, PUBLICATION_ONLINE_STATUS_VALUE) .And().Field("publicationId", new DefaultTermValue(pubId)) .GroupEnd() .And() .GroupStart() .Field("content.cjk", queryString) .Or() .Field($"content.{lang}", queryString) .GroupEnd(); criteria = q.Compile(); } else { var q = new SearchQuery().GroupStart() .Field(PUBLICATION_ONLINE_STATUS_FIELD, PUBLICATION_ONLINE_STATUS_VALUE) .GroupEnd() .And() .GroupStart() .Field("content.cjk", queryString) .Or() .Field($"content.{lang}", queryString) .GroupEnd(); criteria = q.Compile(); } } else { criteria = SingleLanguageSearchQuery(searchParams); } var search = ApiClientFactory.Instance.CreateSearchClient <SearchResultSet, SearchResult>(); var results = search.WithResultFilter(new SearchResultFilter { StartOfRange = searchParams.StartIndex, EndOfRange = searchParams.StartIndex + searchParams.Count, IsHighlightingEnabled = true }).Search(criteria); var resultSet = new SearchResultSetWrapped(results) { Hits = results.Hits, Count = searchParams.Count.Value, StartIndex = searchParams.StartIndex.Value }; return(Json(resultSet)); } catch (Exception) { Response.StatusCode = 405; return(new EmptyResult()); } }