Database Reference
In-Depth Information
The display code is located in {PROJECTROOT}/ app/views/graphs/interest/index.mustache . The interest
route uses two queries, which are shown in Listing 10-36 and 10-37. The get_following_content_with_tag finds
users being followed, accesses all of their content, and finds connected tags through the HAS relationship type.
The get_user_content_with_tag method is similar but is concerned only with content and, subsequently, tags
connected to the current user. Both methods limit the results to 30 items. As mentioned earlier, the methods return
an array of content and tags , which supports autosuggest plugin in the view and requires both a label and name to be
provided in order to execute. This autosuggest feature is used in the status update form as well as some search forms
found later in this chapter.
Listing 10-35. The interest Route
# show tags within the user's network (theirs and those being followed)
get '/interest' do
@title = "Interest"
@tagsInNetwork = tags_in_network(neo,request.cookies[graphstoryUserAuthKey])
@userTags = user_tags(neo,request.cookies[graphstoryUserAuthKey])
if params[:userscontent] == "true"
@contents = get_user_content_with_tag(neo,request.cookies[graphstoryUserAuthKey],params[:tag] )
else
@contents = get_following_content_with_tag(neo,request.cookies[graphstoryUserAuthKey],
params[:tag] )
end
mustache :"graphs/interest/index"
end
Filtering Managed Content
Once the list of tags for the user and for the group she follows has been provided, then the content can be filtered
based of the generated tag links, which is shown in Figure 10-12 . If a tag is clicked on inside of “My Interests” section,
then the get_user_content_with_tag method, displayed in Listing 10-34, will be called.
Listing 10-36. Get the Content of the Current User Based on a Tag
def get_user_content_with_tag(neo,username,wordPhrase)
cypher = " MATCH (u:User {username: {u} })-[:CURRENTPOST]-lp-[:NEXTPOST*0..]-p " +
" WITH DISTINCT u,p" +
" MATCH p-[:HAS]-(t:Tag {wordPhrase : {wp} } )" +
" RETURN p.contentId as contentId, p.title as title, p.tagstr as tagstr, " +
" p.timestamp as timestamp, p.url as url, u.username as username, true as owner" +
" ORDER BY p.timestamp DESC"
results=neo.execute_query(cypher, {:u => username, :wp => wordPhrase} )
r=results["data"].map {|row| Hash[*results["columns"].zip(row).flatten] }
r.each do |e|
#convert the timestamp to readable date and time
e.merge!("timestampAsStr" => Time.at(e["timestamp"]).strftime("%m/%d/%Y") +
" at " +
Time.at(e["timestamp"]).strftime("%l:%M %p"))
end
r
end
 
Search WWH ::




Custom Search