码迷,mamicode.com
首页 > 数据库 > 详细

Sql CLR

时间:2015-11-21 19:40:01      阅读:266      评论:0      收藏:0      [点我收藏+]

标签:

 

using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using System.IO;
using System.Text;
using System.Collections;
using System.Text.RegularExpressions;

 

/// <summary>
/// 匹配旅游线路多个关键词并获取权重。
/// </summary>
/// <param name="searchKeywords">客户端提交关键词(多个关键词之间以|号分隔)</param>
/// <param name="title">旅游线路标题</param>
/// <param name="dbKeywords">数据库中保存的搜索关键词(多个关键词之间以|号分隔)</param>
/// <returns></returns>
[Microsoft.SqlServer.Server.SqlFunction]
public static SqlDouble fun_CLR_MatchTripKeywords(string searchKeywords, string title, string dbKeywords)
{
//如果没有关键词直接返回1。
if (string.IsNullOrEmpty(searchKeywords))
return 1;

//如果没有索引数据直接返回0。
if (string.IsNullOrEmpty(title) && string.IsNullOrEmpty(dbKeywords))
return 0;

//权重值。
double boost = 0;

//分割字符串。
foreach (string _sk in searchKeywords.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries))
{
//匹配标题。
if (!string.IsNullOrEmpty(title) && title.IndexOf(_sk, StringComparison.OrdinalIgnoreCase) >= 0)
boost += 1;

//匹配数据库关键词字段。
if (!string.IsNullOrEmpty(dbKeywords) && dbKeywords.IndexOf(_sk, StringComparison.OrdinalIgnoreCase) >= 0)
boost += 0.8;
}

// 返回结果。
return boost;
}

Sql CLR

标签:

原文地址:http://www.cnblogs.com/lxf1117/p/4984327.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!