Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
slide-index
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Welter, Felix
slide-index
Commits
f1aa74ae
Commit
f1aa74ae
authored
4 years ago
by
felixwelter
Browse files
Options
Downloads
Patches
Plain Diff
Reformat and remove comments
parent
ba1b257a
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
app.py
+5
-9
5 additions, 9 deletions
app.py
search_index.py
+1
-0
1 addition, 0 deletions
search_index.py
with
6 additions
and
9 deletions
app.py
+
5
−
9
View file @
f1aa74ae
import
os
import
sys
from
pathlib
import
Path
import
pdfplumber
from
flask
import
Flask
,
render_template
,
request
,
redirect
,
send_file
from
werkzeug.utils
import
secure_filename
from
search_index
import
BasicSearchIndex
from
title_focus_search_index
import
TitleFocusSearchIndex
import
os
app
=
Flask
(
__name__
)
...
...
@@ -15,6 +15,7 @@ IMAGE_DIR = "img_cache"
Index
=
TitleFocusSearchIndex
@app.route
(
'
/
'
)
def
index
():
ll
=
os
.
listdir
(
SLIDE_DIR
)
...
...
@@ -27,11 +28,8 @@ def allowed_file(filename):
@app.route
(
'
/upload
'
,
methods
=
[
'
POST
'
])
def
upload
():
# check if the post request has the file part
if
'
file
'
in
request
.
files
:
file
=
request
.
files
[
'
file
'
]
# if user does not select file, browser also
# submit an empty part without filename
if
file
.
filename
!=
''
:
if
file
and
allowed_file
(
file
.
filename
):
filename
=
secure_filename
(
file
.
filename
)
...
...
@@ -48,21 +46,19 @@ def upload():
del
index
return
redirect
(
'
/
'
)
@app.route
(
"
/search
"
)
def
query
():
try
:
index
=
Index
()
query
=
request
.
args
.
get
(
"
term
"
)
result
=
index
.
search
(
query
)
#pdf = pdfplumber.open(result["path"])
#page = pdf.pages[result["page"]]
img_name
=
result
[
"
path
"
][
7
:]
+
"
_
"
+
str
(
result
[
"
page
"
])
+
"
.jpg
"
#img_path = os.path.join(IMAGE_DIR, img_name)
#page.to_image().save(img_path)
return
"
slide/
"
+
img_name
except
:
return
str
(
sys
.
exc_info
()[
0
]).
replace
(
"
<
"
,
"
-
"
).
replace
(
"
>
"
,
"
-
"
)
@app.route
(
"
/slide/<img_name>
"
)
def
slide
(
img_name
):
path
=
os
.
path
.
join
(
IMAGE_DIR
,
img_name
)
...
...
This diff is collapsed.
Click to expand it.
search_index.py
+
1
−
0
View file @
f1aa74ae
...
...
@@ -8,6 +8,7 @@ from whoosh.qparser import QueryParser, OrGroup
class
BasicSearchIndex
:
"""
Expose relevant functions of Whoosh using a simple interface
"""
def
__init__
(
self
,
index_dir
=
"
index
"
):
self
.
schema
=
Schema
(
path
=
ID
(
stored
=
True
),
page
=
NUMERIC
(
stored
=
True
),
content
=
TEXT
(
stored
=
True
))
try
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment