Peter Justin 8 лет назад
Родитель
Сommit
0c62704e73
3 измененных файлов с 32 добавлено и 6 удалено
  1. 6 1
      flaskbb/app.py
  2. 5 5
      flaskbb/forum/forms.py
  3. 21 0
      flaskbb/utils/search.py

+ 6 - 1
flaskbb/app.py

@@ -42,6 +42,9 @@ from flaskbb.utils.requirements import (IsAdmin, IsAtleastModerator,
                                         TplCanModerate, TplCanDeletePost,
                                         TplCanDeleteTopic, TplCanEditPost,
                                         TplCanPostTopic, TplCanPostReply)
+# whooshees
+from flaskbb.utils.search import (PostWhoosheer, TopicWhoosheer,
+                                  ForumWhoosheer, UserWhoosheer)
 # app specific configurations
 from flaskbb.utils.settings import flaskbb_config
 
@@ -137,8 +140,10 @@ def configure_extensions(app):
 
     # Flask-Whooshee
     whooshee.init_app(app)
-    from flaskbb.utils.search import PostWhoosheer
     whooshee.register_whoosheer(PostWhoosheer)
+    whooshee.register_whoosheer(TopicWhoosheer)
+    whooshee.register_whoosheer(ForumWhoosheer)
+    whooshee.register_whoosheer(UserWhoosheer)
 
     # Flask-Login
     login_manager.login_view = app.config["LOGIN_VIEW"]

+ 5 - 5
flaskbb/forum/forms.py

@@ -90,7 +90,7 @@ class UserSearchForm(Form):
 
     def get_results(self):
         query = self.search_query.data
-        return User.query.whoosh_search(query)
+        return User.query.whooshee_search(query)
 
 
 class SearchPageForm(Form):
@@ -107,10 +107,10 @@ class SearchPageForm(Form):
         # Because the DB is not yet initialized when this form is loaded,
         # the query objects cannot be instantiated in the class itself
         search_actions = {
-            'post': Post.query.whoosh_search,
-            'topic': Topic.query.whoosh_search,
-            'forum': Forum.query.whoosh_search,
-            'user': User.query.whoosh_search
+            'post': Post.query.whooshee_search,
+            'topic': Topic.query.whooshee_search,
+            'forum': Forum.query.whooshee_search,
+            'user': User.query.whooshee_search
         }
 
         query = self.search_query.data

+ 21 - 0
flaskbb/utils/search.py

@@ -54,18 +54,27 @@ class TopicWhoosheer(AbstractWhoosheer):
 
     schema = whoosh.fields.Schema(
         topic_id=whoosh.fields.NUMERIC(stored=True, unique=True),
+        title=whoosh.fields.TEXT(),
+        username=whoosh.fields.TEXT(),
+        content=whoosh.fields.TEXT()
     )
 
     @classmethod
     def update_topic(cls, writer, topic):
         writer.update_document(
             topic_id=topic.id,
+            title=topic.title,
+            username=topic.username,
+            content=topic.first_post.content
         )
 
     @classmethod
     def insert_topic(cls, writer, topic):
         writer.add_document(
             topic_id=topic.id,
+            title=topic.title,
+            username=topic.username,
+            content=topic.first_post.content
         )
 
     @classmethod
@@ -78,18 +87,24 @@ class ForumWhoosheer(AbstractWhoosheer):
 
     schema = whoosh.fields.Schema(
         forum_id=whoosh.fields.NUMERIC(stored=True, unique=True),
+        title=whoosh.fields.TEXT(),
+        description=whoosh.fields.TEXT()
     )
 
     @classmethod
     def update_forum(cls, writer, forum):
         writer.update_document(
             forum_id=forum.id,
+            title=forum.title,
+            description=forum.description
         )
 
     @classmethod
     def insert_forum(cls, writer, forum):
         writer.add_document(
             forum_id=forum.id,
+            title=forum.title,
+            description=forum.description
         )
 
     @classmethod
@@ -102,18 +117,24 @@ class UserWhoosheer(AbstractWhoosheer):
 
     schema = whoosh.fields.Schema(
         user_id=whoosh.fields.NUMERIC(stored=True, unique=True),
+        username=whoosh.fields.TEXT(),
+        email=whoosh.fields.TEXT()
     )
 
     @classmethod
     def update_user(cls, writer, user):
         writer.update_document(
             user_id=user.id,
+            username=user.username,
+            email=user.email
         )
 
     @classmethod
     def insert_user(cls, writer, user):
         writer.add_document(
             user_id=user.id,
+            username=user.username,
+            email=user.email
         )
 
     @classmethod