search the library
This commit is contained in:
parent
ff30e05391
commit
d306b61b2d
1
.gitignore
vendored
1
.gitignore
vendored
@ -6,3 +6,4 @@
|
|||||||
build/
|
build/
|
||||||
dist/
|
dist/
|
||||||
pip-wheel-metadata/
|
pip-wheel-metadata/
|
||||||
|
library/data
|
||||||
|
56
library/searchtest.py
Normal file
56
library/searchtest.py
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
from whoosh.index import create_in
|
||||||
|
from whoosh.fields import *
|
||||||
|
from whoosh.qparser import QueryParser
|
||||||
|
|
||||||
|
import csv
|
||||||
|
import os
|
||||||
|
import argparse
|
||||||
|
from csvparser.csvparser import getfullpublication
|
||||||
|
|
||||||
|
SCRIPT_DIR = os.path.dirname(__file__)
|
||||||
|
DATA_DIR = os.path.abspath(os.path.join(SCRIPT_DIR, "data"))
|
||||||
|
|
||||||
|
|
||||||
|
def index_csv_file():
|
||||||
|
filename = os.path.join(DATA_DIR, "varlib.csv")
|
||||||
|
with open(filename, 'r', encoding='utf_8_sig') as libcsv:
|
||||||
|
csv_as_dict = csv.DictReader(libcsv)
|
||||||
|
for row in csv_as_dict:
|
||||||
|
rowcontent = concatenate_csv_row(row)
|
||||||
|
writer.add_document(title=row["Id"], path=u"/a", content=rowcontent)
|
||||||
|
writer.commit()
|
||||||
|
|
||||||
|
def search(searchinput):
|
||||||
|
with ix.searcher() as searcher:
|
||||||
|
query = QueryParser("content", ix.schema).parse(searchinput)
|
||||||
|
results = searcher.search(query)
|
||||||
|
bookid = results[0]['title']
|
||||||
|
for book in results:
|
||||||
|
bookid = book['title']
|
||||||
|
print(f"result found: {bookid}")
|
||||||
|
publication = getfullpublication(bookid)
|
||||||
|
print(f"{publication['Author']} - {publication['Title']}")
|
||||||
|
|
||||||
|
|
||||||
|
def concatenate_csv_row(row):
|
||||||
|
rowcontent = []
|
||||||
|
rowcontent.append(row["Publication"])
|
||||||
|
rowcontent.append(row["Author"])
|
||||||
|
rowcontent.append(row["Fields"])
|
||||||
|
rowcontent.append(row["Type"])
|
||||||
|
rowcontent.append(row["Publishers"])
|
||||||
|
rowcontent.append(row["Highlights"])
|
||||||
|
rowcontent.append(row["Comments"])
|
||||||
|
return ' '.join(rowcontent)
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument("-s", "--search", type=str)
|
||||||
|
args = parser.parse_args()
|
||||||
|
searchinput = args.search
|
||||||
|
|
||||||
|
schema = Schema(title=TEXT(stored=True), path=ID(stored=True), content=TEXT)
|
||||||
|
ix = create_in(DATA_DIR, schema)
|
||||||
|
writer = ix.writer()
|
||||||
|
index_csv_file()
|
||||||
|
print(searchinput)
|
||||||
|
search(searchinput)
|
@ -43,7 +43,7 @@ body:after {
|
|||||||
margin: 1em 0;
|
margin: 1em 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#tagsearch{
|
#booksearch{
|
||||||
background: #f1f1f1;
|
background: #f1f1f1;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
|
23
library/static/js/search.js
Normal file
23
library/static/js/search.js
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
let searchInput = document.getElementById('booksearch');
|
||||||
|
let timeout = null;
|
||||||
|
// Listen for keystroke events
|
||||||
|
searchInput.addEventListener('keyup', function (e) {
|
||||||
|
// Clear the timeout if it has already been set.
|
||||||
|
clearTimeout(timeout);
|
||||||
|
// Make a new timeout set to go off in 1000ms (1 second)
|
||||||
|
timeout = setTimeout(function () {
|
||||||
|
if (searchInput.value.length > 2) {
|
||||||
|
searchTags(searchInput.value);
|
||||||
|
} else {
|
||||||
|
clearSearchTags();
|
||||||
|
}
|
||||||
|
}, 1000);
|
||||||
|
});
|
||||||
|
|
||||||
|
function searchTags(searchInput) {
|
||||||
|
console.log(searchInput);
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearSearchTags() {
|
||||||
|
console.log("stop search");
|
||||||
|
}
|
@ -31,4 +31,6 @@
|
|||||||
{% endfor%}
|
{% endfor%}
|
||||||
</div>
|
</div>
|
||||||
<script src="{{ url_for('static', filename='js/dropdown.js')}}"></script>
|
<script src="{{ url_for('static', filename='js/dropdown.js')}}"></script>
|
||||||
|
<script src="{{ url_for('static', filename='js/search.js')}}"></script>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -26,6 +26,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="dropdown">
|
<div class="dropdown">
|
||||||
<input id="tagsearch" type="text" placeholder="🔍 Search..">
|
<input id="booksearch" type="text" placeholder="🔍 Search..">
|
||||||
</div>
|
</div>
|
||||||
{% endblock menu %}
|
{% endblock menu %}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
anyascii==0.3.2
|
||||||
|
attrs==23.1.0
|
||||||
bcrypt==4.0.1
|
bcrypt==4.0.1
|
||||||
blinker==1.6.2
|
blinker==1.6.2
|
||||||
certifi==2023.5.7
|
certifi==2023.5.7
|
||||||
@ -13,6 +15,7 @@ itsdangerous==2.1.2
|
|||||||
Jinja2==3.1.2
|
Jinja2==3.1.2
|
||||||
MarkupSafe==2.1.3
|
MarkupSafe==2.1.3
|
||||||
Pillow==10.0.0
|
Pillow==10.0.0
|
||||||
|
pyahocorasick==2.0.0
|
||||||
python-dateutil==2.8.2
|
python-dateutil==2.8.2
|
||||||
pytz==2023.3
|
pytz==2023.3
|
||||||
requests==2.31.0
|
requests==2.31.0
|
||||||
|
Loading…
Reference in New Issue
Block a user