久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

T-SQL 存儲過程返回谷歌風(fēng)格的“建議"搜索結(jié)

T-SQL stored procedure to return google style quot;suggestedquot; search results(T-SQL 存儲過程返回谷歌風(fēng)格的“建議搜索結(jié)果)
本文介紹了T-SQL 存儲過程返回谷歌風(fēng)格的“建議"搜索結(jié)果的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

好的,使用 SQL Server 2008.在我的網(wǎng)頁上,我有一個帶有 jQ??uery-UI AutoComplete 的文本框.

現(xiàn)在我需要一個存儲過程來搜索來自文本框/自動完成 AJAX 調(diào)用的搜索字符串,并返回建議的"搜索字符串.我正在使用 AdventureWorks db 進(jìn)行測試(產(chǎn)品表)

例如,產(chǎn)品表包含產(chǎn)品名稱和產(chǎn)品編號(以及其他)列,我想根據(jù)用戶輸入返回建議的搜索字符串,他們可以在其中輸入產(chǎn)品名稱和/或產(chǎn)品編號.

我讓它在一個簡單的列中工作.有什么想法嗎?

解決方案

我將建議全文搜索(MS 或 Lucene 可以工作) 下面的代碼使用 MSSQL FTS 作為我在我的應(yīng)用程序中使用的瞬間.

如果您還沒有安裝 FTS 搜索.如果你有檢查服務(wù)正在運(yùn)行.在管理工作室中運(yùn)行它來設(shè)置目錄并添加產(chǎn)品表;和顏色/名稱/產(chǎn)品編號到目錄.

使用 [AdventureWorks]走創(chuàng)建全文目錄 [ProductsTest]WITH ACCENT_SENSITIVITY = OFF授權(quán) [dbo]走使用 [AdventureWorks]走CREATE FULLTEXT INDEX ON [Production].[Product] KEY INDEX [PK_Product_ProductID] ON ([ProductsTest]) WITH (CHANGE_TRACKING AUTO)走使用 [AdventureWorks]走ALTER FULLTEXT INDEX ON [Production].[Product] ADD ([Color])走使用 [AdventureWorks]走ALTER FULLTEXT INDEX ON [Production].[Product] ADD ([Name])走使用 [AdventureWorks]走ALTER FULLTEXT INDEX ON [Production].[Product] ADD ([ProductNumber])走使用 [AdventureWorks]走ALTER FULLTEXT INDEX ON [Production].[Product] ENABLE走

然后您可以一次對所有列運(yùn)行查詢;例如銀色(選擇顏色和名稱)

Select * from production.product wherecontains(*, '"銀*"')

查詢中的 * 會找到 Silver*,因此您可以在用戶輸入時使用它來構(gòu)建結(jié)果.需要考慮的一件事是 google 實(shí)時進(jìn)行這項工作 - 如果您要搜索大量數(shù)據(jù)能夠在不中斷用戶打字的情況下取回數(shù)據(jù).我認(rèn)為通常人們通過從他們正在尋找的第一個字母開始輸入來使用這些搜索 - 我接受會有拼寫錯誤 - 你可以在他們按下的每個空格之后實(shí)施拼寫檢查器,也許可以處理這個問題.或者存儲運(yùn)行的搜索并查看拼寫錯誤并更改代碼以根據(jù)映射(或使用自定義同義詞庫在 FTS 中處理).

排名對任何企業(yè)來說都是一個有趣的發(fā)展問題;您是在尋找 Mountain Frame 的第一個結(jié)果 - 還是想按銷售額或價格對它們進(jìn)行加權(quán)?如果用戶輸入多個文本術(shù)語,您可以使用 FTS 根據(jù)搜索字符串生成排名.

選擇aa.rank, bb.*來自 containstable(production.product, *, '"Mountain" and "Silver*"') aa內(nèi)連接生產(chǎn).product bb在 aa.[key] = bb.productid按等級降序排列

這將返回 30 行;并根據(jù)用戶輸入的文本進(jìn)行權(quán)重來確定第一名記錄.在任何一種情況下,您都可能希望添加編碼排名來調(diào)整結(jié)果以滿足您的業(yè)務(wù)需求 - 對價格最高的小部件 1 進(jìn)行排名可能不是這樣.這就是為什么您要存儲人們搜索/點(diǎn)擊的內(nèi)容,以便稍后分析結(jié)果.

有一個非常好的語言解析器用于 .Net 進(jìn)行翻譯輸入到 FTS'able 語言中的谷歌樣式字符串查詢,可讓您熟悉使用您網(wǎng)站的任何布爾搜索.

您可能還想通過審核用戶輸入的內(nèi)容并最終訪問并使用成功地圖來更改最終建議,以使其真正與用戶相關(guān),從而添加一些群體智慧功能.

最后的建議,如果這是一個商業(yè)網(wǎng)站,你可能想看看 Easyask,這是一個可怕的偉大的自然語言處理器>

Ok, using SQL Server 2008. On my web page I have a textbox with jQuery-UI AutoComplete hooked up.

Now I need a stored procedure to search across all columns of a single table(or multiple joined tables I suppose) for a search string coming from the textbox/autocomplete AJAX call, and return "suggested" search strings. I am using the AdventureWorks db for testing(Products table)

