knowledgebase: include the topic (application name) in list search

The KB list search matched only shortdescription + keywords, so searching a
topic (e.g. "Spotfire", the Application name) surfaced just the one article
whose title/keywords contained the word, not the others tied to it by topic.
Match the topic too via an appid IN (apps named like the term) subquery - used
instead of a join so it does not collide with the sort=topic join, and articles
with no app still match on title/keywords.
This commit is contained in:
cproudlock
2026-07-29 10:06:18 -04:00
parent c5ee164565
commit 8dce622392
2 changed files with 43 additions and 3 deletions

View File

@@ -29,12 +29,19 @@ def list_articles():
query = KnowledgeBase.query.filter_by(isactive=True)
# Search
# Search: title, keywords, and the topic (its Application's name). The topic
# is matched via an appid subquery instead of a join so it does not collide
# with the sort=='topic' join below; articles with no app just miss that
# clause and still match on title/keywords.
if search := request.args.get('search'):
like = f'%{search}%'
topic_appids = db.session.query(Application.appid).filter(
Application.appname.ilike(like))
query = query.filter(
db.or_(
KnowledgeBase.shortdescription.ilike(f'%{search}%'),
KnowledgeBase.keywords.ilike(f'%{search}%')
KnowledgeBase.shortdescription.ilike(like),
KnowledgeBase.keywords.ilike(like),
KnowledgeBase.appid.in_(topic_appids)
)
)