让.Text的搜索引擎支持二级域名

博主在做.Text Blog的Wap版时,考虑到手机输入难,为其添加二级域名支持并优化地址分析功能。但.Text搜索引擎不支持该域名方式,于是对其搜索引擎进行修改,还介绍了对Web.config的修改及相关类方法的改动。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近在做.Text Blog的Wap版,因为手机上输入比电脑上更难,所以,如果用户手动输入地址访问Blog的话,会对没有意义又繁长的URL非常反感,所以,花了点时间做了.Text对二级域名的支持并对其地址分析功能做了些优化,可是做好后发现,.Text的搜索引擎并不支持这种域名方式,没办法,只好对它的搜索引索又动了点小手术。(博客园现在有点慢啊)

1、对Web.config的修改:

None.gif      < SearchConfiguration  type ="Dottext.Search.SearchConfiguration, Dottext.Search"  urlFormat ="http://{1}{0}/Blog/{2}/{3}.aspx"
None.gif        virtualPath
="~/SearchIndex"  physicalPath ="D:\Code\MSS1\Blog\DotTextWeb\SearchIndex"  domains =".tzl.com"
None.gif        pageSize
="20"   />

其中http://{1}{0}/Blog/{2}/{3}.aspx中的Blog是你的应用程序名,比如你的程序在www.blog.com/blog下,注意domains不要加上www之类的

2、将Dottext.Search.EntryData类的CreateDoc(IDataReader reader)方法改成这样

None.gif          private  Document CreateDoc(IDataReader reader)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            
//Null values are not allowed in the index
InBlock.gif
            
InBlock.gif            Document doc 
= new Document();
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                doc.Add(Field.Text(SearchConfiguration.Author,(
string)reader["Author"]));
InBlock.gif
InBlock.gif                doc.Add(Field.Text(SearchConfiguration.Title,(
string)reader["Title"]));
InBlock.gif
InBlock.gif                
string body = (string)reader["Text"];
InBlock.gif                doc.Add(Field.UnIndexed(SearchConfiguration.Body,body));
InBlock.gif                doc.Add(Field.Text(SearchConfiguration.Link,
string.Join(" ",GetLinks(body))));
InBlock.gif                doc.Add(Field.Text(SearchConfiguration.RawPost,regexStripHTML.Replace(body,
string.Empty)));
InBlock.gif
InBlock.gif                DateTime dateCreated 
= (DateTime)reader["DateAdded"];
InBlock.gif                doc.Add(Field.UnIndexed(SearchConfiguration.DateCreated,dateCreated.ToLongDateString()));
InBlock.gif
InBlock.gif                
string app = (string)reader["Application"];
InBlock.gif                doc.Add(Field.Text(SearchConfiguration.Blog,app));
InBlock.gif
InBlock.gif                
//Do we really need this?
InBlock.gif                
//doc.Add(Field.Text(SearchConfiguration.Description,reader["Description"].ToString()));
InBlock.gif

InBlock.gif                
string host = (string)reader["Host"];
InBlock.gif                doc.Add(Field.Text(SearchConfiguration.Domain,host));
InBlock.gif
InBlock.gif
InBlock.gif                
int posttype = (int)reader["PostType"];        
InBlock.gif                doc.Add(Field.UnIndexed(SearchConfiguration.PostType,posttype.ToString()));
InBlock.gif
InBlock.gif                
string permaLink  = null;
InBlock.gif                SearchConfiguration searchConfig 
= SearchConfiguration.Instance();
InBlock.gif                
if((PostType)posttype == PostType.BlogPost)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
//permaLink = string.Format(SearchConfiguration.Instance().UrlFormat,host,app, "archive/" + dateCreated.ToString("yyyy'/'MM'/'dd"),reader["EntryID"]);
InBlock.gif
                    permaLink = string.Format(searchConfig.UrlFormat,searchConfig.Domains,app, "archive/" + dateCreated.ToString("yyyy'/'MM'/'dd"),reader["EntryID"]);
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else if((PostType)posttype == PostType.Comment)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    permaLink 
=    reader["SourceUrl"].ToString()+"#"+reader["EntryID"].ToString();
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
//permaLink = string.Format(SearchConfiguration.Instance().UrlFormat,host,app, "articles",reader["EntryID"]);
InBlock.gif
                    permaLink = string.Format(searchConfig.UrlFormat,searchConfig.Domains,app, "articles",reader["EntryID"]);
ExpandedSubBlockEnd.gif                }

InBlock.gif
InBlock.gif                
int feedbackCount = (int)reader["FeedbackCount"];
InBlock.gif                
int webviewCount = (int)reader["WebViewCount"];
InBlock.gif
InBlock.gif                
int boost = weighter.Calculate(body.Length,feedbackCount,webviewCount,dateCreated,(PostType)posttype);
InBlock.gif                doc.SetBoost(boost);
InBlock.gif
InBlock.gif                doc.Add(Field.UnIndexed(SearchConfiguration.BoostFactor,boost.ToString()));
InBlock.gif
InBlock.gif                doc.Add(Field.UnIndexed(SearchConfiguration.PermaLink,permaLink));
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch(Exception e)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Dottext.Framework.Logger.LogManager.Log(
"CreateDoc Fail","EntryID is "+reader["EntryID"]);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
InBlock.gif            
return doc;
ExpandedBlockEnd.gif        }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值