English 中文(简体)
如何节省Sql服务器中的超文本数据
原标题:How to save HTML data in Sql Server
问题回答

如果你重新使用2008年服务器,全文索引是一个很好的选择。 将其超文本储存在“最高”一栏,并将其相关档案类型定为“.html”。 全文索引员将数据作为超文本处理,只检索文本内容,而忽略超文本标签。

将数据储存在两个不同栏目中两次;一次是作为超文本储存,另一次是单纯文本。 是否从超文本栏显示,并对案文栏进行搜索。

另一种答案是,在进行搜捕之前,使用CTE来排除超文本。

下面的CTE摘录可能符合搜索标准的行文,可追溯性地排除了超文本。 然后,Query利用CTE的结果,过滤仍然含有超文本的浏览器和没有完全达到搜索标准的浏览器。

CTE是很复杂的。 大部分赛事是处理PATINDEX返回。

--** Test table
DECLARE @HTML TABLE (id INT IDENTITY, html VARCHAR(max))
INSERT INTO @HTML SELECT  This is a <span style="font-weight: bold; ">nice</span> question ;
INSERT INTO @HTML SELECT  The cat sat <span style="font-weight: bold; ">on the</span> mat ;

--** Search criteria
DECLARE @Search VARCHAR(50) =  is a nice ;

--** CTE to return the matching rows ignoring the HTML
;WITH Search_CTE (html_id, html_text)
AS (
    SELECT h.id AS  html_id 
         , LEFT(h.html,REPLACE(PATINDEX( %<% ,h.html)-1,-1,999999)) + SUBSTRING(h.html,CONVERT(INT,REPLACE(PATINDEX( %>% ,h.html)+1,1,999999)),LEN(h.html)) AS  html_text 
      FROM @HTML AS h
     WHERE h.html LIKE  %  + REPLACE(@Search,   , % ) +  % 
     UNION ALL
    SELECT c.html_id AS  html_id 
         , LEFT(c.html_text,REPLACE(PATINDEX( %<% ,c.html_text)-1,-1,999999)) + SUBSTRING(c.html_text,CONVERT(INT,REPLACE(PATINDEX( %>% ,c.html_text)+1,1,999999)),LEN(c.html_text)) AS  html_text 
      FROM Search_CTE AS c
     WHERE PATINDEX( %<% ,c.html_text) > 0
)
SELECT h.html AS  Original HTML 
     , cte.html_text AS  HTML Text 
  FROM Search_CTE AS cte
  JOIN @HTML AS h
    ON h.id = cte.html_id
 WHERE PATINDEX( %<% ,cte.html_text) = 0   --** Filter out rows still containing HTML
   AND html_text LIKE  %  + @Search +  % ; --** Filter out rows not matching the search criteria

这种质疑有限制,即它处理“......”或“......”的情况;在案文中,如果需要,可加以编码。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签