示例#1
0
def search():
	a = request.args.get('a', 0, type=str)
	user_id = request.args.get('uid', 0, type=str)
	query = a
	db = dbms.Database()
	res = db.find_queryresults(query)
	non_relevant = db.find_nonrelevant(query) 
	update = False
	#print "NR: "
	#print non_relevant
	if  res == None:
		res2 = Read_Data.work(query)
		temp = copy.deepcopy(res2)    	#Important - Deep copy of returned results list
	else:
		#print "Reading from DB..."
		if len(res) < 10:
			res = Read_Data.work(query)
			update = True
			print "Results < 10"
		temp = copy.deepcopy(res)
	
	non_relevant_flag = False
	
	temp2 = copy.deepcopy(temp)
		
	for course in temp2:
		if course[1] in non_relevant:
			print "Removing non-relevant course ", course[1]
			temp.remove(course)
			non_relevant_flag = True


	if non_relevant_flag or update:
		#print "Updating DB..."
		db.update_queryresults(query, temp)
	else:
		db.insert_queryresults(query, temp)
	
	if len(temp) > 10:
		temp = temp[0:10]	
	
	user_info = conn_data(db, user_id, temp)	
	print "User Info list: ", user_info
	#print "User not interested list: ", db.find_notinterested(user_id)
	for i in range(len(user_info)):
		print user_info[i]
		temp[i].append(user_info[i]["basic"])
		temp[i].append(user_info[i]["adv"])
		temp[i].append(user_info[i]["likes"])

	ret = isbn.getisbnData(query)
	return jsonify(result = temp, result2 = ret)
示例#2
0
def search():
	a = request.args.get('a', 0, type=str)
	res = Read_Data.work(a)
	return jsonify(result = res)