Commits

ghorvath committed 88a17e6

BUG:no search result with empty search string. hacky workaround

Comments (0)

Files changed (3)

freieit/forms/search.py

 from haystack.forms import SearchForm
 from django import forms
 import random
+from freieit import models
+from haystack.models import SearchResult
 
 class ExpertSearchForm(SearchForm):
     q = forms.CharField(required=False,
             errors_on_separate_row = True)
 
     def no_query_found(self):
-        all_ = list(self.searchqueryset.all())        
+        # we do not use searchqueryset here because with ngramfields
+        # all does not return any object
+        # see https://groups.google.com/forum/?fromgroups#!topic/django-haystack/q1n6w6S5PJQ
+        
+        # this a quick hack: fake a searchresult list
+        # Performance? (Double database access, sort as list in memory)
+        # Since we have to switch the search backend anyway if the site grows
+        # this should work as quick workaround
+        # (premature optimization ist the root of all evil)
+        
         random.seed(self.seed)
-        all_.sort(key=lambda o:random.random())
+        def make_result(expert):
+            return SearchResult(app_label="freieit",
+                                pk=expert.id,
+                                model_name="expertprofile",
+                                score=random.random())
+        all_ = map(make_result,
+                   models.ExpertProfile.objects.filter(available=True))
+        all_.sort(key=lambda o:o.score)
         return all_

freieit/search_indexes.py

 from freieit.models import ExpertProfile
 
 class ExpertProfileIndex(indexes.SearchIndex):
+    #text = indexes.CharField(document=True, use_template=True)
     text = indexes.EdgeNgramField(document=True, use_template=True)
     #name = indexes.CharField(model_attr='name')
     #location = indexes.CharField(model_attr='location')

freieit/static/freie-it.css

-body {
-	padding:40px 50px 30px 50px;
-	background-color:#fff;
-	font-family:verdana,arial,sans;
-	font-size:.9em;
-	line-height:1.4em;
-}
-article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section { 
-    display:block;
-}
-.logo {
-	float:left;
-	margin:-10px 0em 0em -10px;
-}
-h1 {
-	margin:0em 0em 50px 200px;
-	padding-top:5px;
-	font-family:courier,monospace;
-	font-size:1em;
-	font-weight:normal;
-	font-style:italic;
-	line-height:1.4em;
-}
-h2 {
-	margin:0em;
-	padding:0em;
-}
-header > form {
-	float:right;
-	margin-top:-1.8em;
-}
-header > form > input {
-	background-color:#e2ebf7;
-	padding:.2em .5em;
-	border:none;
-}
-header > form > input[type=text] {
-	width:23em;
-	color:#525bf7;
-	font-weight:xx-small;
-}
-header > form > input[type=submit] {
-	color:#fff;
-	background-color:#c2cbf7;
-	font-weight:bold;
-}
-section > header > h2 {
-	margin-right:18em;
-}
-section > div > div:first-child {
-	float:left;
-	font-size:.8em;
-}
-section > div > div:first-child img {
-	width:100px;
-}
-section > div > div > table {
-	margin:0em;
-	padding:0em;
-	width:100px;
-}
-section > div > div th {
-	text-align:left;
-	font-weight:normal;
-	padding:0em;
-}
-section > div > div td {
-	text-align:right;
-	padding:0em;
-}
-section > div {
-	margin-top:1em;
-	padding:30px 30px 15px 30px;
-	min-height:200px;
-	background-color:#e2ebf7;
-	border-radius:10px;
-}
-section > div > header, section > div > dl {
-	margin-left:120px;
-}
-section > div > dl > dd {
-	margin:0em 0em .5em 100px;
-}
-section > nav {
-	margin-top:.8em;
-	font-size:1.6em;
-	font-weight:bold;
-}
-right {	
-    text-align:right;
-}
-left {	
-    text-align:left;
-}
-a {
-	color:#00709f;
-	font-style:italic;
-	text-decoration:none;
-}
-a:hover, a:focus {
-	text-decoration:underline;
-}
-li {
-	padding:.5em 0em;
-}
-dt {
-	float:left;
-}
-table {
-	border-collapse:collapse;
-}
-q {
-	color:#555;
-	font-style:italic;
-}
-q:before {
-	content:"„";
-}
-q:after {
-	content:"”";
-}
-footer {
-	font-size:x-small;
-}
-footer > div {
-	clear:both;
-	margin-top:3em;
-	padding:20px;
-	color:#fff;
-	background-color:#00709f;
-	background-image:url(fit.png);
-	background-position:20px 20px;
-	background-repeat:no-repeat;
-	border-radius:10px;
-	font-style:italic;
-	font-size:x-small;
-}
-footer ul {
-	margin:0em 60px 0em 80px;
-	list-style-type:none;
-}
-footer ul:first-child {
-	float:left;
-}
-footer > div a {
-	color:#fff;
-	font-style:normal;
-}
-footer p {
-	margin:0em 10px 0em 10px;
-	padding:0em;
-	color:#777;
-	text-align:right;
-	font-size:xx-small;
-}
-footer #dat {
-	float:left;
-	text-align:left;
-}
-footer a {
-	color:#777;
-}
-
-
-/*******************************************************************/
-/* map styling                                                     */
-/*******************************************************************/
-
-.olControlAttribution {
-	top: 185px;
-	right: 2px;
-	border-radius: 3px 3px 3px 3px;
-	background-color: #eee;
-	font-size: smaller;
-	opacity: 0.75;
-}
-
-#the_expert_map {
-	width: 490px;
-	height: 200px;
-}
-
-.the_expert_map_super_div {
-	height: 220px;
-}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.