public string RewriteUrl(string url) { if (url.Contains("productid")) { // Give it a thorough look - see if we can redirect it Url uri = new Url(url); string[] productIds = uri.QueryCollection.GetValues("productid"); if (productIds != null && productIds.Any()) { string productId = productIds.FirstOrDefault(); if (productId != null && string.IsNullOrEmpty(productId) == false) { SearchResults <FindProduct> results = SearchClient.Instance.Search <FindProduct>() .Filter(p => p.Code.MatchCaseInsensitive(productId)) .GetResult(); if (results.Hits.Any()) { // Pick the first one SearchHit <FindProduct> product = results.Hits.FirstOrDefault(); return(product.Document.ProductUrl); } } } } return(null); }
protected void rptSearchResults_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { SearchHit <SitecoreItem> item = (SearchHit <SitecoreItem>)e.Item.DataItem; { HyperLink ItemLink = (HyperLink)e.Item.FindControl("ItemLink"); Literal ItemDescription = (Literal)e.Item.FindControl("ItemDescription"); if (ItemLink != null && ItemDescription != null) { Item i = item.Document.GetItem(); ItemLink.NavigateUrl = LinkManager.GetItemUrl(i); if (i["menu title"] != string.Empty) { ItemLink.Text = i["menu title"]; } else if (i["title"] != string.Empty) { ItemLink.Text = i["title"]; } else { ItemLink.Text = i.Name; } ItemDescription.Text = SiteConfiguration.GetPageDescripton(i); } } } }
private static SearchHit ToSearchHit(SearchResult searchResult) { var searchHit = new SearchHit { Key = (string)searchResult.Document["id"], Title = GetTitleForItem(searchResult), PictureUrl = null, Description = ((string)searchResult.Document["job_description"]).Substring(0, 512) + "...", }; object minimumRequirements; if (searchResult.Document.TryGetValue("minimum_qual_requirements", out minimumRequirements)) { searchHit.PropertyBag.Add("minimum_qual_requirements", minimumRequirements); } object preferedSkills; if (searchResult.Document.TryGetValue("preferred_skills", out preferedSkills)) { searchHit.PropertyBag.Add("preferred_skills", preferedSkills); } return(searchHit); }
public void GetHashOfSearchResults_Returns_Same_Hash_WhenCallingForSameSearchResult() { var SearchHitList = new List <SearchHit>(); var SearchHit = new SearchHit(); var SearchHit2 = new SearchHit(); SearchHit.Source.Add("http://pid.bayer.com/kos/19014/hasPID", JObject.Parse("{ \"outbound\": [ { \"value\": \"https://dev-pid.bayer.com/kos/test1\", \"uri\": \"https://dev-pid.bayer.com/kos/test1\", \"edge\": \"http://pid.bayer.com/kos/19014/hasPID\" } ], \"inbound\": [] }")); SearchHit.Source.Add("https://pid.bayer.com/kos/19050/lastChangeDateTime", JObject.Parse("{ \"outbound\": [ { \"value\": \"2021-02-01T09:07:25.327Z\", \"uri\": null, \"edge\": null } ], \"inbound\": [] }")); SearchHit.Source.Add("https://pid.bayer.com/kos/19050/dateCreated", JObject.Parse("{ \"outbound\": [ { \"value\": \"2021-02-01T09:06:30.452Z\", \"uri\": null, \"edge\": null } ], \"inbound\": [] }")); SearchHit2.Source.Add("http://pid.bayer.com/kos/19014/hasPID", JObject.Parse("{ \"outbound\": [ { \"value\": \"https://dev-pid.bayer.com/kos/test2\", \"uri\": \"https://dev-pid.bayer.com/kos/test2\", \"edge\": \"http://pid.bayer.com/kos/19014/hasPID\" } ], \"inbound\": [] }")); SearchHit2.Source.Add("https://pid.bayer.com/kos/19050/lastChangeDateTime", JObject.Parse("{ \"outbound\": [ { \"value\": \"2021-02-08T09:07:25.327Z\", \"uri\": null, \"edge\": null } ], \"inbound\": [] }")); SearchHit2.Source.Add("https://pid.bayer.com/kos/19050/dateCreated", JObject.Parse("{ \"outbound\": [ { \"value\": \"2021-02-08T09:06:30.452Z\", \"uri\": null, \"edge\": null } ], \"inbound\": [] }")); SearchHitList.Add(SearchHit); SearchHitList.Add(SearchHit2); var Hits = new HitDTO() { Total = SearchHitList.Count, Hits = SearchHitList }; var searchResult = new SearchResultDTO("testForProcessingStoredQueries", null, Hits); string computedHash = _service.GetHashOfSearchResults(searchResult); string computedHash2 = _service.GetHashOfSearchResults(searchResult); Assert.NotEmpty(computedHash); Assert.NotEmpty(computedHash2); Assert.Equal(computedHash, computedHash2); }
public void GetUpdatedResources_Returns_EmptyList_IfSearchResultsDidntChange() { var storedQuery = new StoredQuery() { ExecutionInterval = ExecutionInterval.Daily, LatestExecutionDate = new DateTime(2021, 2, 5) }; var searchList = new List <SearchHit>(); SearchHit SearchHit = new SearchHit(); SearchHit SearchHit2 = new SearchHit(); SearchHit.Source.Add("http://pid.bayer.com/kos/19014/hasPID", JObject.Parse("{ \"outbound\": [ { \"value\": \"https://dev-pid.bayer.com/kos/test1\", \"uri\": \"https://dev-pid.bayer.com/kos/test1\", \"edge\": \"http://pid.bayer.com/kos/19014/hasPID\" } ], \"inbound\": [] }")); SearchHit.Source.Add("https://pid.bayer.com/kos/19050/lastChangeDateTime", JObject.Parse("{ \"outbound\": [ { \"value\": \"2021-02-01T09:07:25.327Z\", \"uri\": null, \"edge\": null } ], \"inbound\": [] }")); SearchHit.Source.Add("https://pid.bayer.com/kos/19050/dateCreated", JObject.Parse("{ \"outbound\": [ { \"value\": \"2021-02-01T09:06:30.452Z\", \"uri\": null, \"edge\": null } ], \"inbound\": [] }")); SearchHit2.Source.Add("http://pid.bayer.com/kos/19014/hasPID", JObject.Parse("{ \"outbound\": [ { \"value\": \"https://dev-pid.bayer.com/kos/test2\", \"uri\": \"https://dev-pid.bayer.com/kos/test2\", \"edge\": \"http://pid.bayer.com/kos/19014/hasPID\" } ], \"inbound\": [] }")); SearchHit2.Source.Add("https://pid.bayer.com/kos/19050/lastChangeDateTime", JObject.Parse("{ \"outbound\": [ { \"value\": \"2021-02-03T09:07:25.327Z\", \"uri\": null, \"edge\": null } ], \"inbound\": [] }")); SearchHit2.Source.Add("https://pid.bayer.com/kos/19050/dateCreated", JObject.Parse("{ \"outbound\": [ { \"value\": \"2021-02-03T09:06:30.452Z\", \"uri\": null, \"edge\": null } ], \"inbound\": [] }")); searchList.Add(SearchHit); searchList.Add(SearchHit2); List <string> resultPidUris = _service.GetUpdatedResources(searchList, storedQuery); Assert.NotNull(resultPidUris); Assert.Empty(resultPidUris); }
private static SearchHit Map(Hit hit) { var searchHit = new SearchHit(hit); CustomProperty[] customPropertiesForType = GetCustomPropertiesForType(hit); if (!IsValidCustomProperty()) { return(searchHit); } foreach (CustomProperty property in customPropertiesForType) { if (!hit.Source.UnmappedFields.ContainsKey(property.Name)) { continue; } JToken unmappedField = hit.Source.UnmappedFields[property.Name]; if (unmappedField == null) { break; } if (IsArrayValue(unmappedField)) { searchHit.CustomProperties[property.Name] = unmappedField.Children().Cast <JValue>().Select(v => v.Value).ToArray(); continue; } if (IsDictionaryValue(unmappedField)) { searchHit.CustomProperties[property.Name] = JObject.FromObject(unmappedField).ToObject <IDictionary <string, object> >(); continue; } if (unmappedField is JValue value) { searchHit.CustomProperties[property.Name] = value.Value; } } return(searchHit); bool IsValidCustomProperty() { return(customPropertiesForType.Length > 0 && hit.Source?.UnmappedFields != null && hit.Source.UnmappedFields.Any(u => customPropertiesForType.Any(c => c.Name == u.Key))); }
protected virtual ScoredItem BuildScoredItemModel <T>(SearchHit <T> searchItem) where T : IndexedItem { var item = searchItem.Document.GetItem(); if (item == null) { return(null); } return(new ScoredItem { Item = item, Score = searchItem.Score, ItemUrl = item.Url() }); }
private static SearchHit Map(Hit hit) { var searchHit = new SearchHit(hit); CustomProperty[] customPropertiesForType = hit.Source?.Types != null ? Conventions.Indexing.CustomProperties.Where(c => hit.Source.Types.Contains(c.OwnerType.GetTypeName())).ToArray() : Enumerable.Empty <CustomProperty>().ToArray(); if (customPropertiesForType.Length == 0) { return(searchHit); } if (hit.Source?.UnmappedFields == null || !hit.Source.UnmappedFields.Any(u => customPropertiesForType.Any(c => c.Name == u.Key))) { return(searchHit); } foreach (CustomProperty property in customPropertiesForType) { if (!hit.Source.UnmappedFields.ContainsKey(property.Name)) { continue; } JToken unmappedField = hit.Source.UnmappedFields[property.Name]; if (unmappedField == null) { break; } // Array value if (unmappedField.Children().Any()) { searchHit.CustomProperties[property.Name] = unmappedField.Children().Cast <JValue>().Select(v => v.Value).ToArray(); continue; } if (unmappedField is JValue value) { searchHit.CustomProperties[property.Name] = value.Value; } } return(searchHit); }
public static SearchHit ToSearchHit(dynamic hit) { var searchHit = new SearchHit { Key = (string)hit.Document["rid"], Title = (string)hit.Document["FileName"], PictureUrl = (string)hit.Document["BlobUri"], Description = (string)hit.Document["Caption"] }; object Tags; if (hit.Document.TryGetValue("Tags", out Tags)) { searchHit.PropertyBag.Add("Tags", Tags); } return(searchHit); }
private IList <SearchHit> checkForHit(Sql8rServer s, Sql8rDatabase db, bool isSystemObject, string objectType, IColumnedObject o, string criteria, bool exactMatch, bool caseSensitive) { IList <SearchHit> hits = new List <SearchHit>(); StringComparison cases = StringComparison.OrdinalIgnoreCase; if (caseSensitive) { cases = StringComparison.Ordinal; } foreach (Sql8rColumn c in o.Columns.Values) { bool IsMatch = false; if (exactMatch) { if (c.Name.Equals(criteria, cases)) { IsMatch = true; } } else { if (c.Name.IndexOf(criteria, cases) >= 0) { IsMatch = true; } } if (IsMatch) { var hit = new SearchHit(s.Name, db.Name, isSystemObject, objectType, o.Schema, o.Name, c.Name); hits.Add(hit); } } return(hits); }
public WebSearchResult(SearchHit hit) { var result = new SearchResult(hit); PathAndQuery = hit.Document.Get(BuiltinFields.Path); Title = result.Title; Description = hit.Document.Get(CustomFields.Description); Score = hit.Position; if (!string.IsNullOrEmpty(result.Url) && ItemUri.IsItemUri(result.Url)) { var uri = ItemUri.Parse(result.Url); var db = !String.IsNullOrEmpty(uri.DatabaseName) ? Factory.GetDatabase(uri.DatabaseName) : global::Sitecore.Context.Database; if (db != null) { using (new SecurityDisabler()) { this.Item = db.GetItem(new DataUri(uri)); } } } }
public Expression PostSearch(Expression executable, SearchHit <JObject> searchHit, IClientConventions clientConventions, Language language) { return(ExpressionExtensions.Replace <MethodCallExpression>(ExpressionExtensions.Replace <MethodCallExpression>(executable, (Func <MethodCallExpression, bool>)(x => { if (x.Method.Name == "AsHighlighted") { return x.Method.ReflectedType == typeof(XhtmlStringProjectionExtensions); } else { return false; } }), new Func <MethodCallExpression, Expression>(this.ReplaceAsHighlightedCall)), (Func <MethodCallExpression, bool>)(x => { if (x.Method.Name == "AsCropped") { return x.Method.ReflectedType == typeof(XhtmlStringProjectionExtensions); } else { return false; } }), new Func <MethodCallExpression, Expression>(this.ReplaceAsCroppedCall))); }
public bool Test(SearchHit hit) { int age = (int)hit.Record["Age"]; return(age >= _min && age <= _max); }
public SearchDocumentImplementation(ISearchConfiguration config, string locale, SearchHit <FindDocument> hit) { this._fields = new List <ISearchField>(); this._fields.Add((ISearchField) new SearchField("_id", (object)hit.Document.CatalogEntryId)); foreach (string language in hit.Document.Languages) { config.AddLocale(language); } foreach (string currency in hit.Document.Currencies) { config.AddCurrency((Mediachase.Commerce.Currency)currency); } foreach (string market in hit.Document.Markets) { config.AddMarket((MarketId)market); } foreach (IFieldConfiguration allField in config.GetAllFields(locale)) { object obj = allField.GetObjectValue(hit.Document); IEnumerable <string> source = obj as IEnumerable <string>; if (source != null) { string[] array = source.Where <string>((Func <string, bool>)(v => v != null)).ToArray <string>(); obj = array.Length != 0 ? (object)array : (object)(string[])null; } if (obj != null) { if (allField.Currency.HasValue) { this._fields.Add((ISearchField) new SearchField(string.Format("{0}{1}_{2}", (object)allField.Name, (object)allField.Currency.Value.CurrencyCode, (object)allField.MarketId.Value), obj)); } else { this._fields.Add((ISearchField) new SearchField(allField.Name, obj)); } } } }