Browse Source

Merge branch 'featured_result' of https://github.com/pw3t/searx

asciimoo 11 years ago
parent
commit
bfdd6ebb92

+ 2
- 0
searx/engines/mediawiki.py View File

@@ -14,5 +14,7 @@ def request(query, params):
14 14
 def response(resp):
15 15
     search_results = loads(resp.text)
16 16
     res = search_results.get('query', {}).get('search', [])
17
+
17 18
     return [{'url': url + 'wiki/' + quote(result['title'].replace(' ', '_').encode('utf-8')),
18 19
         'title': result['title']} for result in res[:int(number_of_results)]]
20
+

+ 7
- 3
searx/engines/vimeo.py View File

@@ -35,7 +35,11 @@ def response(resp):
35 35
     for result in dom.xpath(results_xpath):
36 36
         url = base_url + result.xpath(url_xpath)[0]
37 37
         title = p.unescape(extract_text(result.xpath(title_xpath)))
38
-        content = '<a href="{0}">  <img src="{2}"/> </a>'.format(url, title, extract_text(result.xpath(content_xpath)[0]))
39
-        results.append({'url': url, 'title': title, 'content': content})
40
-
38
+        thumbnail = extract_text(result.xpath(content_xpath)[0])
39
+        content = '<a href="{0}">  <img src="{2}"/> </a>'.format(url, title, thumbnail)
40
+        results.append({'url': url
41
+                        , 'title': title
42
+                        , 'content': content 
43
+                        , 'template':'videos.html'
44
+                        , 'thumbnail': thumbnail})
41 45
     return results

+ 9
- 2
searx/engines/youtube.py View File

@@ -26,14 +26,21 @@ def response(resp):
26 26
             url = url[:-1]
27 27
         title = result['title']['$t']
28 28
         content = ''
29
+
30
+        thumbnail = ''
29 31
         if len(result['media$group']['media$thumbnail']):
30
-            content += '<a href="{0}" title="{0}" ><img src="{1}" /></a>'.format(url, result['media$group']['media$thumbnail'][0]['url'])
32
+            thumbnail = result['media$group']['media$thumbnail'][0]['url']
33
+            content += '<a href="{0}" title="{0}" ><img src="{1}" /></a>'.format(url, thumbnail)
31 34
         if len(content):
32 35
             content += '<br />' + result['content']['$t']
33 36
         else:
34 37
             content = result['content']['$t']
35 38
 
36
-        results.append({'url': url, 'title': title, 'content': content})
39
+        results.append({'url': url
40
+                        , 'title': title
41
+                        , 'content': content
42
+                        , 'template':'videos.html'
43
+                        , 'thumbnail':thumbnail})
37 44
 
38 45
     return results
39 46
 

+ 1
- 0
searx/static/css/style.css View File

@@ -79,6 +79,7 @@ a { text-decoration: none; color: #1a11be; }
79 79
 a:visited { color: #7b11be; }
80 80
 
81 81
 .result { margin: 19px 0 18px 0; padding: 0; max-width: 55em;  clear: both; }
82
+.result:hover { background: #e8e7e6; }
82 83
 .result_title { margin-bottom: 0; }
83 84
 .result h3 { font-size: 1em; word-wrap:break-word; margin: 5px 0 1px 0; padding: 0 }
84 85
 .result .content { font-size: 0.8em; margin: 0; padding: 0; max-width: 54em; word-wrap:break-word; line-height: 1.24; }

BIN
searx/static/img/icon_github.ico View File


BIN
searx/static/img/icon_soundcloud.ico View File


BIN
searx/static/img/icon_stackoverflow.ico View File


BIN
searx/static/img/icon_twitter.ico View File


BIN
searx/static/img/icon_vimeo.ico View File


BIN
searx/static/img/icon_wikipedia.ico View File


BIN
searx/static/img/icon_youtube.ico View File


+ 10
- 1
searx/templates/result_templates/default.html View File

@@ -1,5 +1,14 @@
1 1
 <div class="result {{ result.class }}">
2
-    <h3 class="result_title"><a href="{{ result.url }}">{{ result.title|safe }}</a></h3>
2
+
3
+  {% if result['favicon'] %}
4
+  <div style="float:left; margin:2px;">
5
+    <img width="18" height="18" src="static/img/icon_{{result['favicon']}}.ico" alt="{{result['favicon']}}.ico" title="{{result['favicon']}}.ico" />
6
+  </div>
7
+  {% endif %}
8
+
9
+  <div>
10
+    <h3 class="result_title"><a href="{{ result.url }}">{{ result.title|safe }}</a></h3></br>
3 11
     <p class="content">{% if result.content %}{{ result.content|safe }}<br />{% endif %}</p>
4 12
     <p class="url">{{ result.pretty_url }}</p>
13
+  </div>
5 14
 </div>

+ 13
- 0
searx/templates/result_templates/videos.html View File

@@ -0,0 +1,13 @@
1
+<div class="result">
2
+  {% if result['favicon'] %}
3
+  <div style="float:left; margin:2px;">
4
+    <img width="18" height="18" src="static/img/icon_{{result['favicon']}}.ico" alt="{{result['favicon']}}.ico" title="{{result['favicon']}}.ico" />
5
+  </div>
6
+  {% endif %}
7
+
8
+    <p>
9
+      <h3 class="result_title"><a href="{{ result.url }}">{{ result.title|safe }}</a></h3>
10
+      <a href="{{ result.url }}"><img width="300" height="170"  src="{{ result.thumbnail }}" title={{ result.title }} alt=" {{ result.title }}"/></a>
11
+      <p class="url">{{ result.url }}</p>
12
+    </p>
13
+</div>

+ 3
- 0
searx/templates/results.html View File

@@ -9,9 +9,12 @@
9 9
     {% if suggestions %}
10 10
     <div id="suggestions"><span>Suggestions: </span>{% for suggestion in suggestions %}<form method="post" action="/"><input type="hidden" name="q" value="{{suggestion}}"><input type="submit" value="{{ suggestion }}" /></form>{% endfor %}</div>
11 11
     {% endif %}
12
+    
13
+
12 14
     <div id ="result_count">
13 15
         Number of results: {{ number_of_results }}
14 16
     </div>
17
+
15 18
     {% for result in results %}
16 19
         {% if result['template'] %}
17 20
             {% include 'result_templates/'+result['template'] %}

+ 7
- 1
searx/webapp.py View File

@@ -120,6 +120,7 @@ def index():
120 120
 
121 121
     results, suggestions = search(query, request, selected_engines)
122 122
 
123
+    featured_results = []
123 124
     for result in results:
124 125
         if request_data.get('format', 'html') == 'html':
125 126
             if 'content' in result:
@@ -134,6 +135,10 @@ def index():
134 135
         else:
135 136
             result['pretty_url'] = result['url']
136 137
 
138
+        for engine in result['engines']:
139
+            if engine in ['wikipedia', 'youtube', 'vimeo', 'soundcloud', 'twitter', 'stackoverflow', 'github']:
140
+                result['favicon'] = engine
141
+
137 142
     if request_data.get('format') == 'json':
138 143
         return Response(json.dumps({'query': query, 'results': results}), mimetype='application/json')
139 144
     elif request_data.get('format') == 'csv':
@@ -162,7 +167,8 @@ def index():
162 167
                  ,results=results
163 168
                  ,q=request_data['q']
164 169
                  ,selected_categories=selected_categories
165
-                 ,number_of_results=len(results)
170
+                 ,number_of_results=len(results)+len(featured_results)
171
+                 ,featured_results=featured_results 
166 172
                  ,suggestions=suggestions
167 173
                  )
168 174