Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi, I have Implemented site search in Umbraco 7 using examine.
Now i need to add blog data to be visible in the search, I have used Ublogsy for implmnetation of blod.
Here is the code what I am trying to do to add blog data in seearch
Examine code:
<IndexAttributeFields> <add Name="id" /> <add Name="nodeName"/> <add Name="updateDate" /> <add Name="writerName" /> <add Name="path" /> <add Name="nodeTypeAlias" /> <add Name="umbracoNaviHide" /> <add Name="parentID" /> </IndexAttributeFields> <IndexUserFields> <add Name="bodyText" /> <add Name="uBlogsyContentBody" /> <add Name="uBlogsyContentTitle" /> <add Name="uBlogsyContentSummary" /> </IndexUserFields> <ExcludeNodeTypes> <add Name="Folder" /> </ExcludeNodeTypes> Search code: @inherits Umbraco.Web.Macros.PartialViewMacroPage @using Examine.LuceneEngine.SearchCriteria @{ var searchTerm = Request.QueryString["s"]; if (String.IsNullOrWhiteSpace(searchTerm)) { searchTerm = ""; } var searcher = ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"]; var searchCriteria = searcher.CreateSearchCriteria(UmbracoExamine.IndexTypes.Content); Examine.SearchCriteria.IBooleanOperation filter = null; var searchKeywords = searchTerm.Split(' '); int i = 0; for (i = 0; i < searchKeywords.Length; i++) { if (filter == null) { filter = searchCriteria.GroupedOr(new string[] { "nodeName", "bodyText", "browserTitle", "tags", "mediaTags", "uBlogsyContentTitle", "uBlogsyContentSummary", "uBlogsyContentBody" }, searchKeywords[i]); } else { filter = filter.Or().GroupedOr(new string[] { "nodeName", "bodyText", "browserTitle", "tags", "mediaTags", "uBlogsyContentTitle", "uBlogsyContentSummary", "uBlogsyContentBody" }, searchKeywords[i]); } } var searchResults = searcher.Search(searchCriteria).Where(r => r["__IndexType"] == "content").ToList(); if (searchResults.Any()) { int total = 0; @**@ foreach (var result in searchResults) { if (result.Fields.ContainsKey("bodyText") && Umbraco.Field("umbracoNaviHide").ToString() == "True" || result.Fields.ContainsKey("uBlogsyContentBody")) { string bodyText = result["bodyText"]; //string blogTitle = result["uBlogsyContentTitle"]; //string blogSummary = result["uBlogsyContentSummary"]; string blogContent = result.Fields["uBlogsyContentBody"]; if (bodyText.Trim().Length >0 || blogContent.Trim().Length > 0) { total = total + 1; } } } @**@ Your search for @searchTerm returned @total.ToString() result(s) @foreach (var result in searchResults) { if (result.Fields.ContainsKey("bodyText")) { string bodyText = result["bodyText"]; if ((string.IsNullOrEmpty(bodyText)) || bodyText.Trim().Length < 1) { continue; } } else { continue; } var node = Umbraco.TypedContent(result.Id); var pathIds = result["__Path"].Split(','); var path = Umbraco.TypedContent(pathIds).Where(p => p != null).Select(p => new { p.Name }).ToList(); @node.Namexyz.com@node.Url @if (result.Fields.ContainsKey("title") || result.Fields.ContainsKey("uBlogsyContentTitle")) {@result["title"] } @if (result.Fields.ContainsKey("bodyText") || result.Fields.ContainsKey("uBlogsyContentSummary") || result.Fields.ContainsKey("uBlogsyContentBody")) { @result["bodyText"].Truncate(250) } } } else { There are no results matching your search criteria: @if (!String.IsNullOrWhiteSpace(searchTerm)) { '@searchTerm' } } } I get error string blogContent = result.Fields["uBlogsyContentBody"]; doesnot contains key.Please hel and guide where I am doing it wrongThanks
Search code:
@inherits Umbraco.Web.Macros.PartialViewMacroPage @using Examine.LuceneEngine.SearchCriteria @{ var searchTerm = Request.QueryString["s"]; if (String.IsNullOrWhiteSpace(searchTerm)) { searchTerm = ""; } var searcher = ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"]; var searchCriteria = searcher.CreateSearchCriteria(UmbracoExamine.IndexTypes.Content); Examine.SearchCriteria.IBooleanOperation filter = null; var searchKeywords = searchTerm.Split(' '); int i = 0; for (i = 0; i < searchKeywords.Length; i++) { if (filter == null) { filter = searchCriteria.GroupedOr(new string[] { "nodeName", "bodyText", "browserTitle", "tags", "mediaTags", "uBlogsyContentTitle", "uBlogsyContentSummary", "uBlogsyContentBody" }, searchKeywords[i]); } else { filter = filter.Or().GroupedOr(new string[] { "nodeName", "bodyText", "browserTitle", "tags", "mediaTags", "uBlogsyContentTitle", "uBlogsyContentSummary", "uBlogsyContentBody" }, searchKeywords[i]); } } var searchResults = searcher.Search(searchCriteria).Where(r => r["__IndexType"] == "content").ToList(); if (searchResults.Any()) { int total = 0; @*
Your search for @searchTerm returned @total.ToString() result(s)
xyz.com@node.Url
@result["title"]
@result["bodyText"].Truncate(250)
There are no results matching your search criteria: @if (!String.IsNullOrWhiteSpace(searchTerm)) { '@searchTerm' }
I get error string blogContent = result.Fields["uBlogsyContentBody"]; doesnot contains key.
Please hel and guide where I am doing it wrong
Thanks
Hi Abdul,
It looks like you used wrong indexSet. Try to use
<!-- Default Indexset for external searches, this indexes all fields on all types of nodes--> <IndexSet SetName="ExternalIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/External/" > <IndexAttributeFields> <add Name="uBlogsyContentBody" /> <add Name="uBlogsyContentTitle" /> <add Name="uBlogsyContentSummary" /> </IndexAttributeFields> </IndexSet>
Hi Alex,
Thanks for your reply.
I tried this but it doesnot work.
Now I am able to get ublogsy data in search, but there is another issue.
If I add a new post, it doesnot create its index automatically and also not after rebuilding indexes.
I always have to delete the old indexes to feth the new blog data into the search, Can you help me in that, I have pasted my indexconfig
<IndexSet SetName="ExternalIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/External/">
<IndexAttributeFields>
<add Name="id" />
<add Name="nodeName"/>
<add Name="nodeTypeAlias" />
<add Name="umbracoNaviHide" />
<add Name="parentID" />
<add Name="updateDate" />
<add Name="writerName" />
<add Name="uBlogsyPost" />
</IndexAttributeFields>
<IndexUserFields>
<add Name="bodyText"/>
<add Name="uBlogsyContentBody" />
<add Name="uBlogsyContentSummary" />
</IndexUserFields>
<IncludeNodeTypes>
</IncludeNodeTypes>
<ExcludeNodeTypes>
<add Name="Folder" />
</ExcludeNodeTypes>
</IndexSet>
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
how to integrate ublogsy search with site search
Hi, I have Implemented site search in Umbraco 7 using examine.
Now i need to add blog data to be visible in the search, I have used Ublogsy for implmnetation of blod.
Here is the code what I am trying to do to add blog data in seearch
Examine code:
Hi Abdul,
It looks like you used wrong indexSet. Try to use
Hi Alex,
Thanks for your reply.
I tried this but it doesnot work.
Now I am able to get ublogsy data in search, but there is another issue.
If I add a new post, it doesnot create its index automatically and also not after rebuilding indexes.
I always have to delete the old indexes to feth the new blog data into the search, Can you help me in that, I have pasted my indexconfig
<IndexSet SetName="ExternalIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/External/">
<IndexAttributeFields>
<add Name="id" />
<add Name="nodeName"/>
<add Name="nodeTypeAlias" />
<add Name="umbracoNaviHide" />
<add Name="parentID" />
<add Name="updateDate" />
<add Name="writerName" />
<add Name="uBlogsyPost" />
</IndexAttributeFields>
<IndexUserFields>
<add Name="bodyText"/>
<add Name="uBlogsyContentBody" />
<add Name="uBlogsyContentSummary" />
</IndexUserFields>
<IncludeNodeTypes>
</IncludeNodeTypes>
<ExcludeNodeTypes>
<add Name="Folder" />
</ExcludeNodeTypes>
</IndexSet>
is working on a reply...