mirror of
https://github.com/ail-project/ail-framework.git
synced 2024-11-23 06:37:15 +00:00
Added display of number of elements inside the index + changed variables names
This commit is contained in:
parent
e4757f5ceb
commit
381e72ee99
3 changed files with 24 additions and 18 deletions
|
@ -11,6 +11,9 @@ import flask
|
|||
from flask import Flask, render_template, jsonify, request
|
||||
|
||||
import Paste
|
||||
from whoosh import index
|
||||
from whoosh.fields import Schema, TEXT, ID
|
||||
from whoosh.qparser import QueryParser
|
||||
|
||||
# ============ VARIABLES ============
|
||||
import Flask_config
|
||||
|
@ -40,7 +43,12 @@ def get_index_list(selected_index=""):
|
|||
index_list = []
|
||||
for dirs in os.listdir(baseindexpath):
|
||||
if os.path.isdir(os.path.join(baseindexpath, dirs)):
|
||||
index_list.append([ dirs, dirs + " - " + str(get_dir_size(dirs) / (1000*1000)) + " Mb", dirs==selected_index.split('/')[-1]])
|
||||
value = dirs
|
||||
name = dirs + " - " + \
|
||||
str(get_dir_size(dirs) / (1000*1000)) + " Mb " + \
|
||||
"(" + str(get_item_count(dirs)) + " Items" + ")"
|
||||
flag = dirs==selected_index.split('/')[-1]
|
||||
index_list.append([ value, name, flag])
|
||||
return index_list
|
||||
|
||||
def get_dir_size(directory):
|
||||
|
@ -49,6 +57,10 @@ def get_dir_size(directory):
|
|||
cur_sum += sum(os.path.getsize(os.path.join(directory, name)) for name in files)
|
||||
return cur_sum
|
||||
|
||||
def get_item_count(dirs):
|
||||
ix = index.open_dir(os.path.join(baseindexpath, dirs))
|
||||
return ix.doc_count_all()
|
||||
|
||||
|
||||
# ============ ROUTES ============
|
||||
|
||||
|
@ -61,14 +73,14 @@ def search():
|
|||
c = [] #preview of the paste content
|
||||
paste_date = []
|
||||
paste_size = []
|
||||
index_num = request.form['index_num']
|
||||
index_name = request.form['index_name']
|
||||
num_elem_to_get = 50
|
||||
|
||||
# select correct index
|
||||
if index_num is None or index_num == "0":
|
||||
if index_name is None or index_name == "0":
|
||||
selected_index = get_current_index()
|
||||
else:
|
||||
selected_index = os.path.join(baseindexpath, index_num)
|
||||
selected_index = os.path.join(baseindexpath, index_name)
|
||||
|
||||
# Search filename
|
||||
for path in r_serv_pasteName.smembers(q[0]):
|
||||
|
@ -83,12 +95,9 @@ def search():
|
|||
paste_size.append(paste._get_p_size())
|
||||
|
||||
# Search full line
|
||||
from whoosh import index
|
||||
from whoosh.fields import Schema, TEXT, ID
|
||||
schema = Schema(title=TEXT(stored=True), path=ID(stored=True), content=TEXT)
|
||||
|
||||
ix = index.open_dir(selected_index)
|
||||
from whoosh.qparser import QueryParser
|
||||
with ix.searcher() as searcher:
|
||||
query = QueryParser("content", ix.schema).parse(" ".join(q))
|
||||
results = searcher.search_page(query, 1, pagelen=num_elem_to_get)
|
||||
|
@ -121,26 +130,23 @@ def get_more_search_result():
|
|||
q = []
|
||||
q.append(query)
|
||||
page_offset = int(request.form['page_offset'])
|
||||
index_num = request.form['index_num']
|
||||
index_name = request.form['index_name']
|
||||
num_elem_to_get = 50
|
||||
|
||||
# select correct index
|
||||
if index_num is None or index_num == "0":
|
||||
if index_name is None or index_name == "0":
|
||||
selected_index = get_current_index()
|
||||
else:
|
||||
selected_index = os.path.join(baseindexpath, index_num)
|
||||
selected_index = os.path.join(baseindexpath, index_name)
|
||||
|
||||
path_array = []
|
||||
preview_array = []
|
||||
date_array = []
|
||||
size_array = []
|
||||
|
||||
from whoosh import index
|
||||
from whoosh.fields import Schema, TEXT, ID
|
||||
schema = Schema(title=TEXT(stored=True), path=ID(stored=True), content=TEXT)
|
||||
|
||||
ix = index.open_dir(selected_index)
|
||||
from whoosh.qparser import QueryParser
|
||||
with ix.searcher() as searcher:
|
||||
query = QueryParser("content", ix.schema).parse(" ".join(q))
|
||||
results = searcher.search_page(query, page_offset, num_elem_to_get)
|
||||
|
|
|
@ -92,7 +92,7 @@
|
|||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<strong style="">Index: </strong>
|
||||
<select class="form-control" id="index_num" style="display: inline-block; margin-bottom: 5px; width: 15%">
|
||||
<select class="form-control" id="index_name" style="display: inline-block; margin-bottom: 5px; width: 25%">
|
||||
{% for indexElem in index_list %}
|
||||
<option {% if indexElem[2] %} selected="selected" {% endif %} value="{{ indexElem[0] }}" >{{ indexElem[1] }}</option>
|
||||
{% endfor %}
|
||||
|
@ -166,14 +166,14 @@
|
|||
$("#load_more_json_button1").show();
|
||||
}
|
||||
|
||||
$('#index_num').on('change', function() {
|
||||
$('#index_name').on('change', function() {
|
||||
var form = document.createElement('form');
|
||||
form.setAttribute("method", 'post');
|
||||
form.setAttribute("action", "{{ url_for('search') }}");
|
||||
|
||||
var input1 = document.createElement('input');
|
||||
input1.setAttribute("type", "hidden");
|
||||
input1.setAttribute("name", "index_num");
|
||||
input1.setAttribute("name", "index_name");
|
||||
input1.setAttribute("value", this.value);
|
||||
form.appendChild(input1);
|
||||
|
||||
|
@ -201,7 +201,7 @@
|
|||
}
|
||||
|
||||
function load_search_50_data() {
|
||||
var options = { query: query, page_offset: page_offset, index_num: $("#index_num").val() };
|
||||
var options = { query: query, page_offset: page_offset, index_name: $("#index_name").val() };
|
||||
$.post( "{{ url_for('get_more_search_result') }}", options).done(function( data ) {
|
||||
|
||||
for(i=0; i<data.path_array.length; i++) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<div class="input-group custom-search-form">
|
||||
<form action="/search" id="form-search" method=POST>
|
||||
<input type="text" name="query" class="form-control" placeholder="Search Paste">
|
||||
<input type="hidden" name="index_num" class="form-control" value="0" placeholder="Index Num">
|
||||
<input type="hidden" name="index_name" class="form-control" value="0" placeholder="Index Name">
|
||||
<span class="input-group-btn">
|
||||
<button class="btn btn-default" type="submit">
|
||||
<i class="fa fa-search"></i>
|
||||
|
|
Loading…
Reference in a new issue