--- /dev/null
+# -*- encoding: utf-8 -*-
+from django import forms
+
+class RechercheAvancee (forms.Form):
+ creator = forms.CharField (max_length=60, required=False, \
+ label = "Auteur ou contributeur") # + contributor
+ title = forms.CharField (max_length=100, required=False, \
+ label = "Titre") # + alt_title
+ description = forms.CharField (max_length=100, required=False, \
+ label = "Description ou résumé") # + abstract
+ subject = forms.CharField (max_length=100, required=False, label = "Sujet")
+ operator = forms.ChoiceField (choices = (('or', 'ou'), ('and', 'et')), label = "Operateur")
+ type = forms.CharField (initial='avancee', required=False, widget=forms.HiddenInput)
+
+
maxlen = 200
content = description
if len (description) > maxlen:
+ start = 0
loc = regexp.search (description)
if loc:
- f = loc.start () - (maxlen / 2)
- t = 0
- if f < 0:
- t = -f
- f = 0
- t += loc.start () + (maxlen / 2)
+ start = loc.start ()
+
+ f = start - (maxlen / 2)
+ t = 0
+ if f < 0:
+ t = -f
+ f = 0
+ t += start + (maxlen / 2)
+ if f > 0:
+ while description[f] != '.' and f > 0:
+ f -= 1
if f > 0:
- while description[f] != '.' and f > 0:
- f -= 1
- if f > 0:
- f += 1
- if t < len (description):
- while t < len (description) and description[t] != '.':
- t += 1
+ f += 1
+ if t < len (description):
+ while t < len (description) and description[t] != '.':
t += 1
- content = description[f:t]
- if f > 0:
- content = "(...) " + content
- if t < (len (description) - 1):
- content = content + " (...)"
+ t += 1
+ content = description[f:t]
+ if f > 0:
+ content = "(...) " + content
+ if t < (len (description) - 1):
+ content = content + " (...)"
content = regexp.sub (r'<b>\1</b>', content)
return content
f = page * configuration['resultats_par_page']
t = f + 8
s = SEP ()
- matches = s.search ({'q': q.encode ('utf-8')})
+ matches = s.search (q)
data['last_page'] = math.ceil (float(len (matches)) / \
float(configuration['resultats_par_page'])) - 1
set = s.get (matches[f:t])
- print set
regexp = re.compile (r'(%s)' % q, re.IGNORECASE)
for r in set:
uri = r.get ("source", "")
google_search (page, q, rc)
elif engin == 'sep':
+ sep_search (page, {'q': q.encode ('utf-8')}, rc)
+
+ elif engin == 'avancee':
sep_search (page, q, rc)
return rc
from savoirs import configuration
from recherche import cherche, google_search
from auf_savoirs_en_partage_backend.sep.io import SEP
+from forms import RechercheAvancee
def index (request):
delta = datetime.timedelta (days = 90)
type = request.GET.get("type", "")
page = int(request.GET.get("page", 0))
- ##TEMP
r = {'results': [], 'last_page': 0, 'more_link': ''}
q = request.GET.get("google-q", "")
+ f = RechercheAvancee ()
if type == 'google':
r = cherche (page, q, type)
+ q = {'q': q}
+ elif type == 'avancee':
+ f = RechercheAvancee (request.GET)
+ if f.is_valid():
+ q = {}
+ for k in ['creator', 'title', 'description', 'subject']:
+ tmp = f.cleaned_data[k].strip()
+ if len (tmp) > 0:
+ q[k] = tmp
+ q['operator'] = '|'
+ if f.cleaned_data['operator'] == 'and':
+ q['operator'] = "&"
+
+ r = cherche (page, q, type)
return render_to_response ("savoirs/avancee.html", \
Context ({'type': type,
'page': page,
'data': r,
+ 'form': f,
'q': q}),
context_instance = RequestContext(request))
div.boite-recherche { display: none !important; }
div#contenu { margin-top: 20px !important; }
div#results { margin-top: 15px; }
+ div.tabber { display: none; }
+ th { font-weight: normal; padding-right: 10px;}
+ input[type=text] { width: 250px; }
</style>
<script>
function setup () {
<div id="tabs" class="tabber">
<div id="tabs-1" class="tabbertab">
<h2>Recherche détaillée</h2>
- <p>Proin elit arcu, rutrum commodo, vehicula tempus, commodo a, risus. Curabitur nec arcu. Donec sollicitudin mi sit amet mauris. Nam elementum quam ullamcorper ante. Etiam aliquet massa et lorem. Mauris dapibus lacus auctor risus. Aenean tempor ullamcorper leo. Vivamus sed magna quis ligula eleifend adipiscing. Duis orci. Aliquam sodales tortor vitae ipsum. Aliquam nulla. Duis aliquam molestie erat. Ut et mauris vel pede varius sollicitudin. Sed ut dolor nec orci tincidunt interdum. Phasellus ipsum. Nunc tristique tempus lectus.</p>
+ <form method="get">
+ <table>
+ {{ form }}
+ <tr>
+ <th></th>
+ <td><input type="submit" name="" value="Chercher" /></td>
+ </tr>
+ </table>
+ </form>
</div>
<div id="tabs-2" class="tabbertab">
<h2>Recherche google</h2>
<form method="get">
<input type="hidden" name="type" value="google" />
- <p style="margin-top: 10px;"><input type="text" name="google-q" value="{{ q|default:""}}" /><input type="submit" name="" value="Chercher" /></p>
+ <p style="margin-top: 10px;"><input type="text" name="google-q" value="{{ q.q|default:""}}" /><input type="submit" name="" value="Chercher" /></p>
</form>
</div>
</div>
<div id="results">
- <h4>Résultats de recherche pour « {{ q }} » :</h4>
+ <h4>Résultats de recherche:</h4>
<div class="zone-texte">
{% for r in data.results %}