forked from tanner/qotnews
gotta try this on live.
This commit is contained in:
parent
32f1455bbb
commit
59c6f17e67
|
@ -67,9 +67,9 @@ def put_story(story):
|
||||||
logging.error('Problem putting MeiliSearch story: {}'.format(str(e)))
|
logging.error('Problem putting MeiliSearch story: {}'.format(str(e)))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def search(q):
|
def search(q, skip=0, limit=250):
|
||||||
try:
|
try:
|
||||||
params = dict(q=q, limit=250)
|
params = dict(q=q, skip=skip, limit=limit)
|
||||||
r = requests.get(MEILI_URL + 'indexes/qotnews/search', params=params, timeout=2)
|
r = requests.get(MEILI_URL + 'indexes/qotnews/search', params=params, timeout=2)
|
||||||
if r.status_code != 200:
|
if r.status_code != 200:
|
||||||
raise Exception('Bad response code ' + str(r.status_code))
|
raise Exception('Bad response code ' + str(r.status_code))
|
||||||
|
|
|
@ -51,8 +51,10 @@ def api():
|
||||||
@flask_app.route('/api/search', strict_slashes=False)
|
@flask_app.route('/api/search', strict_slashes=False)
|
||||||
def apisearch():
|
def apisearch():
|
||||||
q = request.args.get('q', '')
|
q = request.args.get('q', '')
|
||||||
|
skip = request.args.get('skip', 0)
|
||||||
|
limit = request.args.get('limit', 20)
|
||||||
if len(q) >= 3:
|
if len(q) >= 3:
|
||||||
results = search.search(q)
|
results = search.search(q, skip=skip, limit=limit)
|
||||||
else:
|
else:
|
||||||
results = []
|
results = []
|
||||||
return dict(results=results)
|
return dict(results=results)
|
||||||
|
|
|
@ -54,10 +54,6 @@
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
color: #888;
|
color: #888;
|
||||||
}
|
}
|
||||||
.comment-text.is-collapsed::after {
|
|
||||||
content: "...";
|
|
||||||
font-style: italic;
|
|
||||||
}
|
|
||||||
.comment-children {
|
.comment-children {
|
||||||
margin-left: 0.5rem;
|
margin-left: 0.5rem;
|
||||||
padding-left: 0.5rem;
|
padding-left: 0.5rem;
|
||||||
|
@ -85,14 +81,15 @@
|
||||||
<header class="comment-info">
|
<header class="comment-info">
|
||||||
<span
|
<span
|
||||||
class={comment.author === story.author ? 'comment-author is-op' : 'comment-author'}>{comment.author || '[Deleted]'}</span>
|
class={comment.author === story.author ? 'comment-author is-op' : 'comment-author'}>{comment.author || '[Deleted]'}</span>
|
||||||
•
|
|
||||||
<a class="time-link" href="{story.id}#comment-{id}">
|
<a class="time-link" href="{story.id}#comment-{id}">
|
||||||
<Time date={comment.date} />
|
<Time date={comment.date} />
|
||||||
</a>
|
</a>
|
||||||
{#if comment.comments.length}
|
{#if comment.comments.length}
|
||||||
<button
|
<button
|
||||||
class="toggle-children"
|
class="toggle-children"
|
||||||
on:click={toggleComments}>[{showComments ? '-' : '+'}]</button>
|
on:click={toggleComments}>{#if showComments}
|
||||||
|
[–]
|
||||||
|
{:else}[+]{/if}</button>
|
||||||
{/if}
|
{/if}
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
on
|
on
|
||||||
<a class="source" href={story.link || story.url}>{story.source}</a>
|
<a class="source" href={story.link || story.url}>{story.source}</a>
|
||||||
{#if story.score}• {story.score} points{/if}
|
{#if story.score}• {story.score} points{/if}
|
||||||
{#if story.num_comments}
|
{#if Number(story.num_comments)}
|
||||||
•
|
•
|
||||||
<a rel="prefetch" href="/{story.id}#comments">{story.num_comments}
|
<a rel="prefetch" href="/{story.id}#comments">{story.num_comments}
|
||||||
comments</a>
|
comments</a>
|
||||||
|
|
|
@ -18,8 +18,10 @@
|
||||||
export let story;
|
export let story;
|
||||||
export let related;
|
export let related;
|
||||||
|
|
||||||
let others = related.filter((r) => r.id !== story.id && r.num_comments);
|
let others = related.filter(
|
||||||
let hasComments = related.some((r) => r.num_comments);
|
(r) => r.id !== story.id && Number(r.num_comments)
|
||||||
|
);
|
||||||
|
let hasComments = related.some((r) => Number(r.num_comments));
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|
|
@ -24,7 +24,10 @@ class Results extends React.Component {
|
||||||
const signal = this.controller.signal;
|
const signal = this.controller.signal;
|
||||||
|
|
||||||
const search = this.props.location.search;
|
const search = this.props.location.search;
|
||||||
fetch('/api/search' + search, { method: 'get', signal: signal })
|
const params = new URLSearchParams(search);
|
||||||
|
params.set('skip', params.get('skip') || 0);
|
||||||
|
params.set('limit', params.get('limit') || 20);
|
||||||
|
fetch('/api/search?' + params.toString(), { method: 'get', signal: signal })
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
.then(
|
.then(
|
||||||
(result) => {
|
(result) => {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user