Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
djrandom-py
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ale
djrandom-py
Commits
d503d522
Commit
d503d522
authored
13 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
add the search log
parent
5118a672
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
server/djrandom/database.py
+1
-0
1 addition, 0 deletions
server/djrandom/database.py
server/djrandom/frontend/api_views.py
+5
-1
5 additions, 1 deletion
server/djrandom/frontend/api_views.py
server/djrandom/model/mp3.py
+14
-0
14 additions, 0 deletions
server/djrandom/model/mp3.py
with
20 additions
and
1 deletion
server/djrandom/database.py
+
1
−
0
View file @
d503d522
...
...
@@ -18,6 +18,7 @@ class SetTextFactory(PoolListener):
def
init_db
(
uri
):
# Import all ORM modules here, so that 'create_all' can find them.
from
djrandom.model
import
mp3
,
playlist
engine
=
create_engine
(
uri
,
listeners
=
[
SetTextFactory
()],
pool_recycle
=
1800
)
...
...
This diff is collapsed.
Click to expand it.
server/djrandom/frontend/api_views.py
+
5
−
1
View file @
d503d522
...
...
@@ -4,7 +4,7 @@ from flask import Flask, request, Response, abort, jsonify, render_template, g
from
flask.helpers
import
send_file
from
djrandom
import
utils
from
djrandom.database
import
Session
from
djrandom.model.mp3
import
MP3
,
PlayLog
from
djrandom.model.mp3
import
MP3
,
PlayLog
,
SearchLog
from
djrandom.model.playlist
import
Playlist
from
djrandom.frontend
import
app
,
svcs
,
require_auth
from
sqlalchemy
import
distinct
...
...
@@ -131,6 +131,10 @@ def search_json():
resultiter
=
svcs
[
'
searcher
'
].
search
(
query
,
n
=
num_results
)
results
=
[{
'
score
'
:
score
,
'
sha1
'
:
sha1
}
for
(
score
,
sha1
)
in
resultiter
]
if
results
:
# Save this query in the search log.
Session
.
add
(
SearchLog
.
add
(
query
,
g
.
userid
))
Session
.
commit
()
return
jsonify
(
results
=
results
)
...
...
This diff is collapsed.
Click to expand it.
server/djrandom/model/mp3.py
+
14
−
0
View file @
d503d522
from
sqlalchemy
import
*
from
datetime
import
datetime
from
djrandom.database
import
Base
...
...
@@ -63,3 +64,16 @@ class PlayLog(Base):
hashes
=
[
None
]
*
n
yield
(
plog
.
sha1
,
hashes
)
class
SearchLog
(
Base
):
__tablename__
=
'
searchlog
'
userid
=
Column
(
String
(
40
),
index
=
True
)
query
=
Column
(
String
(
256
))
stamp
=
Column
(
DateTime
())
@classmethod
def
add
(
cls
,
query_str
,
userid
):
return
cls
(
query
=
query_str
,
userid
=
userid
,
stamp
=
datetime
.
now
())
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