0

我是使用 SQL Server 自由文本索引的新手。我编写了一个查询,我想将其转换为 EF Core Linq 查询。

如果可能,我不是(如果不是,我将创建一个存储过程),但理想情况下,我想在 C# 中构建它,因为其他一些查询将比这个更动态,并且 id 宁愿没有多个存储过程。

这是查询:

declare @searchTerm varchar(50) = '16 Sorrento';
declare @postcode varchar(50) = 'CF10 4AR';
declare @language varchar(3) = 'ENG';
declare @offset int = 0;
declare @limit int = 100;

select 
    RankTotal = isnull(RankSAONDetails, 0) + isnull(RankPAONDetails, 0) + 
                isnull(RankStreet, 0) + isnull(RankWard, 0) + 
               isnull(RankPostcode, 0),
    Id, UPRN, ParentUPRN, USRN, SAONDetails, PAONDetails, 
    Street, Ward, PostTown, Postcode, Easting, Northing, 
    Usage, Language, LastUpdateDate, DateExtracted
from
    LLPG
left join 
    (select Rank * 3.0 as RankSAONDetails, [KEY] 
     from FREETEXTTABLE(LLPG, SAONDetails, @searchTerm)) as k on k.[key]= LLPG.Id
left join 
    (select Rank * 4.0 as RankPAONDetails, [KEY] 
     from FREETEXTTABLE(LLPG, PAONDetails, @searchTerm)) as l on l.[key]= LLPG.Id
left join 
    (select Rank * 3.0 as RankStreet, [KEY] 
     from FREETEXTTABLE(LLPG, Street, @searchTerm)) as m on m.[key]= LLPG.Id
left join 
    (select Rank * 3.0 as RankWard, [KEY] 
     from FREETEXTTABLE(LLPG, Ward, @searchTerm)) as w on w.[key]= LLPG.Id
left join 
    (select Rank * 10.0 as RankPostcode, [KEY] 
     from FREETEXTTABLE(LLPG, Postcode, @searchTerm)) as p on p.[key]= LLPG.Id
where
    LLPG.Language = @language and
    StatusCode = 1 and
    LPIStatusCode = 1 and
    Usage LIKE 'Res%' and
    Replace(Postcode, ' ', '') = Replace(@postcode, ' ', '') and
    (RankSAONDetails is not null or
     RankPAONDetails is not null or
     RankStreet is not null or
     RankWard is not null or
     RankPostcode is not null)
order by
    RankTotal desc
offset @offset rows
    fetch next @limit rows only
4

0 回答 0