mirror of
https://github.com/viq/NewsBlur.git
synced 2025-09-18 21:43:31 +00:00
Adding Add URL button to site search on dashboard. Thanks to Brian Johns for the suggestion.
This commit is contained in:
parent
a5eda6d0b2
commit
2eb3218094
2 changed files with 27 additions and 12 deletions
|
@ -386,21 +386,24 @@ class SearchFeed:
|
|||
logging.debug(" ***> ~FRNo search server available.")
|
||||
|
||||
@classmethod
|
||||
def query(cls, text):
|
||||
def query(cls, text, max_subscribers=5):
|
||||
try:
|
||||
cls.ES().default_indices = cls.index_name()
|
||||
cls.ES().indices.refresh()
|
||||
except pyes.exceptions.NoServerAvailable:
|
||||
logging.debug(" ***> ~FRNo search server available.")
|
||||
return []
|
||||
|
||||
|
||||
if settings.DEBUG:
|
||||
max_subscribers = 1
|
||||
|
||||
logging.info("~FGSearch ~FCfeeds~FG: ~SB%s" % text)
|
||||
q = pyes.query.BoolQuery()
|
||||
q.add_should(pyes.query.MatchQuery('address', text, analyzer="simple", cutoff_frequency=0.0005, minimum_should_match="75%"))
|
||||
q.add_should(pyes.query.MatchQuery('link', text, analyzer="simple", cutoff_frequency=0.0005, minimum_should_match="75%"))
|
||||
q.add_should(pyes.query.MatchQuery('title', text, analyzer="simple", cutoff_frequency=0.0005, minimum_should_match="75%"))
|
||||
q = pyes.Search(q, min_score=1)
|
||||
results = cls.ES().search(query=q, size=5, doc_types=[cls.type_name()], sort="num_subscribers:desc")
|
||||
results = cls.ES().search(query=q, size=max_subscribers, doc_types=[cls.type_name()], sort="num_subscribers:desc")
|
||||
|
||||
return results
|
||||
|
||||
|
|
|
@ -6,7 +6,8 @@ NEWSBLUR.Views.DashboardSearch = Backbone.View.extend({
|
|||
"keyup .NB-module-search-sites input" : "search_sites",
|
||||
"keyup .NB-module-search-people input" : "search_people",
|
||||
"click .NB-module-search-sites .NB-search-close" : "clear_site",
|
||||
"click .NB-module-search-people .NB-search-close" : "clear_person"
|
||||
"click .NB-module-search-people .NB-search-close" : "clear_person",
|
||||
"click .NB-module-search-add-url" : "add_url"
|
||||
},
|
||||
|
||||
initialize: function() {
|
||||
|
@ -46,18 +47,23 @@ NEWSBLUR.Views.DashboardSearch = Backbone.View.extend({
|
|||
|
||||
if (!data || !data.feeds || !data.feeds.length) {
|
||||
this.$results.html($.make('div', {
|
||||
className: 'NB-friends-search-badges-empty'
|
||||
className: 'NB-friends-search-badges-empty NB-feed-badge'
|
||||
}, [
|
||||
$.make('div', { className: 'NB-raquo' }, '»'),
|
||||
'Sorry, nothing matches "'+query+'".'
|
||||
]));
|
||||
return;
|
||||
}
|
||||
|
||||
this.$results.html($.make('div', _.map(data.feeds, function(feed) {
|
||||
var model = new NEWSBLUR.Models.Feed(feed);
|
||||
return new NEWSBLUR.Views.FeedBadge({model: model});
|
||||
})));
|
||||
} else {
|
||||
this.$results.html($.make('div', _.map(data.feeds, function(feed) {
|
||||
var model = new NEWSBLUR.Models.Feed(feed);
|
||||
return new NEWSBLUR.Views.FeedBadge({model: model});
|
||||
})));
|
||||
}
|
||||
|
||||
if (query.indexOf('.') != -1) {
|
||||
this.$results.append($.make('div', { className: 'NB-feed-badge' }, [
|
||||
$.make('div', { className: 'NB-module-search-add-url NB-badge-action-add NB-modal-submit-button NB-modal-submit-green' }, 'Subscribe to ' + query)
|
||||
]));
|
||||
}
|
||||
}, this));
|
||||
},
|
||||
|
||||
|
@ -109,6 +115,12 @@ NEWSBLUR.Views.DashboardSearch = Backbone.View.extend({
|
|||
this.$person_input.val('');
|
||||
this.$results.empty();
|
||||
this.$person.removeClass('NB-active');
|
||||
},
|
||||
|
||||
add_url: function() {
|
||||
var query = this.$site_input.val();
|
||||
|
||||
NEWSBLUR.reader.open_add_feed_modal({url: query});
|
||||
}
|
||||
|
||||
});
|
Loading…
Add table
Reference in a new issue