Skip to content

Commit

Permalink
Merge pull request #338 from pratikb64/search-fix
Browse files Browse the repository at this point in the history
fix: fix search
  • Loading branch information
pratikb64 authored Feb 12, 2025
2 parents 8db453b + c2d4b8a commit 156f2c1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion wiki/public/scss/general.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
b.match {
background-color: transparent;
color: var(--primary);
font-weight: 500;
font-weight: 800;
padding: 0; // rm website css
}

Expand Down
22 changes: 20 additions & 2 deletions wiki/wiki/doctype/wiki_page/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,17 @@ def search(query, path, space):

# if redisearch enabled use redisearch
r = frappe.cache()
query = Query(query).paging(0, 20).highlight(tags=['<b class="match">', "</b>"])

# Build fuzzy search terms with wildcard matching
search_terms = []
for term in query.split():
search_terms.append(f"*{term}*")
fuzzy_query = " ".join(search_terms)

query = Query(fuzzy_query).paging(0, 20).highlight(tags=['<b class="match">', "</b>"])

# Create search query with pagination and highlighting
query = Query(fuzzy_query).paging(0, 20).highlight(tags=['<b class="match">', "</b>"])

try:
result = r.ft(space).search(query)
Expand Down Expand Up @@ -105,7 +115,15 @@ def rebuild_index():
)
r.ft(space).create_index(schema, definition=index_def)

records_to_index = [d for d in wiki_pages if space in d.get("route")]
records_to_index = [
d
for d in wiki_pages
if (space + "/" == d.get("route"))
or (
d.get("route").startswith(space + "/")
and not d.get("route").replace(space + "/", "").startswith("v")
)
]
create_index_for_records(records_to_index, space)
except ResponseError as e:
print(e)
Expand Down

0 comments on commit 156f2c1

Please sign in to comment.