Browse Source

search sorts

develop
Rob Colbert 4 months ago
parent
commit
931e30db52
  1. 3
      app/controllers/newsroom.js
  2. 30
      app/services/feed.js
  3. 33
      app/views/newsroom/components/search-form.pug
  4. 22
      app/views/newsroom/index.pug
  5. 3
      app/views/newsroom/layouts/kiosk.pug
  6. 4
      app/views/newsroom/search.pug

3
app/controllers/newsroom.js

@ -175,8 +175,9 @@ class NewsroomController extends SiteController {
async getSearch (req, res, next) {
const { feed: feedService } = this.dtp.services;
try {
const sortOrder = req.query.s || 's';
res.locals.pagination = this.getPaginationParameters(req, 20);
res.locals.newsroom = await feedService.search(req.query.q, res.locals.pagination);
res.locals.newsroom = await feedService.search(req.query.q, res.locals.pagination, { sortOrder });
res.render('newsroom/search');
} catch (error) {
this.log.error('failed to search the newsfeed', { error });

30
app/services/feed.js

@ -361,17 +361,37 @@ class FeedService extends SiteService {
};
}
async search (query, pagination) {
async search (query, pagination, options) {
options = Object.assign({
sortOrder: 's',
}, options);
const search = {
$text: { $search: query },
};
const sort = { };
switch (options.sortOrder) {
case 's':
sort.score = { $meta: "textScore" };
sort.published = -1;
break;
case 'dd':
sort.published = -1;
break;
case 'da':
sort.published = 1;
break;
}
this.log.debug('searching Newsroom', {
query: search,
options,
sort,
});
const entries = await FeedEntry
.find(search, { score: { $meta: "textScore" } })
.sort({
score: { $meta: "textScore" },
published: -1,
})
.sort(sort)
.skip(pagination.skip)
.limit(pagination.cpp)
.populate(this.populateFeedEntry)

33
app/views/newsroom/components/search-form.pug

@ -1,7 +1,26 @@
form(method="GET", action="/newsroom/search").uk-form.uk-margin-small
div(uk-grid).uk-grid-small
.uk-width-expand
input(id="search", name="q", type="text", placeholder="Enter search", value= query.q || undefined).uk-input
.uk-width-auto
button(type="submit").uk-button.dtp-button-secondary.uk-border-rounded
i.fas.fa-search
form(method="GET", action="/newsroom/search").uk-form.uk-margin
.uk-margin-small
div(uk-grid).uk-grid-small
.uk-width-expand
input(id="search", name="q", type="text", placeholder="Enter search", value= query.q || undefined).uk-input
.uk-width-auto
button(type="submit").uk-button.dtp-button-secondary.uk-border-rounded
i.fas.fa-search
.uk-margin-small
div(uk-grid).uk-grid-small
.uk-width-auto Sort:
.uk-width-auto
.pretty.p-default.p-round.p-smooth
input(type="radio", name="s", value="s", checked= (query.s === 's'))
.state
label Relevance
.uk-width-auto
.pretty.p-default.p-round.p-smooth
input(type="radio", name="s", value="dd", checked= (query.s === 'dd'))
.state
label Newest First
.uk-width-auto
.pretty.p-default.p-round.p-smooth
input(type="radio", name="s", value="da", checked= (query.s === 'da'))
.state
label Oldest First

22
app/views/newsroom/index.pug

@ -3,18 +3,18 @@ block content
include ../components/pagination-bar
section.uk-section.uk-section-default
section.uk-section.uk-section-secondary.uk-section
.uk-container
div(uk-grid).uk-flex-middle
.uk-width-expand
h1.uk-margin-remove #{site.name} Newsroom
.uk-width-auto
a(href="/newsroom/feed").uk-button.dtp-button-primary.uk-button-small.uk-border-rounded
span View All
include components/search-form
section.uk-section.uk-section-default.uk-section
.uk-container
.uk-margin
div(uk-grid).uk-flex-middle
.uk-width-expand
h1.uk-margin-remove #{site.name} Newsroom
.uk-width-auto
a(href="/newsroom/feed").uk-button.dtp-button-primary.uk-button-small.uk-border-rounded
span View All
include components/search-form
if Array.isArray(newsroom.feeds) && (newsroom.feeds.length > 0)
div(uk-grid).uk-grid-match

3
app/views/newsroom/layouts/kiosk.pug

@ -13,7 +13,8 @@ block content
.header-site= site.name
.header-title Newsroom
.uk-width-auto
img(src=`/img/icon/${site.domainKey}/icon-72x72.png`)
a(href="/")
img(src=`/img/icon/${site.domainKey}/icon-72x72.png`)
ul.uk-list.sidebar-feed-list
li

4
app/views/newsroom/search.pug

@ -3,7 +3,7 @@ block content
include ../components/pagination-bar
section.uk-section.uk-section-secondary
section.uk-section.uk-section-secondary.uk-section
.uk-container
.some-kinda-header.uk-margin-medium
@ -16,7 +16,7 @@ block content
include components/search-form
.uk-text-bold #{formatCount(newsroom.totalFeedEntryCount)} articles matching #[code= query.q] at #{site.name}.
section.uk-section.uk-section-default
section.uk-section.uk-section-default.uk-section
.uk-container
article.uk-article

Loading…
Cancel
Save