aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBobby <[email protected]>2023-04-27 03:18:51 -0400
committerBobby <[email protected]>2023-04-27 03:18:51 -0400
commit72ec724bd66aaab64eb7c618400d1b25078ebd49 (patch)
tree38c4fd1c28327424e2973bccf8b1d7280c5ced65
parent08f57b0f8029ee5f45adba91ceb31e07a7bd65fd (diff)
downloadthatcomputerscientist-72ec724bd66aaab64eb7c618400d1b25078ebd49.tar.xz
thatcomputerscientist-72ec724bd66aaab64eb7c618400d1b25078ebd49.zip
Impl::`Comment` Model in *Search_Index*
-rw-r--r--blog/views.py3
-rw-r--r--templates/blog/search.html3
-rw-r--r--thatcomputerscientist/search_indexes.py18
3 files changed, 22 insertions, 2 deletions
diff --git a/blog/views.py b/blog/views.py
index acab2d74..e12752b5 100644
--- a/blog/views.py
+++ b/blog/views.py
@@ -204,6 +204,7 @@ def search(request):
search_model_map = {
'posts': Post,
'users': User,
+ 'comments': Comment,
}
if query:
@@ -215,6 +216,8 @@ def search(request):
else:
search_results = None
+ print(search_results)
+
return render(request, 'blog/search.html', {'title': f"Search results for '{query}'", 'query': query, 'search_results': search_results, 'search_in': search_in, 'sort_by': sort_by, 'order': order, 'date_range': date_range})
def articles(request, date=None, cg=None):
diff --git a/templates/blog/search.html b/templates/blog/search.html
index 9fde878c..dc92cd15 100644
--- a/templates/blog/search.html
+++ b/templates/blog/search.html
@@ -38,7 +38,8 @@
</td>
<td id="search_results" style="width: 530px; vertical-align: top; padding-left: 20px;">
<h2>Search Results</h2>
- <p>Coming Soon!</p>
+ <p>Sorry, this feature is under construction, and will be available soon.</p>
+ <p>In case, you were curious, your query returned {{ search_results|length }} results.</p>
</td>
</tr>
</table>
diff --git a/thatcomputerscientist/search_indexes.py b/thatcomputerscientist/search_indexes.py
index db8761b5..edfff3a9 100644
--- a/thatcomputerscientist/search_indexes.py
+++ b/thatcomputerscientist/search_indexes.py
@@ -1,5 +1,5 @@
from haystack import indexes
-from blog.models import Post
+from blog.models import Post, Comment
from django.contrib.auth.models import User
class PostIndex(indexes.SearchIndex, indexes.Indexable):
@@ -27,4 +27,20 @@ class UserIndex(indexes.SearchIndex, indexes.Indexable):
def index_queryset(self, using=None):
"""Return all user profiles without filtering."""
+ return self.get_model().objects.all()
+
+class CommentIndex(indexes.SearchIndex, indexes.Indexable):
+ text = indexes.CharField(document=True, use_template=True)
+ post = indexes.CharField(model_attr='post')
+ user = indexes.CharField(model_attr='user')
+ body = indexes.CharField(model_attr='body')
+ created_at = indexes.DateTimeField(model_attr='created_at')
+ edited = indexes.BooleanField(model_attr='edited')
+ edited_at = indexes.DateTimeField(model_attr='edited_at')
+
+ def get_model(self):
+ return Comment
+
+ def index_queryset(self, using=None):
+ """Return all comments without filtering."""
return self.get_model().objects.all() \ No newline at end of file