private SI4T.Query.Models.SearchResult CreateSearchResult(IHit <object> hit)
        {
            SI4T.Query.Models.SearchResult result = new SI4T.Query.Models.SearchResult {
                Id = hit.Id
            };
            Dictionary <string, object> fields = JsonConvert.DeserializeObject <Dictionary <string, object> >(hit.Source.ToString());

            foreach (KeyValuePair <string, object> field in fields)
            {
                string type      = field.Value.GetType().ToString();
                string fieldname = field.Key;

                switch (fieldname)
                {
                case "publicationid":
                    result.PublicationId = int.Parse(field.Value.ToString());
                    break;

                case "title":
                    result.Title = field.Value.ToString();
                    break;

                case "url":
                    result.Url = field.Value.ToString();
                    break;

                case "summary":
                    result.Summary = field.Value.ToString();
                    break;

                default:
                    object data = null;
                    switch (type)
                    {
                    case "arr":         //TODO: Make smarter
                        data = field.Value;
                        break;

                    default:
                        data = field.Value.ToString();
                        break;
                    }
                    result.CustomFields.Add(fieldname, data);
                    break;
                }
            }

            if (string.IsNullOrEmpty(result.Summary) && hit.Highlights.ContainsKey("body"))
            {
                // If no summary field is present in the index, use the highlight fragment from the body field instead.
                string autoSummary = hit.Highlights["body"].Highlights.FirstOrDefault();
                if (autoSummary.Length > AutoSummarySize)
                {
                    // To limit the size of the fragment in the Search Request.
                    // Therefore we truncate it here if needed.
                    autoSummary = autoSummary.Substring(0, AutoSummarySize) + "...";
                }
                result.Summary = autoSummary;
            }

            return(result);
        }
        private SI4T.Query.Models.SearchResult CreateSearchResult(Hit hit)
        {
            SI4T.Query.Models.SearchResult result = new SI4T.Query.Models.SearchResult {
                Id = hit.Id
            };

            foreach (KeyValuePair <string, List <string> > field in hit.Fields)
            {
                string type      = field.Value.GetType().ToString();
                string fieldname = field.Key;

                switch (fieldname)
                {
                case "publicationid":
                    result.PublicationId = Int32.Parse(field.Value.FirstOrDefault());
                    break;

                case "title":
                    result.Title = field.Value.FirstOrDefault();
                    break;

                case "url":
                    result.Url = field.Value.FirstOrDefault();
                    break;

                case "summary":
                    result.Summary = field.Value.FirstOrDefault();
                    break;

                default:
                    object data = null;
                    switch (type)
                    {
                    case "arr":         //TODO: Make smarter
                        data = field.Value.ToList();
                        break;

                    default:
                        data = field.Value.FirstOrDefault();
                        break;
                    }
                    result.CustomFields.Add(fieldname, data);
                    break;
                }
            }

            if (String.IsNullOrEmpty(result.Summary) && hit.Highlights.ContainsKey("body"))
            {
                // If no summary field is present in the index, use the highlight fragment from the body field instead.
                string autoSummary = hit.Highlights["body"];
                if (autoSummary.Length > AutoSummarySize)
                {
                    // CloudSearch returns up to 10K of content and there doesn't seem to be a way to limit the size of the fragment in the Search Request.
                    // Therefore we truncate it here if needed.
                    autoSummary = autoSummary.Substring(0, AutoSummarySize) + "...";
                }
                result.Summary = autoSummary;
            }

            return(result);
        }
Exemplo n.º 3
0
        private SI4T.Query.Models.SearchResult CreateSearchResult(Hit hit)
        {
            SI4T.Query.Models.SearchResult result = new SI4T.Query.Models.SearchResult {Id = hit.Id};

            foreach (KeyValuePair<string, List<string>> field in hit.Fields)
            {
                string type = field.Value.GetType().ToString();
                string fieldname = field.Key;
                
                switch (fieldname)
                {
                    case "publicationid":
                        result.PublicationId = Int32.Parse(field.Value.FirstOrDefault());
                        break;
                    case "title":
                        result.Title = field.Value.FirstOrDefault();
                        break;
                    case "url":
                        result.Url = field.Value.FirstOrDefault();
                        break;
                    case "summary":
                        result.Summary = field.Value.FirstOrDefault();
                        break;
                    default:
                        object data = null;
                        switch (type)
                        {
                            case "arr": //TODO: Make smarter
                                data = field.Value.ToList();
                                break;
                            default:
                                data = field.Value.FirstOrDefault();
                                break;
                        }
                        result.CustomFields.Add(fieldname, data);
                        break;
                }
            }

            if (String.IsNullOrEmpty(result.Summary) && hit.Highlights.ContainsKey("body"))
            {
                // If no summary field is present in the index, use the highlight fragment from the body field instead.
                string autoSummary = hit.Highlights["body"];
                if (autoSummary.Length > AutoSummarySize)
                {
                    // CloudSearch returns up to 10K of content and there doesn't seem to be a way to limit the size of the fragment in the Search Request.
                    // Therefore we truncate it here if needed.
                    autoSummary = autoSummary.Substring(0, AutoSummarySize) + "...";
                }
                result.Summary = autoSummary;
            }

            return result;
        }