View page description in searchresults
Hello,
I would like to display the description of the pages at the same place as where the summary is for news items. I removed the HighLighterResult since that also gave a lot of other things I don't need. Then I tried adding Eval("Description") but this isn't recognised and results in an error. Is there any way to add the Description field of pages in stead of only the Summary in, for example, news items?
Below is the code I am using at the moment.
<
ItemTemplate
>
<
dt
class
=
"sfsearchResultTitle"
><
a
runat
=
"server"
href='<%# Eval("Link")%>'><%# Eval("Title") %></
a
></
dt
>
<
dd
class
=
"sfsearchResultSnippet"
><%# Eval("Summary")%></
dd
>
<
dd
class
=
"sfsearchResultUrl"
><
a
runat
=
"server"
href='<%# Eval("Link")%>'><%# Eval("Link")%></
a
></
dd
>
</
ItemTemplate
>
Hello Rick,
For our search indexing functionality we're using Lucene. The search results that are displayed when you perform search are of type IDocument and are stored in an IResultSet, in other words these are not the actual pages. However each of these documents contains a property ContentType
which can be used to determine what is the actual object type it represents. Once you determine if the object is of the desired type (PageNode in your case) you can get the OriginalItemId
property of the document, which represents the actual item ID. usingt he corresponding manager you can get the object ad access any of its fields so you can display the information on the template. What you can do is create an external template based on the original one, and subscribe to the DataBound event of the repeater control where you'll be checking each item. Here's an example how you can perform this check for products inside the search result:'
var type = myitem.GetValue(
"ContentType"
);
//You need to check for the type of the item you have gotten in your search results
//here we're checking if the item is an eCommerce product:
if
(TypeResolutionService.ResolveType(type) ==
typeof
(Product))
var ID =
new
Guid(myitem.GetValue(
"OriginalItemId"
));
//you can now get the item with its manager and access its properties,
//since you'll be working with an object of the correct type
//for example:
var manager = CatalogManager.GetManager();
var product = manager.GetProduct(ID);
var myOwner = product.Owner;
//please none this is an ID of the user
var displayName = UserProfilesHelper.GetUserDisplayName(myOwner);
//get the FirstName and LastName from the string
var FirstName = displayName.Split(
' '
).First();
var LastName = displayName.Split(
' '
).Last();
Your solution is geared towards an ASP.NET developer, but how can an ordinary web designer or content user implement this who lacks understanding of asp.net?
Is there an easier way to do this? just like settings properties in the search module or backend administration?
If coding is the only solution, can you please kindly include the complete page and code behind solution to do this, in a way like a non asp.net developer can follow?
Hi Robert,
Thanks for pointing this out, please find attached a customized SearchResults template that you can add to your project, build it and then go to the page where your SearchResults widget is placed, edit the widget and in the Advanced properties find the LayoutTemplatePath property and enter there the application relative path to the customized template. Save the changes and publish the page - the SearchResults widget will now use your custom template instead of the default one, and it will have the desired logic implemented - display the Page Description in the SearchResults.
All the best,
Boyan Barnev
the Telerik team
Hi Boyan-
I tried this and I get some weird results. When I edit the LayoutTemplatePath Property in the Advanced Properties and hit 'Save', the value is never saved. When I go back into the form the value always reverts back to ~/SFRes/Telerik.Sitefinity.Resources.Templates.PublicControls.SearchResults.ascx.
Is there another property that has to be changed? Do I need to register the new Search widget somewhere?
Warm Regards,
Gregg Crystal
Hi Gregg,
Where in the file structure are you storing your custom templates and what is the URL you are using to reference them? Also make sure you don't have a template selected from the basic view mode as well.
Greetings,Thanks for the code, but I am also having the same issue. I am pretty sure there is no template selected and just referencing to ~/Modules/Folder/Control.ascx but it keeps replacing it for some reason. Any other way of forcing this?
Many thanks,
Ricardo
Same problem here, it reverts back all the time when I hit save.
Hello-
If the LayoutTemplatePath property is not saving, then you have an error in your ascx or cs file. Sitefinity is just quietly failing. My issue turned out to be I was referencing the wrong assembly in my ascx file, as the assemblies have changed between v4 and v5. Some of the examples in this forum are the 'old' way.
In my code, which now works, I had to change the register tags to this:
<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI" TagPrefix="sitefinity" %>
<%@ Register Assembly="Telerik.Sitefinity.Search.Impl" Namespace="Telerik.Sitefinity.Services.Search.Web.UI.Public" TagPrefix="sfSearch" %>
Hope this helps!
-Gregg
Gregg,
Thanks for the reply. Your input gave me a lead to find the problem. Yes, there is something wrong in the ascx file. In my case, I am missing the sitefinity pager, top and bottom search box. Its actually strange, I have nt added them because, I dont need them, but sitefinity is expecting them in the control, so i added them and hidden them. Thanks for the reply though