Gravatar for anweshadastider@gmail.com

Question by anwesha, Apr 25, 2016 6:39 AM

Display linked items in search results page

Hi,

I am trying to achieve document listing using Coveo search view(MVC). I want to group some of the documents from my media library under a folder located under a sitecore page. The grouping will be done using proxy items that are linked to media items located in media library. I want to point the datasource of the Coveo Search View(MVC) to this folder and display all the linked items from media library in the search results page. How can I display only the linked media items in the search results page (not the proxy items) based on the datasource location?

1 Reply
Gravatar for jflheureux@coveo.com

Answer by Jean-François L'Heureux, Apr 25, 2016 8:34 AM

The Datasource field of a Coveo Search (View) component is not used to define the root item to be displayed in the search page but to define a Sitecore item containing the parameters of the component.

To define which items should be visible in a search page, you should look at the filtering rules in the component properties (Enterprise Edition) or in the JavaScript code:

  • https://developers.coveo.com/pages/viewpage.action?pageId=31916139
  • https://developers.coveo.com/display/SitecoreV3/Inserting+and+Customizing+a+Search+Interface+Component#InsertingandCustomizingaSearchInterfaceComponent-AddingaFilterExpression
  • https://developers.coveo.com/display/SitecoreV3/Adding+Filter+and+Boost+Expressions+Programmatically

I don't think proxy items would work for a search page unless you process those items at indexing time to replicate the real media item fields on its proxy item. You could achieve this using the coveoItemProcessingPipeline or coveoPostItemProcessingPipeline pipelines (see Understanding the Indexing and Search Pipelines).

Gravatar for anweshadastider@gmail.com

Comment by anwesha, Apr 25, 2016 11:15 PM

Thanks Jeff! Will try this approach.

Gravatar for anweshadastider@gmail.com

Comment by anwesha, Apr 26, 2016 1:32 PM

An update to my question. I have used the approach mentioned above and I am getting the related media items in the result page. I have a "Title" field in all my media items and I would like to display the "Title" field's value as the title of all these proxy items. Please see below for my code. I am not able to fetch the "Title" field from my related mediaitem and display it in the result page. Currently it is picking up Title from the properties of the item. Also, how to update the Uri of the proxy item to point to my media item like a PDF,PPT etc

p_Args.CoveoItem.BinaryData = byteArray;
p_Args.CoveoItem.MustDownloadBinaryData = false;
p_Args.CoveoItem.Title = mediaitem.Name;
p_Args.CoveoItem.ClickableUri = Sitecore.Resources.Media.MediaManager.GetMediaUrl(mediaitem);
Gravatar for jflheureux@coveo.com

Comment by Jean-François L'Heureux, Apr 26, 2016 1:59 PM

From your code, I guess your processor is for the coveoPostItemProcessingPipeline pipeline.

For the title of the indexed documents: When an indexed document contains BinaryData, a CES converter will try to extract the title from the original document metadata. If a title is found, it will become by default the title of the indexed document regardless of the title set in the Title property of the CoveoItem object. This is caused by the default setting for the "Title Selection Sequence".

To take the Title property first, you should have the "Automatically detect the title of documents" option before the "Use the title extracted by the converter" option.

You can modify the "Title Selection Sequence" either at the source level (see Modifying General Source Parameters) or at the Modifying How CES Handles a Document Type. If you change it at the source level, you should do it for all your Sitecore sources (web, master, core…). All the indexed documents for these sources will now use the sequence. If you change it at the document type set level, you should do it on the "Sitecore Search Provider Document Types Set" used by Coveo for Sitecore. You can do it on only the file types you want to avoid modifying it for all the file types.

For the URI of the indexed documents: I think your code is right by setting the ClickableUri property value. There's also an Uri property on the CoveoIndexableItem class just like the ClickableUri. However, Coveo Enterprise Search uses this URI as a unique key in the index. If you index 2 documents with the same URI, the latest indexed will override the first one. If you change this property value, make sure not to index 2 proxy items linking to the same media item and be sure not to index the original media items either. It may be better to index the real media item URI in a computed index field on your proxy items and modify the JS UI result template of your search page to use this field value instead of the real clickableUri for display and creating the anchor link around the result title.

I hope this helps,

Jeff

Gravatar for anweshadastider@gmail.com

Comment by anwesha, Apr 27, 2016 1:06 AM

Hi Jeff,

Regarding the title of the documents in media library, I have a Title field in the media items where the user enters the Title for all the documents (PDF, PPT, WordDoc etc.). How can I get that to display as the title of my proxy items? When I changed the "Title Selection Sequence" to have the "Automatically detect the title of documents" option before the "Use the title extracted by the converter" option, the title is getting picked up from the text in the documents and not my "Title" field.

Also, I can see duplicate listings in my result page. Is there a way to clean the index?

Gravatar for jflheureux@coveo.com

Comment by Jean-François L'Heureux, Apr 27, 2016 11:16 AM

For the title of the proxy items, You have to:

  • Set the title selection sequence as I explained.
  • Set the CoveoIndexableItem.Title property in a coveoPostItemProcessingPipeline pipeline processor to the desired value.
  • Rebuild your Sitecore indexes managed by Coveo.

Currently, you set the title as the name of the real media item:

p_Args.CoveoItem.Title = mediaitem.Name;

You have to set it to the Title field of the real media item using the Sitecore API (see Getting a Sitecore field value). Example:

p_Args.CoveoItem.Title = mediaitem["Title"];

For the duplicate listings in your search page, it may be multiple things:

  • Do you have multiple proxy items linking to the same media items?
  • Do you also index the real media items?
  • Did you forget to set a filtering rule on your search page to only display items under a specific folder or items of a specific type to only display the proxy items?
Gravatar for anweshadastider@gmail.com

Comment by anwesha, Apr 29, 2016 12:53 AM

I have the "Automatically detect the title of documents" option before the "Use the title extracted by the converter" option

I have set the CoveoIndexableItem.Title property in a coveoPostItemProcessingPipeline pipeline processor to the Title field of my media item as shown below

p_Args.CoveoItem.Title = mediaitem["Title"];

I have rebuilt my indexes but the Title of the proxy items are being taken from the content of the documents instead of the "Title" field.

I also tried putting the "Use the title extracted by the converter" option at the top and reindexing. But the Title is getting its value from the metadata or something as I do not see the text entered anywhere. I found a similar issue in the questions : https://answers.coveo.com/questions/1323/can-you-update-the-systitle-field-of-a-media-library-item. The text is coming from @systitle field even in my case. Is there any way to update that?

Also, in the index, I can see a "Title" field being indexed @ftitle93147 which has the correct text. How can I display this value in my Coveo Search View?

Currently the cshtml has the below code for displaying the title. What changes should I do to display the title from the "Title" filed which is @ftitle93147.

<span class='CoveoResultTitle'>{{=title?highlight(title, titleHighlights):''}}</span>
Ask a question