Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added html striped content for better search #635

Merged
merged 2 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions raven/api/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def get_search_result(filter_type, doctype, search_text=None, from_user=None, in
}

query = frappe.qb.from_(doctype).select(
doctype.name, doctype.file, doctype.owner, doctype.creation, doctype.message_type, doctype.channel_id, doctype.text).join(channel, JoinType.left).on(doctype.channel_id == channel.name).join(channel_member, JoinType.left).on(
doctype.name, doctype.file, doctype.owner, doctype.creation, doctype.message_type, doctype.channel_id, doctype.text, doctype.content).join(channel, JoinType.left).on(doctype.channel_id == channel.name).join(channel_member, JoinType.left).on(
channel_member.channel_id == doctype.channel_id).where((channel.type != 'Private') | (channel_member.user_id == frappe.session.user))

if filter_type == 'File':
Expand All @@ -40,7 +40,7 @@ def get_search_result(filter_type, doctype, search_text=None, from_user=None, in
query = query.where(doctype.file.like(
"/private/files/%" + search_text + "%"))
elif filter_type == 'Message':
query = query.where(doctype.text.like("%" + search_text + "%"))
query = query.where(doctype.content.like("%" + search_text + "%"))
elif filter_type == 'Channel':
query = query.where(
doctype.channel_name.like("%" + search_text + "%"))
Expand Down
1 change: 1 addition & 0 deletions raven/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
[post_model_sync]
raven.patches.v1_2.create_raven_users
raven.patches.v1_3.create_raven_message_indexes #23
raven.patches.v1_3.update_all_messages_to_include_message_content #1
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import frappe
from frappe.utils import strip_html_tags


def execute():
update_old_messages_to_include_message_content()


def update_old_messages_to_include_message_content():
'''
Update all old messages to include message content
Message content is required for search
It is basically the message's text content but without any html tags
(this is done to improve search results)
This is a one-time operation, not required for new messages
'''
messages = frappe.db.get_all('Raven Message', fields=[
'name', 'text', 'message_type'])
for message in messages:
if message.text:
cleaned_text = strip_html_tags(message.text).replace(
'\ufeff', '').replace(' ', ' ')
content = cleaned_text
frappe.db.set_value(
'Raven Message', message.name, 'content', content)
frappe.db.commit()
11 changes: 9 additions & 2 deletions raven/raven_messaging/doctype/raven_message/raven_message.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"is_reply",
"linked_message",
"link_doctype",
"link_document"
"link_document",
"content"
],
"fields": [
{
Expand Down Expand Up @@ -109,11 +110,17 @@
"fieldtype": "Dynamic Link",
"label": "Link Document",
"options": "link_doctype"
},
{
"fieldname": "content",
"fieldtype": "Long Text",
"label": "Content",
"read_only": 1
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2023-12-22 18:25:02.237368",
"modified": "2024-01-19 14:56:44.534433",
"modified_by": "Administrator",
"module": "Raven Messaging",
"name": "Raven Message",
Expand Down
12 changes: 12 additions & 0 deletions raven/raven_messaging/doctype/raven_message/raven_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import frappe
from frappe import _
from frappe.model.document import Document
from frappe.utils import strip_html_tags
import json
from raven.api.raven_message import track_visit


class RavenMessage(Document):
# begin: auto-generated types
# This code is auto-generated. Do not modify anything in this block.
Expand All @@ -16,6 +18,7 @@ class RavenMessage(Document):
from frappe.types import DF

channel_id: DF.Link
content: DF.LongText | None
file: DF.Attach | None
file_thumbnail: DF.Attach | None
image_height: DF.Data | None
Expand Down Expand Up @@ -91,3 +94,12 @@ def on_trash(self):
def before_save(self):
if frappe.db.get_value('Raven Channel', self.channel_id, 'type') != 'Private' or frappe.db.exists("Raven Channel Member", {"channel_id": self.channel_id, "user_id": frappe.session.user}):
track_visit(self.channel_id)


def on_doctype_update():
'''
Add indexes to Raven Message table
'''
# Index the selector (channel or message type) first for faster queries (less rows to sort in the next step)
frappe.db.add_index("Raven Message", ["channel_id", "creation"])
frappe.db.add_index("Raven Message", ["message_type", "creation"])
Loading