Example #1
0
def shownotes(query):
    form = Search()
    if request.method == 'GET':
        has_starred = False
        list_of_files = []
        all_files = []
        list_of_files = []
        uniq = {}
        try:
            books = indexer.search(query)
            for x in books:
                all_files  = files.query.filter(files.filename.like(x))
                for file in all_files:
                    try:
                        if uniq[file.filename]:
                            print "Duplicate"
                    except:
                        list_of_files.append((file.filename,file.author,file.tags,file.semester,file.description,file.downloads, (has_starred, stars.get_stars(file.id), file.id), file.uploader, file.upload_date.strftime("%d-%m-%Y %H:%M"),file.department))
                        uniq[file.filename] = True
                    try:
                        has_starred = stars.has_starred(file.id, g.user.rollNo)
                    except:
                        pass
        except:
            pass
        indexed_search = files.query.whoosh_search(query)
        has_starred = False
        for file in indexed_search:
            try:
                has_starred = stars.has_starred(file.id, g.user.rollNo)
            except:
                pass
            list_of_files.append((file.filename,file.author,file.tags,file.semester,file.description,file.downloads, (has_starred, stars.get_stars(file.id), file.id), file.uploader, file.upload_date.strftime("%d-%m-%Y %H:%M"),file.department))
        return render_template('notes.html',list_of_files = list_of_files , search_form = form)


    elif request.method == 'POST':
        if request.form.get('star'):
            print 'AHAHH'
            print '{0} is the form'.format(request.form)
            if request.form['star'] == '1':
                stars.add_star(request.form['file_id'], request.form['user_rno'])
            if request.form['star'] == '-1':
                stars.reduce_star(request.form['file_id'],request.form['user_rno'])
            return "F**K YEAH"
        if request.form.get('query'):
            query = request.form['query']
            return redirect(url_for('shownotes',query = query))
Example #2
0
def search(query, show_response=False):
    query_dict = {
        "function_score": {
            "query": {
                "multi_match": {
                    "query":
                    " ".join(query.tags),
                    "type":
                    "cross_fields",
                    # "operator": "and",
                    "fields": [
                        "body_tags^3",
                        "inheritance_tags^2",
                        # "import_tags^1",
                        "name_tags^4",
                        "name^5",
                    ]
                }
            },
            "functions": [{
                "field_value_factor": {
                    "field": "score"
                }
            }],
        }
    }

    if query.return_type is not None:
        if query.return_type == "void":
            query.return_type = "null"
        query_dict["function_score"]["functions"].append({
            "filter": {
                "match": {
                    "return_type": collapse_type(query.return_type)
                }
            },
            "weight": 10
        })

    if query.parameter is not None:
        query_dict["function_score"]["functions"].append({
            "filter": {
                "match": {
                    "parameters.type": collapse_type(query.parameter)
                }
            },
            "weight": 10
        })

    result = indexer.search(index_config, query_dict)

    if show_response:
        print("Response:")
        print(json.dumps(result, indent=4))
        print()
        print()
        print()

    print(green + "Found " + str(len(result["hits"]["hits"])) +
          " function(s)" + reset)
    print()
    for i, hit in enumerate(result["hits"]["hits"]):
        print(green + str(i + 1) + ":" + reset)
        source = hit["_source"]
        retType = source["return_type"]
        if retType == "null":
            retType = "void"

        print(retType + " " + source["name"] + "(" + ", ".join(
            [p["type"] + " " + p["name"] for p in source["parameters"]]) + ")",
              end="")

        print(fix_indentation_in_body(source["body"]))
        print()
Example #3
0
def search_index(word):
	'''search_index(word) - Takes a string word as a argument
		return a list of queried paths'''
	return indexer.search(word)
Example #4
0
def shownotes(query):
    form = Search()
    if request.method == 'GET':
        has_starred = False
        list_of_files = []
        all_files = []
        list_of_files = []
        uniq = {}
        try:
            books = indexer.search(query)
            for x in books:
                all_files = files.query.filter(files.filename.like(x))
                for file in all_files:
                    try:
                        if uniq[file.filename]:
                            print "Duplicate"
                    except:
                        list_of_files.append(
                            (file.filename, file.author, file.tags,
                             file.semester, file.description, file.downloads,
                             (has_starred, stars.get_stars(file.id),
                              file.id), file.uploader,
                             file.upload_date.strftime("%d-%m-%Y %H:%M"),
                             file.department))
                        uniq[file.filename] = True
                    try:
                        has_starred = stars.has_starred(file.id, g.user.rollNo)
                    except:
                        pass
        except:
            pass
        indexed_search = files.query.whoosh_search(query)
        has_starred = False
        for file in indexed_search:
            try:
                has_starred = stars.has_starred(file.id, g.user.rollNo)
            except:
                pass
            list_of_files.append(
                (file.filename, file.author, file.tags, file.semester,
                 file.description, file.downloads, (has_starred,
                                                    stars.get_stars(file.id),
                                                    file.id), file.uploader,
                 file.upload_date.strftime("%d-%m-%Y %H:%M"), file.department))
        return render_template('notes.html',
                               list_of_files=list_of_files,
                               search_form=form)

    elif request.method == 'POST':
        if request.form.get('star'):
            print 'AHAHH'
            print '{0} is the form'.format(request.form)
            if request.form['star'] == '1':
                stars.add_star(request.form['file_id'],
                               request.form['user_rno'])
            if request.form['star'] == '-1':
                stars.reduce_star(request.form['file_id'],
                                  request.form['user_rno'])
            return "F**K YEAH"
        if request.form.get('query'):
            query = request.form['query']
            return redirect(url_for('shownotes', query=query))