在对SQL Server 2008记录进行排序时忽略停用词

问题描述:

我有一个包含书名字段的表。我希望能够像这样记录进行排序:在对SQL Server 2008记录进行排序时忽略停用词

  1. 古代鳄鱼
  2. 安妮阿姨的鳄鱼
  3. 一个完整的指南鳄鱼
  4. Countrified鳄鱼
  5. 不要触摸鳄鱼!
  6. 一个轻松的鳄鱼狩猎

等,无视“A”,“一个” &“的”时,它们显示为标题的第一个字。 (他们也可以忽略标题中的任何地方。)

我知道这些都是SQL Server 2008中的停用词,所以如果有人在搜索中使用它们,它们可以被忽略。

但是有没有办法让它们被ORDER BY忽略? (如果有区别,查询将使用ASP.NET中的LinqDataSource。)

谢谢!

也许这样的事情。

;with T(Title) as 
(
    select 'The Ancient Alligator'   union all 
    select 'Aunt Annie''s Alligator'  union all 
    select 'A Complete Guide to Alligators' union all 
    select 'Countrified Alligators'   union all 
    select 'Don''t Touch the Alligator!' union all 
    select 'An Effortless Alligator Hunt' 
) 

select Title 
from T 
order by replace(
     replace(
     replace(T.Title, 
     'A ', ''), 
     'An ', ''), 
     'The ', '') 

结果:

Title 
------------------------------ 
The Ancient Alligator 
Aunt Annie's Alligator 
A Complete Guide to Alligators 
Countrified Alligators 
Don't Touch the Alligator! 
An Effortless Alligator Hunt 

计算通过使用替代()如果你有大量的记录不会规模排序关键字。

最好的方法是添加一个额外的表字段,包含与A/An /等前缀删除的标题,并确保它有一个索引,加快排序。然后,您可以按这个新字段排序,但显示原始未更改的字段。