AAD Graph Weighted

1

Please login or register to vote for this query.

(click on this box to dismiss)

Computational Science

Q&A for scientists using computers to solve scientific problems

-- DECLARE @Keyword nvarchar(100) = '%##LowerCaseKeyword##%' -- user prompt
DECLARE @Keyword nvarchar(30) = '% graph %' -- leading/trailing space helps match stackoverflow.com search behavior

-- Build the filter result set; contains key and unanswered 'skew' value
CREATE TABLE #unanswered (Id int primary key, UnansweredSkew int)
INSERT #unanswered
SELECT q.Id as Id, 
CASE WHEN q.AcceptedAnswerId is null THEN -10 
     WHEN q.AcceptedAnswerId is not null THEN 0 END AS [Total]
FROM Posts q
WHERE ((q.Tags LIKE '%adal%')
    OR (q.Tags LIKE '%office365%')
    OR (q.Tags LIKE '%azure-active-directory%'))
AND ((LOWER(q.Body) LIKE @Keyword)
   OR(LOWER(q.Title) LIKE @Keyword))
    
-- Build the weighting result set
SELECT p.Id AS [Post Link], 
p.ViewCount, 
p.AnswerCount, 
CASE WHEN p.AcceptedAnswerId is null THEN 'false' ELSE 'true' END AS Answered,
((p.ViewCount * 0.1) + p.AnswerCount + u.UnansweredSkew) AS Weight,
CONVERT(VARCHAR(10), p.CreationDate, 1) as Created,
CAST((GETDATE() - p.CreationDate) AS INT) as Age,
p.Tags

-- Join the 2 result sets
FROM Posts p
JOIN #unanswered u ON u.Id = p.Id
ORDER BY Answered ASC, Weight DESC

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results