So for example, the product table has columns for product name and product number(among others) and I want to return suggested search strings based on user input where they may enter a product name and/or a product number.

I have it working across a single column which was simple. Any ideas?

解決方案

I'm going to suggest full text search (MS' or Lucene will work) The code below use MSSQL FTS as its what I use in my app at the moment.

Install FTS Search if you haven't already. If you have check the service is running. In management studio run this to setup a catalog and add the products table; and Color / Name / Product Number to the catalog.

USE [AdventureWorks]
GO
CREATE FULLTEXT CATALOG [ProductsTest]WITH ACCENT_SENSITIVITY = OFF
AUTHORIZATION [dbo]

GO

USE [AdventureWorks]
GO
CREATE FULLTEXT INDEX ON [Production].[Product] KEY INDEX [PK_Product_ProductID] ON ([ProductsTest]) WITH (CHANGE_TRACKING AUTO)
GO
USE [AdventureWorks]
GO
ALTER FULLTEXT INDEX ON [Production].[Product] ADD ([Color])
GO
USE [AdventureWorks]
GO
ALTER FULLTEXT INDEX ON [Production].[Product] ADD ([Name])
GO
USE [AdventureWorks]
GO
ALTER FULLTEXT INDEX ON [Production].[Product] ADD ([ProductNumber])
GO
USE [AdventureWorks]
GO
ALTER FULLTEXT INDEX ON [Production].[Product] ENABLE
GO

You can then run queries against all columns at once; e.g. Silver (Chosen as its in color and Name)

Select * from production.product where
contains(*, '"Silver*"')

The * on the query will find Silver* so you can use this to build up results as the user types in. One thing to consider is that google make this work in real time - if you are searching a lot of data you to be able to get the data back without interrupting the typing of the user. i think generally people use these searches by typing from the first letter they are looking for - i accept there will be spelling mistakes- you could implement a spell checker after every space they press perhaps to handle that. Or store the searches that are run and look at the mispellings and change the code to handle that based on a mapping (or in FTS using a custom thesaurus.)

Ranking is going to be a fun development issue to any business; are you finding the first result for Mountain Frame -or do you want to weight them by sales or price? If the user types in more than one text term you can use FTS to produce a ranking based on the search string.

select aa.rank, bb.* 
From containstable(production.product, *, '"Mountain" and "Silver*"') aa
inner join production.product bb
on aa.[key] = bb.productid
order by rank desc

This returns 30 rows; and weights based on the user inputted text to determine the first place record. In either case you will likely want to add a coded ranking to tweak the results to suit your business desires - ranking te highest priced widget 1 might not be the way. That is why you are going to store what people searched for / clicked on so you can analyse the results later.

There is a really nice language parser for .Net that translates a google style string query inputted into FTS'able language which gives familiarity for any boolean searches that use your site.

You may also want to add some wisdom of crowds features by auditing against what users have input and ultimately gone to visit and use success maps to alter the final suggestions to actually make them relevant to the user.

As a final suggestion if this is a commercial website you might want to look at Easyask which is a scary great natural language processor

這篇關(guān)于T-SQL 存儲過程返回谷歌風(fēng)格的“建議"搜索結(jié)果的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

SQL trigger on Truncate(截斷時的 SQL 觸發(fā)器)
sql search query with multiple optional search parameters(具有多個可選搜索參數(shù)的 sql 搜索查詢)
SQL Efficiency: WHERE IN Subquery vs. JOIN then GROUP(SQL 效率:WHERE IN 子查詢 vs. JOIN 然后 GROUP)
Retrieving XML element name using t-SQL(使用 t-SQL 檢索 XML 元素名稱)
Insert double quotes into SQL output(在 SQL 輸出中插入雙引號)
Delete rows from CTE in SQL SERVER(從 SQL SERVER 中的 CTE 中刪除行)
主站蜘蛛池模板: 国产欧美精品一区二区色综合朱莉 | 午夜影院在线免费观看视频 | 久久免费国产视频 | 天天干天天色 | 综合久久综合久久 | av一级| 精品国产91亚洲一区二区三区www | 亚洲国产精品99久久久久久久久 | 五月激情婷婷六月 | 亚洲网址 | 在线日韩在线 | 日韩午夜影院 | 久久久久国产 | 国内自拍视频在线观看 | 精品国产18久久久久久二百 | 国产欧美精品一区二区色综合朱莉 | 国产成人免费视频 | 欧美 中文字幕 | 欧美在线国产精品 | 亚洲高清视频在线观看 | 一级黄色片日本 | 成人免费大片黄在线播放 | 9久久精品 | 毛片大全 | 亚洲精品电影在线观看 | 午夜在线视频一区二区三区 | 久久久久久久久久久一区二区 | 久久国产精品72免费观看 | 亚洲一区视频在线播放 | 亚洲一区二区精品视频 | 国产一区精品在线 | aaa级片| www.久草.com| 超碰国产在线 | 成人在线精品视频 | 欧美日韩久久 | h小视频 | 中文字幕在线免费视频 | 99精品久久久久久久 | 国产精品亚洲综合 | 久久久www成人免费无遮挡大片 |