Is it possible to define a function to prevent repeating lots of `case when` in transact sql?
Use APPLY, like the examples I show in: http://blogs.lobsterpot.com.au/2011/12/13/a-t-sql-tip-working-calculations/

...then you can use it everywhere else as a regular column - just a calculated one. 

Select n.Num, left(title,25) --, etc
From posts 
Cross apply (select case 
  when lower(title) like '%open source%' then 0
  when lower(title) like '%recommend%'   then 1    
  when lower(title) like '%free%'        then 2
  when lower(title) like '%good%'        then 2
  when lower(title) like '%best%'        then 2
  when lower(title) like '%better%'      then 2
  when lower(title) like '%any%'         then 2
  when lower(title) like '%what%should%' then 3
  when lower(title) like '%which%should%'then 3
  when lower(title) like '%is there%'    then 3
  when lower(title) like '%looking for%' then 4
  else 5 end as Num) n
-- where ...
Order by n.num