Implementing SearchIndex in Custome user controls

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
3/29/2012 3:59:50 AM
Gravatar
Total Posts 9

Implementing SearchIndex in Custome user controls

Hi Joe,

I need your kind help.

i created user controls , and i tried to implement search index builder in this control  but its not working.

<%@ Control Language="C#" ClassName="TopStoriesWithImage" AutoEventWireup="true"
Inherits="System.Web.UI.UserControl" %>
<%@ Import Namespace="System.Globalization" %>
<%@ Import Namespace="System.Xml.Xsl" %>
<%@ Import Namespace="System.Collections" %>
<%@ Import Namespace="System.Text.RegularExpressions" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Common" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data.SqlTypes" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<%@ Import Namespace="mojoPortal.Business" %>
<%@ Import Namespace="mojoPortal.Business.WebHelpers" %>
<%@ Import Namespace="mojoPortal.Web.Framework" %>
<%@ Import Namespace="mojoPortal.Web" %>
<%@ Import Namespace="mojoPortal.Web.Controls" %>
<%@ Import Namespace="mojoPortal.Web.UI" %>
<%@ Import Namespace="mojoPortal.Web.Editor" %>
<%@ Import Namespace="mojoPortal.Net" %>

<script runat="server">

string QueryStr = "";
string ConnStr = ConfigurationManager.AppSettings["MSSQLConnectionString"].ToString();
SqlConnection sqlconn;
SqlDataReader sqlRdr = null, sqlRdr1 = null;
DataTable sqlTable, sqlTable1;
public string headlineImg;
public string imgtip;

//#region IIndexableContent
//public event ContentChangedEventHandler ContentChanged;
//protected void OnContentChanged(ContentChangedEventArgs e)
//{
//    if (ContentChanged != null)
//    {
//        ContentChanged(this, e);
//    }
//}
//#endregion
//void TopStoriesWithImage_ContentChanged(object sender, ContentChangedEventArgs e)
//{
//    IndexBuilderProvider indexBuilder = IndexBuilderManager.Providers["HtmlContentIndexBuilderProvider"];
//    if (indexBuilder != null)
//    {
//        indexBuilder.ContentChangedHandler(sender, e);
//    }
//}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{

DispalyTopStroriesInBrief();

TopStoriesWithImage TopStories = new TopStoriesWithImage();
HtmlContent html = new HtmlContent();
IndexBuilderProvider indexBuilder = IndexBuilderManager.Providers["HtmlContentIndexBuilderProvider"];

if (indexBuilder != null)
{
html.ContentChanged += new ContentChangedEventHandler(indexBuilder.ContentChangedHandler);
}
html.Body = edContent.Text;  //ERROR:  edContent does not exist in the correct contest
html.Save();

//TopStoriesWithImage TopStories =new TopStoriesWithImage();
//TopStories.ContentChanged += new ContentChangedEventHandler(TopStoriesWithImage_ContentChanged);
//ContentChangedEventArgs si = new ContentChangedEventArgs();
//OnContentChanged(si);
}
}

public override void ContentChangedHandler(object sender, ContentChangedEventArgs e)
{
HtmlContent content = (HtmlContent)sender;
if (e.IsDeleted)
{
// get list of pages where this module is published
List<PageModule> pageModules
= PageModule.GetPageModulesByModule(content.ModuleId);

foreach (PageModule pageModule in pageModules)
{
IndexHelper.RemoveIndexItem(
pageModule.PageId,
content.ModuleId,
content.ItemId);
}
}
else
{
IndexItem(content);
}

}

