Skip to content

Commit

Permalink
Search plugin flexget_archive now produces sensible results.
Browse files Browse the repository at this point in the history
- Does not create None fields, Fixes Flexget#2069
  • Loading branch information
paranoidi committed Jun 5, 2013
1 parent 54c30ac commit a3bc27f
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions flexget/plugins/generic/archive.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import unicode_literals, division, absolute_import
import logging
import re
from datetime import datetime
from argparse import Action, ArgumentError

Expand Down Expand Up @@ -368,7 +369,8 @@ def search(self, entry, config=None):
for archive_entry in search(session, query, desc=True):
log.debug('rewrite search result: %s' % archive_entry)
entry = Entry()
entry.update_using_map(self.entry_map, archive_entry)
entry.update_using_map(self.entry_map, archive_entry,
ignore_none=True)
if entry.isvalid():
entries.append(entry)
log.debug('found %i entries' % len(entries))
Expand Down Expand Up @@ -478,14 +480,17 @@ def search(session, text, tags=None, sources=None, desc=False):
"""
Search from the archive.
:param string text: Search keywords, spaces will be replaced with %
:param string text: Search text, spaces and dots are tried to be ignored.
:param Session session: SQLAlchemy session, should not be closed while iterating results.
:param list tags: Optional list of acceptable tags
:param list sources: Optional list of acceptable sources
:param bool desc: Sort results descending
:return: ArchiveEntries responding to query
"""
keyword = unicode(text).replace(' ', '%')
keyword = unicode(text).replace(' ', '%').replace('.', '%')
# clean the text from any unwanted regexp, convert spaces and keep dots as dots
normalized_re = re.escape(text.replace('.', ' ')).replace('\\ ', ' ').replace(' ', '.')
find_re = re.compile(normalized_re, re.IGNORECASE)
query = session.query(ArchiveEntry).filter(ArchiveEntry.title.like('%' + keyword + '%'))
if tags:
query = query.filter(ArchiveEntry.tags.any(ArchiveTag.name.in_(tags)))
Expand All @@ -496,7 +501,10 @@ def search(session, text, tags=None, sources=None, desc=False):
else:
query = query.order_by(ArchiveEntry.added.asc())
for a in query.yield_per(5):
yield a
if find_re.match(a.title):
yield a
else:
log.trace('title %s is too wide match' % a.title)


class ArchiveCli(object):
Expand Down

0 comments on commit a3bc27f

Please sign in to comment.