DNN 7 has introduced a brand new, Lucene-powered indexing and search results retrieval mechanism. This implies that all strategies you knew are not in impact any more. No much more SQL queries and/or tables, information get returned in JSON format and rendered via Javascript.
This adds a whole lot of new functionality but additionally a great deal of limitations inside the way Search Benefits are presented. Actually, there in no way was a simple method to customize Search Outcomes, but until now you might just edit SearchResults.ascx and its corresponding code-behind file and have your preferred result.

Things are still ugly regarding customization. The default Search Results layout includes a hyperlink guiding you to sophisticated search concepts, an "Advanced" type that asks you to provide a variety of information like exactly where you want to search (categorized by module variety) and so forth.
This does not constantly make sense to finish customers, and some components need to be removed in certain scenarios. Customers don't always want advanced search possibilities, nor do they ought to know what type of modules your website includes. In some instances they do not give a damn regarding the author, or the last modified date too. But there is no immediate approach to configure what is going to be displayed and what is going to be not.
Additionally, till now you might face the issue of default module titles (which customers normally leave as is since they're making use of containers that didn't incorporate the module title) by tweaking the way module titles have been inserted in the SearchItem table (see this older post for a lot more). Because no SQL tables are employed any more, you happen to be left with ugly "Text/HTML" and other default titles in Search Outcomes. The JSON returned for each and every search result item just consists of a title that's typically created of a concatenation from the tab's name as well as the module's title (or, inside the case of grouped outcomes, just the module's title).
Furthermore, getting a module having a BLANK title is no longer an selection considering that modules with blank titles will not be indexed(!).
So le't see how we are able to address all of the above with some modifications on particular files. Be warned that what I am saying here applies to version 7.1 and might or could not be in effect for future DNN versions, at the same time as that those adjustments are not upgrade-proof, which means that should you upgrade your website to a greater DNN version you might shed them. But, it is far better than absolutely nothing. :)
Make sure to get a backup of each of the files you're going to modify in case some thing goes incorrect!
Let's start.
Hiding the "advanced" link
File: dnn.SearchResult.js
Location: DesktopModules\Admin\SearchResults
Go to line 343, you will see a call to the DnnSearchBox like the following
dnn.searchResult.searchInput = $('#dnnSearchResult_dnnSearchBox').dnnSearchBox({
id: 'dnnSearchResult_dnnSearchBox',
filterText: dnn.searchResult.defaultSettings.advancedText,
showAdvanced: true,
advancedId: 'dnnSearchResultAdvancedForm',
Locate this line:
showAdvanced: true,
And change it to
showAdvanced: false,
This is an option that you can't access via the module settings and it hides the "advanced" link. Unfortunately, the form that would pop up will still be visible at the bottom of the page so you have to take an extra step:
File: SearchResults.ascx
Location: DesktopModules\Admin\SearchResults
Go to around line 55 and you'll see a DIV element surrounding the elements of the Advanced form, like the following:
<div id="dnnSearchResultAdvancedForm" class="dnnForm">
<div class="dnnFormItem">
<dnn:Label ID="lblAdvancedTags" runat="server" ResourceKey="lblAdvancedTags" />
<input type="text" id="advancedTagsCtrl" />
</div>
<div class="dnnFormItem">
...
Add a style="display:none;" attribute to the outer div to hide the whole form.
If you need the advanced form but do not need to show specific controls, you can just skip the steps above, go at this point and just add a style="display:none;" attribute to any of the DIVs nested inside to hide the specific control you don't need (e.g. Scope)
Hide Advanced Tips link
File: dnn.SearchResult.js
Location: DesktopModules\Admin\SearchResults
Go to line 359 (it's empty), just above this piece of code:
$('a.dnnSearchResultAdvancedTip').on('click', function () {
$('#dnnSearchResult-advancedTipContainer').slideToggle('fast');
return false;
});
And insert the following line:
$('a.dnnSearchResultAdvancedTip').hide();
Alternatively, you can achieve the same result by adding a style="display:none;" attribute at the A tag in SearchResults.ascx, line 6:
<a href="javascript:void(0)" class="dnnSearchResultAdvancedTip"><%= LinkAdvancedTipText %></a>
Hide Results by Page / Sort section
File: SearchResults.ascx
Location: DesktopModules\Admin\SearchResults
Go to line 13 and add a style="display:none;" attribute to the outer DIV element there (first element in code snippet below):
<div class="dnnSearchResultPanel">
<div class="dnnRight">
<ul class="dnnSearchResultSortOptions">
<li class="active"><a href="#byRelevance"><%= RelevanceText %></a></li>
<li><a href="#byDate"><%= DateText %></a></li>...
If you hide this section but you need to specify a different sort order and/or results per page setting, you can alter the Javascript call at the same file, line 116 onwards, by altering the sortOption and pageSize initial values:
$(function () {
if(typeof dnn != 'undefined' && dnn.searchResult){
dnn.searchResult.moduleId = <%= ModuleId %>;
dnn.searchResult.queryOptions = {
searchTerm: '<%= SearchTerm %>',
sortOption: 0,
pageIndex: 1,
pageSize: 15
};
sortOption can be 0 for date, 1 for relevance.
pageSize can be anything you need.
Hide various elements on Search Results
Well, some people don't like the "last updated" information. Others don't like the "author" info. So let's see how we get rid of anything we don't need:
File: dnn.SearchResult.js
Location: DesktopModules\Admin\SearchResults
Start from about line 112,where you'll see code like this:
markup += '<div class="dnnSearchResultItem-Others">';
markup += '<span>' + dnn.searchResult.defaultSettings.lastModifiedText + ' </span>';
markup += data.DisplayModifiedTime;
markup += '</div>';
markup += '<div class="dnnSearchResultItem-Others">';
markup += '<span>' + dnn.searchResult.defaultSettings.sourceText + ' </span>';
Comment lines 112 to 115 to get rid of the "last updated" text
Comment lines 117 to 119 to get rid of the "source" text and link
Comment lines 121 to 123 to get rid of author info
Comment lines 126 to 135 to get rid of 'tags" info
Hide default HTML module titles (if any)
As mentioned earlier, you may not want module titles to appear in search results, but they do, even if your container doesn't display the module's title. The most common is "Text/HTML" and we'll see how to get rid of it in Search Results.
File: dnn.SearchResult.js
Location: DesktopModules\Admin\SearchResults
Scroll down to the bottom of the file and append this function at the end:
function fixTitle (s) {
if (s=='Text/HTML') {
return ('...');
}
var s1;
var s2;
s1=s.substring(0,s.indexOf('>')-1);
s2=s.substring(s.indexOf('>')+2, s.length);
if (s2=='Text/HTML' || s2==s1) {
return (s1);
}
else
{
return (s);
}
}
This function accepts a search result item title and first checks if the title is "Text/HTML". If so, it returns three dots ("...") instead. You will find this in grouped results, where the module title is displayed on its own.
If the title does not belong to a group subset, it'll be in the format "xxx > yyy" where xxx is the page's name and yyy is the module's title. The code breaks the string in its two parts and checks if the second part is equal to "Text/HTML". If so, it returns only the first part (the page's name). Also, if both parts are the same it once more returns the first part. Useful when a module has the same title as the page and you don't want to see this in search results.
This is not the best possible solution, but it's a decent workaround, provided that you don't have the character ">" anywhere in your module titles or page names. I know it can get better, but this is only to demonstrate how you can do it.
In order to put our function into effect, we have to go to line 107:
markup += '<a href="' + data.DocumentUrl + '"' + dnn.searchResult.defaultSettings.linkTarget + '>' + data.Title + '</a></div>';
and replace data.Title with fixTitle(data.Title):
markup += '<a href="' + data.DocumentUrl + '"' + dnn.searchResult.defaultSettings.linkTarget + '>' + fixTitle(data.Title) + '</a></div>';
Hide subsets (grouped results)
If, for some reason, you don't want to have any grouped results then you can comment out the code that is generating them. Be adviced that the result that was supposed to be grouped won't display a description underneath, just the title and link.
File: dnn.SearchResult.js
Location: DesktopModules\Admin\SearchResults
Go to line 159 and comment the code there until line 161:
// render subsets
for (var j = 0; j < result.Results.length; j++) {
markup += '<div class="dnnSearchResultItem-Subset">' + dnn.searchResult.renderResult(result.Results[j]) + '</div>';
}
Finally, if you tamper with the way search results are rendered, you may not want to have auto-search (search-as-you-type) get in your way by rendering everything in a different way (e.g. using default text/html module titles). There is no option for disabling it, but we can always hack the code a little more:
File: SearchSkinObjectPreview.js
Location: Resources\search
Go to line 137 and comment out this piece of code (until line 155):
throttle = setTimeout(function() {
var service = $.dnnSF ? $.dnnSF(-1) : null;
var url = makeUrl(val, service);
if (url) {
$.ajax({
url: url,
beforeSend: service ? service.setModuleHeaders : null,
success: function(result) {
if (result)
generatePreviewTemplate(result);
},
error: function() {
},
type: 'GET',
dataType: 'json',
contentType: "application/json"
});
}
}, self.settings.delayTriggerAutoSearch);
This will prevent the Search skin object from auto-searching.
Well, that's all! Even if line numbers change with an upgrade, you have a reference point on what to seek in code. I know this is not the prettiest or the most accurate and bullet-proof solution in the world, but until DNN Corp.