private static void IndexItem(HtmlContent content)
{
SiteSettings siteSettings
= CacheHelper.GetCurrentSiteSettings();

if (
(content == null)
|| (siteSettings == null)
)
{
return;
}

Guid htmlFeatureGuid
= new Guid("881e4e00-93e4-444c-b7b0-6672fb55de10");
ModuleDefinition htmlFeature
= new ModuleDefinition(htmlFeatureGuid);
Module module = new Module(content.ModuleId);

// get list of pages where this module is published
List<PageModule> pageModules
= PageModule.GetPageModulesByModule(content.ModuleId);

foreach (PageModule pageModule in pageModules)
{
PageSettings pageSettings
= new PageSettings(
siteSettings.SiteId,
pageModule.PageId);

IndexItem indexItem = new IndexItem();
indexItem.SiteId = siteSettings.SiteId;
indexItem.PageId = pageSettings.PageId;
indexItem.PageName = pageSettings.PageName;
indexItem.ViewRoles = pageSettings.AuthorizedRoles;
if (pageSettings.UseUrl)
{
indexItem.ViewPage = pageSettings.Url.Replace("~/", string.Empty);
indexItem.UseQueryStringParams = false;
}

indexItem.FeatureName = htmlFeature.FeatureName;
indexItem.FeatureResourceFile = htmlFeature.ResourceFile;

indexItem.ItemId = content.ItemId;
indexItem.ModuleId = content.ModuleId;
indexItem.ModuleTitle = module.ModuleTitle;
indexItem.Title = content.Title;
indexItem.Content = content.Body;
indexItem.PublishBeginDate = pageModule.PublishBeginDate;
indexItem.PublishEndDate = pageModule.PublishEndDate;

IndexHelper.RebuildIndex(indexItem);
}

//log.Debug("Indexed " + content.Title);

}

private void DispalyTopStroriesInBrief()
{
try
{
SqlCommand sqlcmd, sqlcmd1;
//i = 0;
sqlTable = new DataTable();
sqlTable1 = new DataTable();
DataTable sqlTableTsImage = new DataTable();
sqlconn = new SqlConnection(ConnStr);
sqlconn.Open();

QueryStr = "Exec rm_USP_SelectingTopStories ";
sqlcmd = new SqlCommand(QueryStr, sqlconn);
sqlRdr = sqlcmd.ExecuteReader();
sqlTable.Load(sqlRdr);
sqlRdr.Close();
sqlconn.Close();
TopStoriesDataList1.DataSource = sqlTable;
TopStoriesDataList1.DataBind();

}
catch (Exception DisExcp) { }
if (sqlconn.State == ConnectionState.Open) { sqlconn.Close(); }
}

</script>
<portal:OuterWrapperPanel ID="pnlOuterWrap" runat="server">
<mp:CornerRounderTop id="ctop1" runat="server" EnableViewState="false" />
<portal:InnerWrapperPanel ID="pnlInnerWrap" runat="server" CssClass="panelwrapper htmlmodule">
<portal:ModuleTitleControl id="Title1" runat="server" EditUrl="/Modules/HtmlEdit.aspx" EnableViewState="false" />
<portal:OuterBodyPanel ID="pnlOuterBody" runat="server">
<portal:mojoRating runat="server" ID="Rating" Enabled="false" />
<portal:InnerBodyPanel ID="pnlContent" runat="server" CssClass="modulecontent">

<div class="ketopstoriesBx">
<div class="contshead">
<a class="tpheadtxt" href="moretopstories.aspx?Country=Nigeria&NewType=TopStories">Top
Most News Headlines</a>
</div>
<table>
<tr>
<td class="ketdtsheadlines">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td valign="top">
<div class="keconTSNews">
<asp:DataList ID="TopStoriesDataList1" runat="server">
<ItemTemplate>
<ul>
<li>

<a href="newsindetail.aspx?id=<%# Eval("TSGuid") %>&Type=<%# Eval("NewsType")%>">
<%# DataBinder.Eval(Container.DataItem, "HeadLine")%>
</a>
<p>
<%# DataBinder.Eval(Container.DataItem, "Details")%>... <span style="font-size: 8px;">
(<%# DataBinder.Eval(Container.DataItem, "SourceWebSite")%>)</span> <span class="emnewsdate">
<%# DataBinder.Eval(Container.DataItem, "EntryDate")%>.</span>
</p>
</li>
</ul>
</ItemTemplate>
</asp:DataList>
</div>
<div class="ketsmore">
<a href="moretopstories.aspx" style="width: 177px;">
More Headlines</a>
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</portal:InnerBodyPanel>
<portal:EmptyPanel id="divFooter" runat="server" CssClass="modulefooter" SkinID="modulefooter"></portal:EmptyPanel>
</portal:OuterBodyPanel>
<portal:EmptyPanel id="divCleared" runat="server" CssClass="cleared" SkinID="cleared"></portal:EmptyPanel>
</portal:InnerWrapperPanel>
<mp:CornerRounderBottom id="cbottom1" runat="server" EnableViewState="false" />
</portal:OuterWrapperPanel>

 

 

You must sign in to post in the forums. This thread is closed to new posts.