Changeset 1548 for trunk/pylucid/PyLucid/plugins_internal/search/search.py
- Timestamp:
- 05/01/08 12:24:21 (7 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/pylucid/PyLucid/plugins_internal/search/search.py
r1544 r1548 27 27 28 28 from django import newforms as forms 29 from django.utils.safestring import mark_safe 29 30 from django.utils.translation import ugettext as _ 30 from django.utils.safestring import mark_safe 31 32 from PyLucid.models import Page 31 33 32 from PyLucid.system.BasePlugin import PyLucidBasePlugin 34 33 from PyLucid.tools.utils import escape 35 36 37 # How min/max long must a search term be? 38 MIN_TERM_LEN = 3 39 MAX_TERM_LEN = 50 40 41 # Number of the paged for the result page: 42 MAX_RESULTS = 20 43 44 # The length of the text-hit-cutouts: 45 TEXT_CUTOUT_LEN = 50 46 47 # Max. cutout lines for every search term: 48 MAX_CUTOUTS_LINES = 5 34 from PyLucid.models import Page, Plugin 49 35 50 36 … … 71 57 ) 72 58 73 74 class SearchForm(forms.Form): 75 # TODO: min und max should be saved in the prefereces. 76 search_string = forms.CharField( 77 min_length = MIN_TERM_LEN, max_length = MAX_TERM_LEN 78 ) 59 # We used preferences values in a newform. We need these values here. 60 try: 61 preferences = Plugin.objects.get_preferences(__file__) 62 except Plugin.DoesNotExist, e: 63 # in _install section? 64 pass 65 else: 66 class SearchForm(forms.Form): 67 search_string = forms.CharField( 68 min_length = preferences["min_term_len"], 69 max_length = preferences["max_term_len"], 70 ) 79 71 80 72 … … 85 77 Insert a empty search form into the page. 86 78 """ 87 self.page_msg("Preferences:", self.preferences)88 79 search_form = SearchForm() 89 80 context = { … … 138 129 search_strings = [] 139 130 for term in raw_search_strings: 140 if len(term)< MIN_TERM_LEN:131 if len(term)<preferences["min_term_len"]: 141 132 self.page_msg("Ignore '%s' (too small)" % cgi.escape(term)) 142 133 else: … … 178 169 179 170 # Use only the first pages: 180 results = results[: MAX_RESULTS]171 results = results[:preferences["max_results"]] 181 172 182 173 # Build a dict, for the template … … 191 182 the lines. 192 183 """ 184 text_cutout_len = preferences["text_cutout_len"] 185 max_cutout_lines = preferences["max_cutout_lines"] 186 193 187 for result in results: 194 188 result["cutouts"] = [] … … 197 191 for term in search_strings: 198 192 start = 0 199 for _ in xrange( MAX_CUTOUTS_LINES):193 for _ in xrange(max_cutout_lines): 200 194 try: 201 195 index = content.index(term, start) … … 206 200 start = index+1 207 201 208 if index< TEXT_CUTOUT_LEN:209 txt = content[: TEXT_CUTOUT_LEN]202 if index<text_cutout_len: 203 txt = content[:text_cutout_len] 210 204 else: 211 txt = content[index-TEXT_CUTOUT_LEN:index+TEXT_CUTOUT_LEN] 205 start = index-text_cutout_len 206 end = index+text_cutout_len 207 txt = content[start:end] 212 208 213 209 txt = escape(txt)
