Archive

Archive for the ‘SharePoint 2013 Search’ Category

SharePoint 2013: Friendly URL’s in Publishing HTML Field is broken and showing FIXUPREDIRECT.ASPX as hyperlink in display template

June 12, 2014 4 comments

Hi Friends,

I came across a weird scenario recently, thought to share here so that it will be helpful for some of our friends.

Scenario:

In one of the article page we were having a Publishing HTML Field, content author added relative friendly URL as a hyperlink inside the field.  I.e. help/ithelp/lync

This page was supposed to be crawled and this Publishing HTML Field’s search managed property was used to display the column data in a search display template in content search web part (CBS).

The result displayed in content search web part was perfect except some of the hyperlinks are pointing to wrong pages.

The URL’s were pointing to FIXUPREDIRECT.ASPX page with some GUID’s as query string like following.

/_layouts/15/FIXUPREDIRECT.ASPX?WebId=1230beb8-10d2-46a2-b768-94948b2ea947&TermSetId=cebe5639-ae8c-4225-ab3b-aeb1a81fb09d&TermId=cec1896c-16e2-410f-a1f9-6b084e3b9890

Analysis of the issue:

After analysing the issue for couple of hours found that it is something related to managed metadata terms as the query string formed had termsetid and termId as query sting parameters.

Also we found that only the friendly URL’s ware broken. The magic happening while the page is getting saved and SharePoint tries to resolve the friendly URL with available terms and replacing the URL with FIXUPREDIRECT.ASPX URL and same gets crawled. It is nothing to do with search display template.

Workaround:

We tried to find out the solution to resolve this issue but no luck; we have tried workaround to replace the friendly relative URL with non-friendly URL and it worked for us.

help/ithelp/lync   TO   help/ithelp/lync.aspx

 

Advertisements

SharePoint 2013: Display template in content search web part not retaining selection

March 27, 2014 3 comments

Scenario: While adding content search web part in a page or page layout using all user web part. The selected display template while exporting web part is not retained the selection of custom display template and default display template gets selected if we create new page out of the page layout or page. I have verified couple of times in all user web part and it is correctly pointing to the display template like following-

~sitecollection/_catalogs/masterpage/Display Templates/Content Web Parts/Test_Item_Contacts.js

before_change

Solution:  Found out the problem with ~ symbol and solution is to replace it with ASCII equivalent & # 126 ; (Remove space)

~sitecollection/_catalogs/masterpage/Display Templates/Content Web Parts/Test_Item_Contacts.js

After_change

SharePoint 2013: Content Search web part query having query variables with multiple values

February 12, 2014 Leave a comment

Hi Friends,

While working with one of the SharePoint 2013 content search web part, I came across a query where query variables may return multiple values which causing my search query to fail, after struggling a lot I found a good TechNet article which solved my issue. Putting the solution here so that it will help someone from developer community.

For demo purpose I have created a Term set like following

TermSet

I have a user profile property (MyProfileProperty) which is bound to above term set. I have selected the profile property values for current logged in user.

User_Profile_Property

I have created a site column (MyTaxonomyColumn) which is bound to same term set and added that column in a list. After adding some entries in that list, I did a full crawl so that a managed property for the column will be created (owstaxIdMyTaxonomyColumn).

My requirement is to get all records from list having values from user profile property ‘MyProfileProperty’.

I have added a query like   {|owstaxIdMyTaxonomyColumn:{User.MyProfileProperty}}

Search_Query

This query gets transformed as following and worked for me as the above query syntax combines all the query variable values will be combined by using the bitwise OR operation.

Query_Transform

SharePoint: issue with $top in ListData.svc

September 10, 2013 2 comments

Hi Friends,

While working on SharePoint REST API’s in SP 2013 I come across a scenario where I need to filter on date column, I found solution to use /_vti_bin/ListData.svc service to filter based on date column like following, we can’t use RESTful call in date filtering –

var date = new Date();

var stringUrl=_spPageContextInfo.webAbsoluteUrl+"/_vti_bin/ListData.svc/EventsCalendar?$filter=StartTime+ge+datetime'"+date.toISOString()+"'&$select=Title,Description,Path,Id,StartTime&$orderby=StartTime&$top=3";

