From d1fc988ed090d61a78aa960ece9f7e75a3d55ee8 Mon Sep 17 00:00:00 2001 From: Molly Struve Date: Tue, 31 Mar 2020 16:25:48 -0500 Subject: [PATCH] [deploy] Revert "Serve Feed Content From Elasticsearch (#6847)" (#6983) This reverts commit d7cc1da28041170e88f95cb3029e6f1450763888. --- .../initializers/initScrolling.js.erb | 57 ++++++------- .../utilities/buildArticleHTML.js.erb | 48 ++++++----- app/controllers/search_controller.rb | 20 ++--- .../__tests__/articleForm.test.jsx | 3 + app/javascript/articles/Article.jsx | 6 +- .../__snapshots__/Article.test.jsx.snap | 2 +- .../__tests__/utilities/articleUtilities.js | 24 +++--- .../articles/components/SearchSnippet.jsx | 38 ++++++--- .../common-prop-types/article-prop-types.js | 11 ++- .../src/utils/__tests__/search.test.js | 6 +- app/javascript/src/utils/search.js | 4 +- app/views/articles/_search.html.erb | 79 ++++++++++--------- app/views/articles/index.html.erb | 2 +- app/views/articles/search.html.erb | 2 +- app/views/articles/search/_sidebar.html.erb | 3 +- app/views/articles/tag_index.html.erb | 2 +- app/views/organizations/show.html.erb | 2 +- app/views/podcast_episodes/index.html.erb | 2 +- app/views/users/show.html.erb | 4 +- 19 files changed, 169 insertions(+), 146 deletions(-) diff --git a/app/assets/javascripts/initializers/initScrolling.js.erb b/app/assets/javascripts/initializers/initScrolling.js.erb index b46144491..a018c760f 100644 --- a/app/assets/javascripts/initializers/initScrolling.js.erb +++ b/app/assets/javascripts/initializers/initScrolling.js.erb @@ -179,46 +179,40 @@ function fetchNextPodcastPage(el) { fetchNext(el, "/api/podcast_episodes", insertArticles) } -function paginate(tag, params, requiresApproval) { - const searchHash = { ...{ per_page: 15, page: nextPage }, ...JSON.parse(params) }; - +function paginate(tag, requiresApproval) { + var tagFilters = []; if (tag && tag.length > 0) { - searchHash.tag_names = searchHash.tag_names || []; - searchHash.tag_names.push(tag); + tagFilters.push(tag); + } + + var searchObj = { + hitsPerPage: 15, + page: nextPage, + attributesToHighlight: [], + tagFilters, + filters: (requiresApproval === 'true') ? 'approved:true' : '' } - searchHash.approved = (requiresApproval === 'true') ? 'true' : ''; var homeEl = document.getElementById("index-container"); + var paginationArticlesIndex; if (homeEl.dataset.feed === "base-feed") { - searchHash.class_name = "Article"; + paginationArticlesIndex = client.initIndex('ordered_articles_<%= Rails.env %>'); } else if (homeEl.dataset.feed === "latest") { - searchHash.class_name = "Article"; - searchHash.sort_by = "published_at"; + paginationArticlesIndex = client.initIndex('ordered_articles_by_published_at_<%= Rails.env %>'); } else { - searchHash.class_name = "Article"; - searchHash["published_at[gte]"] = homeEl.dataset.articlesSince; - searchHash.sort_by = "positive_reactions_count"; + var preamble = (requiresApproval === 'true') ? ' AND ' : '' + searchObj.filters += ( preamble +'published_at_int > ' + homeEl.dataset.articlesSince); + paginationArticlesIndex = client.initIndex('ordered_articles_by_positive_reactions_count_<%= Rails.env %>'); } - const searchParams = new URLSearchParams(searchHash).toString(); - - fetch(`/search/feed_content?${searchParams}`, { - method: 'GET', - headers: { - Accept: 'application/json', - 'X-CSRF-Token': window.csrfToken, - 'Content-Type': 'application/json', - }, - credentials: 'same-origin', - }) - .then(response => response.json()) - .then((content) => { + paginationArticlesIndex.search("*", searchObj) + .then(function searchDone(content) { nextPage += 1; - insertArticles(content.result); + insertArticles(content.hits); const checkBlockedContentEvent = new CustomEvent('checkBlockedContent') window.dispatchEvent(checkBlockedContentEvent); initializeReadingListIcons(); - if (content.result.length === 0) { + if (content.hits.length === 0) { document.getElementById("loading-articles").style.display = "none" done = true; } @@ -259,11 +253,7 @@ function fetchNextPageIfNearBottom() { } else { scrollableElemId = "articles-list"; fetchCallback = function fetch() { - paginate( - indexContainer.dataset.tag, - indexContainer.dataset.params, - indexContainer.dataset.requiresApproval - ); + paginate(indexContainer.dataset.tag, indexContainer.dataset.requiresApproval); }; } @@ -276,6 +266,9 @@ function fetchNextPageIfNearBottom() { } function checkIfNearBottomOfPage() { + var publicSearchKey = '<%= ALGOLIASEARCH_PUBLIC_SEARCH_ONLY_KEY %>'; + client = algoliasearch('<%= ApplicationConfig["ALGOLIASEARCH_APPLICATION_ID"] %>', publicSearchKey); + if (document.getElementsByClassName("single-article").length < 2 || window.location.search.indexOf("q=") > -1 ) { document.getElementById("loading-articles").style.display = "none"; done = true; diff --git a/app/assets/javascripts/utilities/buildArticleHTML.js.erb b/app/assets/javascripts/utilities/buildArticleHTML.js.erb index 1ccfacedf..55d8cf2e5 100644 --- a/app/assets/javascripts/utilities/buildArticleHTML.js.erb +++ b/app/assets/javascripts/utilities/buildArticleHTML.js.erb @@ -37,44 +37,42 @@ function buildArticleHTML(article) { if (article.class_name == "PodcastEpisode"){ flareTag = "podcast" } - if (article.class_name == "Comment"){ - flareTag = "comment" - } if (article.class_name == "User"){ flareTag = "person" } - var rc = article.positive_reactions_count + var rc = article.positive_reactions_count || article.reactions_count var reactionsCountHTML = '' if ((rc || '0') > 0 && article.class_name != "User") { var reactionsCountHTML = '
" alt="heart" />
' } - var picUrl; - var profileUsername; - var userName; - if (article.class_name == "PodcastEpisode"){ - picUrl = article.main_image; - profileUsername = article.slug; - userName = article.title; - } else { - picUrl = article.user.profile_image_90; - profileUsername = article.user.username; - userName = article.user.name; - } + var picUrl = article.user.profile_image_90 + var profileUsername = article.user.username var orgHeadline = ""; if (article.organization && !document.getElementById("organization-article-index")) { orgHeadline = '
'+article.organization.name+' logo'+article.organization.name+'
' } var bodyTextSnippet = ""; + var commentsBlobSnippet = ""; var searchSnippetHTML = ""; - if (article.highlight && article.highlight.body_text.length > 0){ - var firstSnippetChar = article.highlight.body_text[0]; - var startingEllipsis = "" - if (firstSnippetChar.toLowerCase() != firstSnippetChar.toUpperCase()){ - startingEllipsis = "…" + if (article._snippetResult && article._snippetResult.body_text){ + if (article._snippetResult.body_text.matchLevel != "none"){ + var firstSnippetChar = article._snippetResult.body_text.value[0]; + var startingEllipsis = "" + if (firstSnippetChar.toLowerCase() != firstSnippetChar.toUpperCase()){ + startingEllipsis = "…" + } + bodyTextSnippet = startingEllipsis+article._snippetResult.body_text.value + "…" } - bodyTextSnippet = startingEllipsis + article.highlight.body_text.join("...") + "…"; - if (bodyTextSnippet.length > 0){ - searchSnippetHTML = '
' + bodyTextSnippet + '
' + if (article._snippetResult.comments_blob.matchLevel != "none" && bodyTextSnippet === ""){ + var firstSnippetChar = article._snippetResult.comments_blob.value[0]; + var startingEllipsis = "" + if (firstSnippetChar.toLowerCase() != firstSnippetChar.toUpperCase()){ + startingEllipsis = "…" + } + commentsBlobSnippet = startingEllipsis+article._snippetResult.comments_blob.value + "… (comments)" + } + if ((bodyTextSnippet.length > 0 || commentsBlobSnippet.length > 0) && article.class_name == "Article"){ + searchSnippetHTML = '
'+bodyTextSnippet+commentsBlobSnippet+'
' } } var saveButton = ''; @@ -129,7 +127,7 @@ function buildArticleHTML(article) { '+searchSnippetHTML+'\ \ \ -

'+filterXSS(userName)+publishDate+timeAgoInWords+'

\ +

'+filterXSS(article.user.name)+publishDate+timeAgoInWords+'

\
'+tagString+'
\ '+commentsCountHTML+reactionsCountHTML+readingTimeHTML+'\ '+saveButton+''; diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index c7fd3ef7b..567cef954 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -17,15 +17,15 @@ class SearchController < ApplicationController per_page ].freeze - FEED_PARAMS = [ - :class_name, - :page, - :per_page, - :search_fields, - :sort_by, - :tag_names, - :user_id, - { published_at: [:gte] }, + FEED_PARAMS = %i[ + page + per_page + published_at + search_fields + sort_by + tag_names + user_id + class_name ].freeze def tags @@ -65,7 +65,7 @@ class SearchController < ApplicationController # No need to check for articles or podcast episodes if we know we only want users user_search else - # if params[:class_name] == PodcastEpisode, Article, or Comment then skip user lookup + # if params[:class_name] == PodcastEpisode or Article then skip user lookup feed_content_search end diff --git a/app/javascript/article-form/__tests__/articleForm.test.jsx b/app/javascript/article-form/__tests__/articleForm.test.jsx index 809b3c1be..cb3a2a776 100644 --- a/app/javascript/article-form/__tests__/articleForm.test.jsx +++ b/app/javascript/article-form/__tests__/articleForm.test.jsx @@ -3,6 +3,7 @@ import render from 'preact-render-to-json'; import { shallow, deep } from 'preact-render-spy'; import { JSDOM } from 'jsdom'; import ArticleForm from '../articleForm'; +import algoliasearch from '../elements/__mocks__/algoliasearch'; const dummyArticleUpdatedAt = new Date(); const getArticleForm = () => ( @@ -37,6 +38,8 @@ describe('', () => { global.document.body.innerHTML = "
"; + global.window.algoliasearch = algoliasearch; + localStorage.clear(); /* eslint-disable-next-line no-underscore-dangle */ localStorage.__STORE__ = {}; diff --git a/app/javascript/articles/Article.jsx b/app/javascript/articles/Article.jsx index b9d15adb6..79dfe6a24 100644 --- a/app/javascript/articles/Article.jsx +++ b/app/javascript/articles/Article.jsx @@ -32,7 +32,7 @@ export const Article = ({ const timeAgoIndicator = timeAgo({ oldTimeInSeconds: article.published_at_int, formatter: x => x, - }); + }) return (
{article.class_name === 'Article' && ( // eslint-disable-next-line no-underscore-dangle - + )}
@@ -94,7 +94,7 @@ export const Article = ({ )} {article.published_at_int ? ( - {timeAgoIndicator.length > 0 ? `(${timeAgoIndicator})` : ''} + {timeAgoIndicator.length > 0 ? `(${timeAgoIndicator})`: '' } ) : null} diff --git a/app/javascript/articles/__tests__/__snapshots__/Article.test.jsx.snap b/app/javascript/articles/__tests__/__snapshots__/Article.test.jsx.snap index 869069b7b..dd67e9b5a 100644 --- a/app/javascript/articles/__tests__/__snapshots__/Article.test.jsx.snap +++ b/app/javascript/articles/__tests__/__snapshots__/Article.test.jsx.snap @@ -1101,7 +1101,7 @@ exports[`
component should render with a snippet result 1`] = ` class="search-snippet" > - …copying Rest withdrawal Handcrafted multi-state Pre-emptive e-markets feed...overriding RSS Fantastic Plastic Gloves invoice productize systemic Monaco… + …copying Rest withdrawal Handcrafted multi-state Pre-emptive e-markets feed overriding RSS Fantastic Plastic Gloves invoice productize systemic Monaco… diff --git a/app/javascript/articles/__tests__/utilities/articleUtilities.js b/app/javascript/articles/__tests__/utilities/articleUtilities.js index c6ac6f108..3f8ee1dd9 100644 --- a/app/javascript/articles/__tests__/utilities/articleUtilities.js +++ b/app/javascript/articles/__tests__/utilities/articleUtilities.js @@ -24,7 +24,6 @@ export const article = { }, published_at_int: 1582037964819, published_timestamp: 'Tue, 18 Feb 2020 14:59:24 GMT', - published_at: '2020-02-18T14:59:24Z', readable_publish_date: 'February 18', }; @@ -85,13 +84,18 @@ export const articleWithSnippetResult = { }, published_at_int: 1582037964819, published_timestamp: 'Tue, 18 Feb 2020 14:59:24 GMT', - published_at: '2020-02-18T14:59:24Z', readable_publish_date: 'February 18', - highlight: { - body_text: [ - 'copying Rest withdrawal Handcrafted multi-state Pre-emptive e-markets feed', - 'overriding RSS Fantastic Plastic Gloves invoice productize systemic Monaco', - ], + _snippetResult: { + body_text: { + matchLevel: 'full', + value: + 'copying Rest withdrawal Handcrafted multi-state Pre-emptive e-markets feed overriding RSS Fantastic Plastic Gloves invoice productize systemic Monaco', + }, + comments_blob: { + matchLevel: 'none', + value: + 'virtual index Global mindshare Malagasy Ariary back up Handmade green Interactions violet bandwidth Chief e-commerce front-end neural', + }, }, }; @@ -119,7 +123,6 @@ export const articleWithReactions = { }, published_at_int: 1582037964819, published_timestamp: 'Tue, 18 Feb 2020 14:59:24 GMT', - published_at: '2020-03-19T10:04:15-05:00', readable_publish_date: 'February 18', positive_reactions_count: 232, }; @@ -148,7 +151,6 @@ export const articleWithComments = { }, published_at_int: 1582037964819, published_timestamp: 'Tue, 18 Feb 2020 14:59:24 GMT', - published_at: '2020-03-19T10:04:15-05:00', readable_publish_date: 'February 18', positive_reactions_count: 428, comments_count: 213, @@ -178,7 +180,6 @@ export const articleWithReadingTimeGreaterThan1 = { }, published_at_int: 1582037964819, published_timestamp: 'Tue, 18 Feb 2020 14:59:24 GMT', - published_at: '2020-02-18T14:59:24Z', readable_publish_date: 'February 18', reading_time: 8, }; @@ -207,7 +208,6 @@ export const videoArticle = { }, published_at_int: 1582038662478, published_timestamp: 'Tue, 18 Feb 2020 15:11:02 GMT', - published_at: '2020-02-18T14:59:24Z', readable_publish_date: 'February 18', cloudinary_video_url: '/images/onboarding-background.png', video_duration_in_minutes: 10, @@ -237,7 +237,6 @@ export const podcastArticle = { }, published_at_int: 1582038662478, published_timestamp: 'Tue, 18 Feb 2020 15:11:02 GMT', - published_at: '2020-02-18T15:11:02Z', readable_publish_date: 'February 18', podcast: { slug: 'monitor-recontextualize', @@ -271,7 +270,6 @@ export const podcastEpisodeArticle = { }, published_at_int: 1582038662478, published_timestamp: 'Tue, 18 Feb 2020 15:11:02 GMT', - published_at: '2020-02-18T15:11:02Z', readable_publish_date: 'February 18', }; diff --git a/app/javascript/articles/components/SearchSnippet.jsx b/app/javascript/articles/components/SearchSnippet.jsx index 6b7a0901c..22aaa79ba 100644 --- a/app/javascript/articles/components/SearchSnippet.jsx +++ b/app/javascript/articles/components/SearchSnippet.jsx @@ -1,25 +1,45 @@ import { h } from 'preact'; import { articleSnippetResultPropTypes } from '../../src/components/common-prop-types'; -export const SearchSnippet = ({ highlightText }) => { - if (highlightText && highlightText.body_text.length > 0) { - const hitHighlights = highlightText.body_text; +export const SearchSnippet = ({ snippetResult }) => { + if (snippetResult && snippetResult.body_text) { let bodyTextSnippet = ''; - if (hitHighlights[0]) { - const firstSnippetChar = hitHighlights[0]; + if (snippetResult.body_text.matchLevel !== 'none') { + const firstSnippetChar = snippetResult.body_text.value[0]; let startingEllipsis = ''; if (firstSnippetChar.toLowerCase() !== firstSnippetChar.toUpperCase()) { startingEllipsis = '…'; } - bodyTextSnippet = `${startingEllipsis + hitHighlights.join('...')}…`; + + bodyTextSnippet = `${startingEllipsis + snippetResult.body_text.value}…`; } - if (bodyTextSnippet.length > 0) { + let commentsBlobSnippet = ''; + + if ( + snippetResult.comments_blob.matchLevel !== 'none' && + bodyTextSnippet === '' + ) { + const firstSnippetChar = snippetResult.comments_blob.value[0]; + let startingEllipsis = ''; + + if (firstSnippetChar.toLowerCase() !== firstSnippetChar.toUpperCase()) { + startingEllipsis = '…'; + } + + commentsBlobSnippet = `${startingEllipsis + + snippetResult.comments_blob.value}… (comments)`; + } + + if (bodyTextSnippet.length > 0 || commentsBlobSnippet.length > 0) { return (
- {bodyTextSnippet} + + {bodyTextSnippet} + {commentsBlobSnippet} +
); } @@ -30,7 +50,7 @@ export const SearchSnippet = ({ highlightText }) => { SearchSnippet.propTypes = { // eslint-disable-next-line no-underscore-dangle - highlightText: articleSnippetResultPropTypes.isRequired, + snippetResult: articleSnippetResultPropTypes.isRequired, }; SearchSnippet.displayName = 'SearchSnippet'; diff --git a/app/javascript/src/components/common-prop-types/article-prop-types.js b/app/javascript/src/components/common-prop-types/article-prop-types.js index 480a7c410..45f30e5aa 100644 --- a/app/javascript/src/components/common-prop-types/article-prop-types.js +++ b/app/javascript/src/components/common-prop-types/article-prop-types.js @@ -3,7 +3,14 @@ import { tagPropTypes } from './tag-prop-types'; import { organizationPropType } from './organization-prop-type'; export const articleSnippetResultPropTypes = PropTypes.shape({ - body_text: PropTypes.arrayOf(PropTypes.string), + body_text: PropTypes.shape({ + matchLevel: PropTypes.oneOf(['full', 'none']), + value: PropTypes.string.isRequired, + }), + comments_blob: PropTypes.shape({ + matchLevel: PropTypes.oneOf(['full', 'none']), + value: PropTypes.string.isRequired, + }), }); export const articlePropTypes = PropTypes.shape({ @@ -28,7 +35,7 @@ export const articlePropTypes = PropTypes.shape({ name: PropTypes.string.isRequired, }), organization: organizationPropType, - highlight: articleSnippetResultPropTypes, + _snippetResult: articleSnippetResultPropTypes, positive_reactions_count: PropTypes.number, reactions_count: PropTypes.number, comments_count: PropTypes.number, diff --git a/app/javascript/src/utils/__tests__/search.test.js b/app/javascript/src/utils/__tests__/search.test.js index 20a8e5fb4..ef589e678 100644 --- a/app/javascript/src/utils/__tests__/search.test.js +++ b/app/javascript/src/utils/__tests__/search.test.js @@ -61,7 +61,7 @@ describe('Search utilities', () => { describe('preloadSearchResults', () => { beforeEach(() => { global.InstantClick = { - preload: (url) => url, + preload: url => url, }; jest.spyOn(InstantClick, 'preload'); }); @@ -145,7 +145,7 @@ describe('Search utilities', () => { describe('displaySearchResults', () => { beforeEach(() => { global.InstantClick = { - display: (url) => url, + display: url => url, }; jest.spyOn(InstantClick, 'display'); }); @@ -242,7 +242,7 @@ describe('Search utilities', () => { }); test('should return response formatted as JSON', () => { - responsePromise.then((response) => { + responsePromise.then(response => { expect(response).toBeInstanceOf(Object); expect(response).toMatchObject({ results: expect.any(Array) }); }); diff --git a/app/javascript/src/utils/search.js b/app/javascript/src/utils/search.js index 6893cf03e..5d5388c0a 100644 --- a/app/javascript/src/utils/search.js +++ b/app/javascript/src/utils/search.js @@ -33,7 +33,7 @@ function fixedEncodeURIComponent(str) { // from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent return encodeURIComponent(str).replace( /[!'()*]/g, - (c) => `%${c.charCodeAt(0).toString(16)}`, + c => `%${c.charCodeAt(0).toString(16)}`, ); } @@ -98,5 +98,5 @@ export function fetchSearch(endpoint, dataHash) { 'Content-Type': 'application/json', }, credentials: 'same-origin', - }).then((response) => response.json()); + }).then(response => response.json()); } diff --git a/app/views/articles/_search.html.erb b/app/views/articles/_search.html.erb index 9f2ce23ee..242bae4cd 100644 --- a/app/views/articles/_search.html.erb +++ b/app/views/articles/_search.html.erb @@ -16,13 +16,16 @@ var params = getQueryParams(document.location.search); + // var query = escape(params.q); function searchMain() { var query = filterXSS(params.q); var filters = filterXSS(params.filters || ""); document.getElementById("substories").innerHTML = '

' + var client = algoliasearch('<%= ApplicationConfig["ALGOLIASEARCH_APPLICATION_ID"] %>', '<%= ALGOLIASEARCH_PUBLIC_SEARCH_ONLY_KEY %>'); + var index = client.initIndex('searchables_<%= Rails.env %>'); if (document.getElementById("query-wrapper")) { - search(query, filters); - initializeFilters(query, filters); + search(query, index, filters); + initializeFilters(query, index, filters); } } @@ -30,7 +33,7 @@ return String(str).replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"'); } - function initializeFilters(query, filters) { + function initializeFilters(query, index, filters) { var filterButts = document.getElementsByClassName("query-filter-button"); for (var i = 0; i < filterButts.length; i++) { if (filters == filterButts[i].dataset.filter) { @@ -50,58 +53,60 @@ if (className.indexOf("selected") == -1) { e.target.classList.add("selected"); window.history.replaceState(null, null, "/search?q=" + query + "&filters=" + filters); - search(query, filters); + search(query, index, filters); } else { window.history.replaceState(null, null, "/search?q=" + query); - search(query, ""); + search(query, index, ""); } } } } - function search(query, filters) { - var hashtags = query.match(/#\w+/g); - var searchTerm = query.replace(/#/g, '').trim(); - var searchHash = { per_page: 60, page: 0 }; + function search(query, index, filters) { + var hashtags = query.match(/#\w+/g) + var searchObj = { + hitsPerPage: 60, + page: "0", + queryType: "prefixNone", + attributesToRetrieve: [ + 'id', + 'title', + 'path', + 'class_name', + 'comments_count', + 'tag_list', + 'readable_publish_date', + 'positive_reactions_count', + 'flare_tag', + 'user', + 'reading_time' + ], + attributesToHighlight: [], + exactOnSingleWordQuery: "none", + attributesToSnippet: ['body_text:19', 'comments_blob:8'], + } - if (hashtags && hashtags.length > 0) { + if (filters === "MY_POSTS" && userData()) { + searchObj["tagFilters"] = [['user_' + userData()['id']]] + } else if (hashtags != null && hashtags.length > 0) { for(var i = 0; i < hashtags.length; i++){ - hashtags[i] = hashtags[i].replace(/#/,''); + hashtags[i] = hashtags[i].replace(/#/,'') } - searchHash.tag_names = hashtags; + searchObj["tagFilters"] = hashtags + } else { + searchObj["filters"] = filters } - - if (filters) { - filters.split('&').forEach((filter) => { - const [key, value] = filter.split(':'); - searchHash[key] = value; - }); - } - - if (searchTerm) { searchHash.search_fields = searchTerm; } - - const searchParams = new URLSearchParams(searchHash).toString(); - - fetch(`/search/feed_content?${searchParams}`, { - method: 'GET', - headers: { - Accept: 'application/json', - 'X-CSRF-Token': window.csrfToken, - 'Content-Type': 'application/json', - }, - credentials: 'same-origin', - }) - .then(response => response.json()) - .then((content) => { + index.search(query, searchObj) + .then(function searchDone(content) { var resultDivs = [] - content.result.forEach(function (story, i) { + content.hits.forEach(function (story, i) { resultDivs.push(buildArticleHTML(story)); }) document.getElementById("substories").innerHTML = resultDivs.join(""); initializeReadingListIcons(); initializeAllFollowButts(); document.getElementById("substories").classList.add("search-results-loaded"); - if (content.result.length == 0) { + if (content.hits.length == 0) { document.getElementById("substories").innerHTML = '
No results match that query
' } }); diff --git a/app/views/articles/index.html.erb b/app/views/articles/index.html.erb index f06fdda3d..ea5e8551e 100644 --- a/app/views/articles/index.html.erb +++ b/app/views/articles/index.html.erb @@ -30,7 +30,7 @@ data-params="<%= params.to_json(only: %i[tag username q]) %>" data-which="<%= @list_of %>" data-tag="" data-feed="<%= params[:timeframe] || "base-feed" %>" - data-articles-since="<%= Timeframer.new(params[:timeframe]).datetime&.iso8601 %>"> + data-articles-since="<%= Timeframer.new(params[:timeframe]).datetime.to_i %>"> <%= render "articles/sidebar" %> diff --git a/app/views/articles/search.html.erb b/app/views/articles/search.html.erb index 057966357..24fba2304 100644 --- a/app/views/articles/search.html.erb +++ b/app/views/articles/search.html.erb @@ -6,7 +6,7 @@ data-params="<%= params.to_json(only: %i[tag username q]) %>" data-which="<%= @list_of %>" data-tag="" data-feed="<%= params[:timeframe] || "base-feed" %>" - data-articles-since="<%= Timeframer.new(params[:timeframe]).datetime&.iso8601 %>"> + data-articles-since="<%= Timeframer.new(params[:timeframe]).datetime.to_i %>"> <%= render "articles/search/sidebar" %>
diff --git a/app/views/articles/search/_sidebar.html.erb b/app/views/articles/search/_sidebar.html.erb index 6e1df2848..0f6654454 100644 --- a/app/views/articles/search/_sidebar.html.erb +++ b/app/views/articles/search/_sidebar.html.erb @@ -9,9 +9,8 @@ POSTS PODCASTS PEOPLE - COMMENTS
- ONLY MY POSTS + ONLY MY POSTS
diff --git a/app/views/articles/tag_index.html.erb b/app/views/articles/tag_index.html.erb index 76589e535..e4bb9a5fe 100644 --- a/app/views/articles/tag_index.html.erb +++ b/app/views/articles/tag_index.html.erb @@ -34,7 +34,7 @@ data-tag="<%= @tag %>" data-feed="<%= params[:timeframe] || "base-feed" %>" data-requires-approval="<%= @tag_model.requires_approval %>" - data-articles-since="<%= Timeframer.new(params[:timeframe]).datetime&.iso8601 %>"> + data-articles-since="<%= Timeframer.new(params[:timeframe]).datetime.to_i %>"> <%= render "articles/tags/sidebar" %>
<% if @tag_model && @tag_model.supported %> diff --git a/app/views/organizations/show.html.erb b/app/views/organizations/show.html.erb index eb5bbd3fb..438573854 100644 --- a/app/views/organizations/show.html.erb +++ b/app/views/organizations/show.html.erb @@ -8,7 +8,7 @@ data-params="<%= params.to_json(only: %i[tag username q]) %>" data-which="<%= @list_of %>" data-tag="<%= "organization_#{@organization.id}" %>" data-feed="<%= params[:timeframe] || "base-feed" %>" - data-articles-since="<%= Timeframer.new(params[:timeframe]).datetime&.iso8601 %>"> + data-articles-since="<%= Timeframer.new(params[:timeframe]).datetime.to_i %>"> <%= render "organizations/sidebar" %>
diff --git a/app/views/podcast_episodes/index.html.erb b/app/views/podcast_episodes/index.html.erb index 27672b0b7..7243f4585 100644 --- a/app/views/podcast_episodes/index.html.erb +++ b/app/views/podcast_episodes/index.html.erb @@ -30,7 +30,7 @@ data-params="<%= params.to_json(only: %i[tag username q]) %>" data-which="<%= @list_of %>" data-tag="" data-feed="<%= params[:timeframe] || "base-feed" %>" - data-articles-since="<%= Timeframer.new(params[:timeframe]).datetime&.iso8601 %>"> + data-articles-since="<%= Timeframer.new(params[:timeframe]).datetime.to_i %>"> <%= render "podcast_episodes/sidebar" %>
diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 2cee6799a..7420e1583 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -171,8 +171,8 @@ <% end %>
" data-which="<%= @list_of %>" - data-tag="" + data-params="<%= params.to_json(only: %i[tag username q]) %>" data-which="<%= @list_of %>" + data-tag="<%= "user_#{@user.id}" %>" data-feed="<%= params[:timeframe] || "base-feed" %>" data-articles-since="0"> <%= render "users/sidebar" %>