让DotNetNuke 4.3.5使用SQL Full-text index 查找用户信息
近日在开发DotNetNuke系统时,要实现一个查找站内注册用户信息的功能,我首先想到的就是系统自带的用户管理页面,因为系统自带的管理页面,在功能上,已经实现了大部份我要的功能,比如按用户名查找用户,按用户的其他Profile信息查找。
但有一个问题,那就是DotNetNuke自带的用户管理的查找功能很弱,对于稍稍不常见的中文查找就会出现找不到的情况,特别是查找公司名称,如果查找“北京三一重工有限公司”,如果用户只输入“三一”是不会返回任何结果的。那么能不能搭一搭SQL的Full-text index search这个顺风车呢?
经过一番研究(当中几千字日后再写.....),简单的解决方案如下:
在SQL数据库中找到如下的存储过程:
1、在企业管理器中,为UserProfile表的PropertyValue和PropertyText建立全文检索。
2、在SQL企业管理器中,点击“工具->查询分析器(Query Analyer)" 运行以下代码:
因为时间紧张,先写到这里,还有很多要补充的,并且这个解决方案直接改到了DotNetNuke系统的内核程序,不能向后兼容,写出来只是提供参考,解一时之急,正确的做法应该是写一个新的Provider,这个有时间再说吧。
但有一个问题,那就是DotNetNuke自带的用户管理的查找功能很弱,对于稍稍不常见的中文查找就会出现找不到的情况,特别是查找公司名称,如果查找“北京三一重工有限公司”,如果用户只输入“三一”是不会返回任何结果的。那么能不能搭一搭SQL的Full-text index search这个顺风车呢?
经过一番研究(当中几千字日后再写.....),简单的解决方案如下:
在SQL数据库中找到如下的存储过程:
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
ALTER PROCEDURE dbo.[GetUsersByProfileProperty]
@PortalId int,
@PropertyName nvarchar(256),
@PropertyValue nvarchar(256),
@PageIndex int,
@PageSize int
AS
BEGIN
-- Set the page bounds
DECLARE @PageLowerBound INT
DECLARE @PageUpperBound INT
SET @PageLowerBound = @PageSize * @PageIndex
SET @PageUpperBound = @PageSize - 1 + @PageLowerBound
-- Create a temp table TO store the select results
CREATE TABLE #PageIndexForUsers
(
IndexId int IDENTITY (0, 1) NOT NULL,
UserId int
)
-- Insert into our temp table
INSERT INTO #PageIndexForUsers (UserId)
SELECT U.UserId
FROM ProfilePropertyDefinition P
INNER JOIN UserProfile UP ON P.PropertyDefinitionID = UP.PropertyDefinitionID
INNER JOIN Users U ON UP.UserID = U.UserID
WHERE (PropertyName = @PropertyName) AND (PropertyValue LIKE @PropertyValue OR PropertyText LIKE @PropertyValue )
AND (P.Portalid = @PortalId OR (P.PortalId Is Null AND @PortalId is null ))
ORDER BY U.DisplayName
SELECT *
FROM vw_Users u,
#PageIndexForUsers p
WHERE u.UserId = p.UserId
AND ( PortalId = @PortalId OR (PortalId Is Null AND @PortalId is null ))
AND p.IndexId >= @PageLowerBound AND p.IndexId <= @PageUpperBound
ORDER BY U.DisplayName
SELECT TotalRecords = COUNT(*)
FROM #PageIndexForUsers
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
GO
SET ANSI_NULLS ON
GO
ALTER PROCEDURE dbo.[GetUsersByProfileProperty]
@PortalId int,
@PropertyName nvarchar(256),
@PropertyValue nvarchar(256),
@PageIndex int,
@PageSize int
AS
BEGIN
-- Set the page bounds
DECLARE @PageLowerBound INT
DECLARE @PageUpperBound INT
SET @PageLowerBound = @PageSize * @PageIndex
SET @PageUpperBound = @PageSize - 1 + @PageLowerBound
-- Create a temp table TO store the select results
CREATE TABLE #PageIndexForUsers
(
IndexId int IDENTITY (0, 1) NOT NULL,
UserId int
)
-- Insert into our temp table
INSERT INTO #PageIndexForUsers (UserId)
SELECT U.UserId
FROM ProfilePropertyDefinition P
INNER JOIN UserProfile UP ON P.PropertyDefinitionID = UP.PropertyDefinitionID
INNER JOIN Users U ON UP.UserID = U.UserID
WHERE (PropertyName = @PropertyName) AND (PropertyValue LIKE @PropertyValue OR PropertyText LIKE @PropertyValue )
AND (P.Portalid = @PortalId OR (P.PortalId Is Null AND @PortalId is null ))
ORDER BY U.DisplayName
SELECT *
FROM vw_Users u,
#PageIndexForUsers p
WHERE u.UserId = p.UserId
AND ( PortalId = @PortalId OR (PortalId Is Null AND @PortalId is null ))
AND p.IndexId >= @PageLowerBound AND p.IndexId <= @PageUpperBound
ORDER BY U.DisplayName
SELECT TotalRecords = COUNT(*)
FROM #PageIndexForUsers
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
1、在企业管理器中,为UserProfile表的PropertyValue和PropertyText建立全文检索。
2、在SQL企业管理器中,点击“工具->查询分析器(Query Analyer)" 运行以下代码:
use DotNetNuke(请更换为你使用的数据库名称)
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GetUsersByProfileProperty]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[GetUsersByProfileProperty]
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE dbo.[GetUsersByProfileProperty]
@PortalId int,
@PropertyName nvarchar(256),
@PropertyValue nvarchar(256),
@PageIndex int,
@PageSize int
AS
BEGIN
-- Set the page bounds
DECLARE @PageLowerBound INT
DECLARE @PageUpperBound INT
SET @PageLowerBound = @PageSize * @PageIndex
SET @PageUpperBound = @PageSize - 1 + @PageLowerBound
-- Create a temp table TO store the select results
CREATE TABLE #PageIndexForUsers
(
IndexId int IDENTITY (0, 1) NOT NULL,
UserId int
)
-- Insert into our temp table
INSERT INTO #PageIndexForUsers (UserId)
SELECT U.UserId
FROM ProfilePropertyDefinition P
INNER JOIN UserProfile UP ON P.PropertyDefinitionID = UP.PropertyDefinitionID
INNER JOIN Users U ON UP.UserID = U.UserID
WHERE (PropertyName = @PropertyName) AND (contains(PropertyValue,@PropertyValue) OR contains(PropertyText,@PropertyValue ))
AND (P.Portalid = @PortalId OR (P.PortalId Is Null AND @PortalId is null ))
ORDER BY U.DisplayName
SELECT *
FROM vw_Users u,
#PageIndexForUsers p
WHERE u.UserId = p.UserId
AND ( PortalId = @PortalId OR (PortalId Is Null AND @PortalId is null ))
AND p.IndexId >= @PageLowerBound AND p.IndexId <= @PageUpperBound
ORDER BY U.DisplayName
SELECT TotalRecords = COUNT(*)
FROM #PageIndexForUsers
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[GetUsersByProfileProperty]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[GetUsersByProfileProperty]
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE dbo.[GetUsersByProfileProperty]
@PortalId int,
@PropertyName nvarchar(256),
@PropertyValue nvarchar(256),
@PageIndex int,
@PageSize int
AS
BEGIN
-- Set the page bounds
DECLARE @PageLowerBound INT
DECLARE @PageUpperBound INT
SET @PageLowerBound = @PageSize * @PageIndex
SET @PageUpperBound = @PageSize - 1 + @PageLowerBound
-- Create a temp table TO store the select results
CREATE TABLE #PageIndexForUsers
(
IndexId int IDENTITY (0, 1) NOT NULL,
UserId int
)
-- Insert into our temp table
INSERT INTO #PageIndexForUsers (UserId)
SELECT U.UserId
FROM ProfilePropertyDefinition P
INNER JOIN UserProfile UP ON P.PropertyDefinitionID = UP.PropertyDefinitionID
INNER JOIN Users U ON UP.UserID = U.UserID
WHERE (PropertyName = @PropertyName) AND (contains(PropertyValue,@PropertyValue) OR contains(PropertyText,@PropertyValue ))
AND (P.Portalid = @PortalId OR (P.PortalId Is Null AND @PortalId is null ))
ORDER BY U.DisplayName
SELECT *
FROM vw_Users u,
#PageIndexForUsers p
WHERE u.UserId = p.UserId
AND ( PortalId = @PortalId OR (PortalId Is Null AND @PortalId is null ))
AND p.IndexId >= @PageLowerBound AND p.IndexId <= @PageUpperBound
ORDER BY U.DisplayName
SELECT TotalRecords = COUNT(*)
FROM #PageIndexForUsers
END
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
因为时间紧张,先写到这里,还有很多要补充的,并且这个解决方案直接改到了DotNetNuke系统的内核程序,不能向后兼容,写出来只是提供参考,解一时之急,正确的做法应该是写一个新的Provider,这个有时间再说吧。
分类:
DotNetNuke
, SQL Server
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· [AI/GPT/综述] AI Agent的设计模式综述