From 0ffaf6f87171ef5f4790b2941e723f5624ec7352 Mon Sep 17 00:00:00 2001 From: abki Date: Sun, 19 Jul 2009 17:58:11 +0200 Subject: [PATCH] regex hack to get 2 & 3 letter words to work modified: models.py modified: planet.py modified: static/css/layout.css modified: templates/ebuildfind/base.html modified: templates/ebuildfind/search.html modified: views.py --- models.py | 6 +++++- planet.py | 4 +--- static/css/layout.css | 9 ++++++++- templates/ebuildfind/base.html | 37 +++++++++++++++++++------------------ templates/ebuildfind/search.html | 38 ++++++++++++++++++++++++++++++++++---- views.py | 19 +++++++++++++------ 6 files changed, 80 insertions(+), 33 deletions(-) diff --git a/models.py b/models.py index 5f1ee15..0f83e62 100644 --- a/models.py +++ b/models.py @@ -5,7 +5,6 @@ from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes import generic PUNCTUATION_REGEX = re.compile('[' + re.escape(string.punctuation) + ']') -FULL_TEXT_MIN_LENGTH = 3 FULL_TEXT_STOP_WORDS = frozenset([ 'a', 'about', 'according', 'accordingly', 'affected', 'affecting', 'after', @@ -94,6 +93,11 @@ class Searchable(object): ctype = ContentType.objects.get_for_model(cls) return Index.objects.filter(content__search=query).filter(content_type=ctype) + @staticmethod + def regex(cls, query): + ctype = ContentType.objects.get_for_model(cls) + return Index.objects.filter(content__regex=query).filter(content_type=ctype) + def index(self): return Index.index(self) diff --git a/planet.py b/planet.py index 6c9abd5..d6ca3c6 100644 --- a/planet.py +++ b/planet.py @@ -2,8 +2,6 @@ import shelve from feedcache.cache import Cache -import pdb - from django.template.defaultfilters import truncatewords_html from django.utils.encoding import smart_unicode @@ -39,7 +37,7 @@ class Parser: """ def __init__(self, url, summary=False): - storage = shelve.open(".feedcache") + storage = shelve.open("/home/timemachine/.feedcache") try : fc = Cache(storage) self.feed = fc.fetch(url) diff --git a/static/css/layout.css b/static/css/layout.css index f1c901d..4d9900f 100755 --- a/static/css/layout.css +++ b/static/css/layout.css @@ -7,7 +7,6 @@ body { background: #FFF; color: #333; font-size: 11px; - padding: 50px 0 40px; } h7 { font-size: 11px; font-weight: normal;} @@ -23,6 +22,13 @@ h7 { font-size: 11px; font-weight: normal;} /* headings ----------------------------------------------- */ +#header { + font-size: 13px; + background: #5218EC; + padding: 5px; + margin-bottom: 50px; +} + /* search-box ----------------------------------------------- */ @@ -85,4 +91,5 @@ ul, li { .ebuild .path { float: left; + font-weight: bold; } \ No newline at end of file diff --git a/templates/ebuildfind/base.html b/templates/ebuildfind/base.html index b20327b..73d45bf 100644 --- a/templates/ebuildfind/base.html +++ b/templates/ebuildfind/base.html @@ -10,11 +10,14 @@ - +
+
@@ -26,26 +29,20 @@ - {% block help %} -

This is a search engine for ebuilds, it looks for the query in the - category, description, application name. Give it a - try now - and here

-

3 July 09': The search engine is now supported by - Mysql FTS in boolean mode, try this out.

-

28 June 09': Some ebuilds and overlays are missing please - notify me bugs - at my email adress

- {% endblock %} +
+
-
+
{% block results %}{% endblock %}
+
+ {% block adv %}{% endblock %} +
@@ -99,10 +96,10 @@
-

Google News

+

Identi.ca community

- - {% for post in GGoogle %} +

Check out ebuildfind@identi.ca

+ {% for post in identica %}
{{ post.title }}
{{ post.content|safe }}
@@ -115,12 +112,16 @@
+
+ {% block advbottom %} + {% endblock %} +

"Gentoo" and "G" logo are the property of Gentoo Foundation, Inc.

This website is made with - django and whoosh - hosted by alwaysdata.com

+ django and mysql FTS hosted by + alwaysdata.com

+ +{% endblock %} + +{% block advbottom %} + + +{% endblock %} \ No newline at end of file diff --git a/views.py b/views.py index d10edcf..0317b71 100644 --- a/views.py +++ b/views.py @@ -12,15 +12,15 @@ def index(request): GPlanet = Parser("http://planet.gentoo.org/atom.xml") GOverlays = Parser("http://overlays.gentoo.org/rss20.xml") GNews = Parser("http://www.gentoo.org/rdf/en/gentoo-news.rdf") - GGoogle = Parser("http://news.google.fr/news?pz=1&ned=us&hl=en&q=gentoo+AND+(linux+OR+OS+OR+Operating+System+OR+GNU)&output=rss") + identica = Parser("https://identi.ca/api/laconica/groups/timeline/gentoo.atom") response = dict() - response['GGoogle'] = GGoogle + response['identica'] = identica response['GNews'] = GNews response['GOverlays'] = GOverlays response['GPlanet'] = GPlanet - + return render_to_response("ebuildfind/index.html", response) @@ -39,12 +39,19 @@ def search(request): query = PUNCTUATION_REGEX.sub(' ', query) except: pass - - if(len(query)>2): + + if(len(query)>3): response["error"] = False response["query"] = query results = Ebuild.search(Ebuild, query) response["results"] = results response["nb"] = len(results) - + + elif len(query) in (2, 3): + response["error"] = False + response["query"] = query + results = Ebuild.regex(Ebuild, query) + response["results"] = results + response["nb"] = len(results) + return render_to_response("ebuildfind/search.html", response) -- 2.11.4.GIT