@@ -88,34 +88,33 @@ def getquestions(request):
8888def listing (request ):
8989 result = _isLoggedIn (request )
9090 if result != None : return result
91- # sentimentOutput = nlu.analyze(text=question['_source']['title'], features=[features.Sentiment()])
92- # sentiment = sentimentOutput['sentiment']['document']['label']
9391 response = searchquestion (request )
9492 print (response )
9593 return render (request , 'askalma/listing.html' , context = response )
9694
9795def searchquestion (request ):
98- try :
99- #print "taking questions from elasticsearch"
100- result = es .search (index = 'questions1' , body = {"from" : 0 , "size" : 1000 , "query" :{"match_all" : {}}})
101- #print result
102- questions = result ['hits' ]['hits' ]
96+ try :
97+ result = es .search (index = 'questions1' , body = {"from" : 0 , "size" : 1000 , "query" :{"match_all" : {}}})
98+ print result
99+ questions = result ['hits' ]['hits' ]
103100 #print questions
104- b = []
105- for question in questions :
106- #print question
107- tags = question ['_source' ]['tags' ]
108- taglist = [s .strip () for s in tags .split (',' )]
109- a = {
101+ b = []
102+ for question in questions :
103+ tags = question ['_source' ]['tags' ]
104+ taglist = [s .strip () for s in tags .split (',' )]
105+ sentimentOutput = nlu .analyze (text = question ['_source' ]['title' ], features = [features .Sentiment ()])
106+ sentiment = sentimentOutput ['sentiment' ]['document' ]['label' ]
107+ a = {
110108 "title" : question ['_source' ]['title' ],
111109 "taglist" : taglist ,
112110 "details" : question ['_source' ]["details" ],
113- "qid" : question ['_id' ]
111+ "qid" : question ['_id' ],
112+ "sentiment" : sentiment
114113 }
115- b .append (a )
116- # print b
117- return {'questions' : b }
118- except KeyError :
114+ b .append (a )
115+ print b
116+ return {'questions' : b }
117+ except KeyError :
119118 return {'questions' : "nothing" }
120119
121120@csrf_exempt
@@ -145,7 +144,7 @@ def pullquestion(request):
145144 tags = categoryOutput ['categories' ][0 ]['label' ]
146145 keywordOutput = nlu .analyze (text = title , features = [features .Keywords ()])
147146 if len (keywordOutput ['keywords' ]) != 0 :
148- tags = tags + ", " + keywordOutput ['keywords' ][0 ]['text' ]
147+ tags = tags + ", " + keywordOutput ['keywords' ][0 ]['text' ]
149148 conceptOutput = nlu .analyze (text = title , features = [features .Concepts ()])
150149 if len (conceptOutput ['concepts' ]) != 0 :
151150 tags = tags + ", " + conceptOutput ['concepts' ][0 ]['text' ]
@@ -247,9 +246,9 @@ def _getStats ():
247246 stats = {}
248247 stats ['views' ] = 7812
249248 stats ['questions' ] = es .search (index = 'questions1' , body = {"size" : 0 ,})['hits' ]['total' ]
250- # stats['answersed_questions'] = es.search(index='questions ', body={"size": 0,"query":{ "query_string": { "query": 1, "default_field": 'answered' }}})['hits']['total']
249+ stats ['answersed_questions' ] = es .search (index = 'questions1 ' , body = {"size" : 0 ,"query" :{ "query_string" : { "query" : 1 , "default_field" : 'answered' }}})['hits' ]['total' ]
251250 stats ['users' ] = es .search (index = 'users' , body = {"size" : 0 ,})['hits' ]['total' ]
252- stats ['answered_questions' ] = 147
251+ stats ['answered_questions' ] = 24
253252
254253 return stats
255254
0 commit comments