When I tried this I was getting data in browser but not using JavaScript code which is using $.ajax call to get and read the response.

After analyzing I found that $top is the culprit in my case and found following workaround.

When we use $top we will get the result date in ‘data.d’ like following-

var resultsArray = data.d;

If you want old JS code ‘data.d.results’ to work as is with $top we need to use $inlinecount=allpages in URL call like following

var date = new Date();

var stringUrl=_spPageContextInfo.webAbsoluteUrl+"/_vti_bin/ListData.svc/EventsCalendar?$filter=StartTime+ge+datetime'"+date.toISOString()+"'&$select=Title,Description,Path,Id,StartTime&$orderby=StartTime&$top=3&$inlinecount=allpages";

Happy coding….

SharePoint 2013: Avoid default results in search result and content search web part with search box

August 9, 2013 10 comments

Hi Friends,

I faced one more issue recently related to SharePoint 2013 search, that I thought to share with you.

Scenario:

I have ‘Search Box’ web part and ‘Content Search’ web part on a page, search box is sending query keyword to content search web part to display results. Content search web part has couple of additional queries as following screen shot showing.

Search_Box_1

This query returning the results always and thus showing me the results before even started searching using search box web part, as shown in following image.

Search_Box_2

I wanted content search web part should show the results only when someone searches for it in search box, else results should not be displayed.

Solution:

I have modified the Content Search web part’s query like following, which given the expected results.

Search_Box_3

So after the query changes by default no results are displayed and I am getting results only when I searched using search box web part, as shown in following images.

Search_Box_4

Search_Box_5

The same changes will be applicable if you are using search results web part.

Hope this article will helpful for some of our friends, if any other good alternative for this found please let me also know about it.

SharePoint 2013 Remove ‘Nothing here matches your search’ from search results web part

July 3, 2013 9 comments

Hi Friends,

SharePoint 2013 search have huge potential, with the integration of FAST and SharePoint search it becomes very powerful search solution. There are couple of new search web parts added like Content Search web part which is excellent search web part. New search result rendering mechanism called display templates is provided which are similar like JSON to HTML templates.

We will discuss a scenario about Search result web part and the solution related to the problem using display templates.

Scenario: If we add a search result web part on page and above that a search box web part to enter search term and according to that search term we want search result web part will display results. When we add both these web parts on page and before entering the search term also the results web part show  “Nothing here matches your search” (as shown in below image), which we don’t want to display unless we enter something in search box.

Search_Result_SP_2013

Obviously we may think that there will be some web part property available which will help us to resolve this issue, but web part do not have any property like this. Here come display templates in our help, we will see how we can use display templates to achieve this.

Search Results web part of SP 2013 uses ‘Control_SearchResults.html’ display template which is available under Master Page Library –> Display Templates –> Search.

Solution:

  1. Rename the ‘Control_SearchResults.html’ file to some other name e.g. ‘Control_Test_SearchResults.html’
  2. Open this file in any text editor like notepad.
  3. Change the Title in this HTML file(I have used Test Default Result for demo), this title will be available for selection in web part properties.
  4. Now we want to get the search text entered in to search box web part, for that we will use ctx object as following ctx.DataProvider.get_currentQueryState().k
  5. Search     if(ctx.ClientControl.get_shouldShowNoResultMessage()){    line in HTML file (as shown in below image).
    Search_Result_SP_2013_Display_Template_1
  6. Replace this line with
    var currentQueryTerm = ctx.DataProvider.get_currentQueryState().k; if(ctx.ClientControl.get_shouldShowNoResultMessage() && currentQueryTerm!=””){
    (As shown in below image)
    Search_Result_SP_2013_Display_Template_2
  7. Save the modified HTML file.
  8. Go to Master Page Library –> Display Templates –> Search and upload new control template.
  9. You will see that respective ‘Control_Test_SearchResults.js’ will be created by SharePoint.
  10. Now go to your page where Search Result web part is added, edit Search results web part. Under Display Templates section select newly uploaded display template.( as shown in below image).
    Search_Result_SP_2013_Display_Template_3
  11. Save the changes and that’s it, you will see the  expected result.