Thursday, March 11, 2010
 
   
 
O-SE: avoid menu entries in your search results   Minimize
Location: BlogsOpenDNN blogOpen-SearchEngine    
Posted by: Xepient Solutions 2/10/2009
We often get the question: how do I prevent the items in the menu from showing-up in the search results? Here are some answers.

As of version 2.1 of O-SE, there is really no way to exclude portions of the content of a page. 
Generally, the text from the menu and breadcrumbs is showing-up when you enter a search word that matches a menu title.

O-SE indexes the content of the whole page as shown in a browser, thus it does not know that the text is coming from a menu.

There is a workaround suggested by one of our clients, that we thought was brilliant.

He changed the names of his menus so as to contain an html representation of the character, instead of the character itself.

For example: if you have a menu item called "menu item", you could edit its name to be: "menu item"

where "m" is the html encoded representation of "m".

The result of this change will be that to the regular user, the menu will still be represented normally, but to Open-SearchEngine, it will not match a search on "menu item", thus it will not be rendered in the search results.

there is a list of symbols here:
http://www.avenue-it.com/html/asciialphabet.html

Building on this first suggestion, Keith Flores graciously offered an automated way of doing this, by adding a little javascript to the DNN skin:

 

<|code|>//************************************************************//
// AHB hack to make Open-SearchEngine index pages properly by
// HTMLencoding menu text on each page automatically, which
// keeps the Admin user from having to do it manually each time
// a "Page Name" is added (on a new page) or changed (on an
// existing page).
//************************************************************//

if (document.getElementById("dnn_ctr_ManageTabs_txtTabName")) {
// EXISTING pages which will already have a Page Name; idea is to change
// ASCII character to a regular character while Page Settings are being viewed
// If a page currently has the old way of first character not being ASCII format,
// nothing will happen to it until page is saved.

var pageName = document.getElementById("dnn_ctr_ManageTabs_txtTabName").value;

if (pageName.charAt(0) == "\&") { // Is first character of Page Name an ampersand
// Modify Page Name at page load from ASCII code to character

var colonIndex = pageName.indexOf(";");
var cutAscii = pageName.substring(0,colonIndex+1); // Extract ASCII code
var cutPageName = pageName.substring(colonIndex+1); // Extract page name without ASCII code
var cutNum = pageName.substring(2,colonIndex); // Extract ASCII number
var firstChar = String.fromCharCode(cutNum); // Convert ASCII number to character

document.getElementById("dnn_ctr_ManageTabs_txtTabName").value = firstChar + cutPageName;
}

// Add onclick when page is saved to convert first character of Page Name into
// ASCII format
var updateButton = document.getElementById("dnn_ctr_ManageTabs_cmdUpdate");

updateButton.onclick = function() {
// For NEW or EXISTING pages, on page save, change first character of
// Page Name to ASCII code which makes Open-Search Engine ignore the page's
// title in the HTML menus

var pageName = document.getElementById("dnn_ctr_ManageTabs_txtTabName").value;
var strCharEnc = pageName.charCodeAt(0); // ASCII encode first character in Page Name

document.getElementById('dnn_ctr_ManageTabs_txtTabName').value = "\&#" + strCharEnc + ";" + pageName.substr(1);
}
}
<|/code|>

 

Thanks to Keith Flores for providing the code.

Permalink |  Trackback

Comments (7)   Add Comment
Re: O-SE: avoid menu entries in your search results    By Svein Berger on 2/23/2009
Hi, thanks for a great product. I am new to DotNetNuke, and to your search engine. Please give me some more information to how I include Keith Flores javascript to a DNN skin. <br><br>Regards<br>Svein

Re: O-SE: avoid menu entries in your search results    By host on 2/23/2009
Hi Sevein,<br><br>Keith's code needs to be placed in the Default.aspx page. preferably, within the Header tag.<br><br>Best Regards

Re: O-SE: avoid menu entries in your search results    By CCDCC on 3/2/2009
What if your using a 3rd party nav. We're using dnn360 CISS.SIDEMENU and so far I don't think this trick is working for me.

Re: O-SE: avoid menu entries in your search results    By host on 3/2/2009
CCDCC, sorry, but we are not not familiar with the menu you are using. The javascript is probably not woirking because it needs menu specific entries, however, you should be able to change those delimiters of control names to suite your needs. If not, you should still be able to write your page names (in the settings of each page), liek suggested in teh first part of the article.<br>

Re: O-SE: avoid menu entries in your search results    By Barry S on 6/3/2009
Is this code complete? Looking at the javascript there are no named functions and there are closing brackets but no opening ones.<br><br>Also, where do you hook the javascript into? I'm assuming there is some menu load event that occurs, but have not been able to find it.<br><br>It will be really nice to implement this as our site page names use general search terms so we are getting a lot of duplicates as a result.

Re: O-SE: avoid menu entries in your search results    By host on 6/3/2009
Hello Barry,<br><br>we have not tested the code, but we believe it is complete, as it was reported working. If there is no hook, it is probably because it will be executed automatically when the page is loaded.<br>

Re: O-SE: avoid menu entries in your search results    By kfc on 8/19/2009
This solution can cause problems with SEO, because searchers will pass these menu items too.


Your name:
Title:
Comment:
Security Code
Enter the code shown above in the box below
Add Comment   Cancel 
     
Search the Blog   Minimize
     
Blog List   Minimize
     
Blog Archive   Minimize