Browse Source

remove useless code

master
wes 7 years ago
parent
commit
800634c498
  1. 59
      src/search.py

59
src/search.py

@ -22,22 +22,6 @@ def summarize(text):
return " ".join(splitted[0:6]) + ".."
return text
def sectionToJSON(section):
return {
"prof" : section.prof,
"sem" : section.sem,
"day" : section.day
}
def classToJSON(clss):
return {
"title" : clss.title,
"sections" : map(sectionToJSON, clss.sections),
"dept" : clss.dept,
"code" : clss.code,
"books" : list(clss.books) if clss.books else []
}
def hashsec(course):
"""
Hash a course into a usable id
@ -61,48 +45,6 @@ def hashsec(course):
h.update(code + title + course["sections"][0]["sem"])
return int(h.hexdigest(), 16)
def createIndex(name):
"""
This creates a new index in elasticsearch
An index is like a schema in a regular database
"""
indices = elasticsearch.client.IndicesClient(es)
print(indices.create(name))
with open("../course.json", "r") as mapping:
print(indices.put_mapping("course", loads(mapping.read()), name))
def indexListing(course):
"""
Index a specific course in the database (using the courses index)
example,
{
'books': [],
'dept': 'COLLAB',
'code': '2C03',
'sections': [
{
'prof': 'Lisa Pender',
'sem': '2015/09/08 - 2015/12/08',
'day': 'Mo'
},
{
'prof': 'Staff',
'sem': '2015/09/08 - 2015/12/08',
'day': 'Th'
}
],
'title': 'COLLAB 2C03 - Sociology I'
}
"""
json_course = classToJSON(course)
courseID = hashsec(json_course)
print(es.index(index="oersearch",
doc_type="course",
id=courseID,
body=json_course))
def termSearch(field):
"""
Make a term search (exact match)
@ -196,7 +138,6 @@ def search_courses(terms):
return results
searchers = {
"title" : search("title"),
"loc" : search("loc"),

Loading…
Cancel
Save