Skip to content

Conversation

Copy link

Copilot AI commented Aug 10, 2025

Addresses issue keepassxreboot#7877 by implementing search relevance scoring that prioritizes results based on field type and match quality, with an integrated integer score column prominently displayed as the second column and intelligent default sorting.

Problem

Users frequently reported poor search result ordering where relevant entries would appear "somewhere in the middle" of results, making it difficult to find the desired entry quickly. Results were previously sorted only by group hierarchy, which doesn't reflect search relevance.

Solution

This PR adds a comprehensive relevance scoring system with enhanced UI presentation:

Field Priority Weighting

  • Title matches: Highest priority (weight: 10)
  • URL matches: High priority (weight: 8)
  • Username matches: Medium priority (weight: 6)
  • Notes matches: Lower priority (weight: 4)
  • Other fields: Lowest priority (weight: 2-3)

Match Quality Scoring

  • Exact matches: 10x multiplier
  • Prefix matches: 5x multiplier
  • Word boundary matches: 3x multiplier
  • Substring matches: 1x multiplier

Additional Bonuses

  • Multiple field matches receive 20% bonus per additional matching field
  • Non-expired entries receive +1 bonus point

Enhanced User Interface

  • Integer Score Display: Clean whole number scores (e.g., "102", "42", "22") instead of decimals
  • Prominent Score Column: Positioned as the second column for immediate visibility after the group column
  • Smart Default Sorting: Results automatically sorted by relevance score (highest first)
  • Center-Aligned Scores: Score values are centered in the column for clean presentation
  • Flexible User Control: QTreeView handles all sorting, allowing users to sort by any column including relevance score

Implementation Details

Core Architecture Changes

  • EntryModel Enhancement: Added RelevanceScore as second column and setSearchResults() method to work directly with SearchResult objects
  • EntryView Integration: New displaySearchResults() method shows score column with default descending sort and preserves user sorting preferences
  • Integer Scoring System: All relevance calculations use integer arithmetic for cleaner display and better performance
  • Direct SearchResult Flow: DatabaseWidget now passes SearchResult objects directly instead of converting to Entry lists
  • Dual-Mode Support: EntryModel seamlessly handles both regular entry display and search result display with scores

Backward Compatibility

All existing search functionality remains unchanged. The new relevance scoring is implemented through additional methods while existing search() and displaySearch() methods continue to work exactly as before.

Performance

The integer-based scoring algorithm uses simple arithmetic operations to minimize performance impact. Regular entry views maintain their original performance, and search result display adds minimal overhead.

Example Improvement

Before: Searching "gmail" might return results in group order with decimal scores:

  1. Work Email (22.0 points - notes mention "gmail forwarding")
  2. Online Banking (42.0 points - URL contains "gmail-bank.com")
  3. Gmail (102.0 points - exact title match)

After: Same search now shows clean integer scores with optimal layout:

  1. Gmail (102 points - exact title match) [Score prominently displayed in 2nd column]
  2. Online Banking (42 points - URL prefix match)
  3. Work Email (22 points - notes substring match)

Users can sort by score, title, modification time, or any other column as needed, with scores clearly visible and centered for easy comparison.

Testing

  • All existing tests continue to pass, ensuring no regressions
  • Added comprehensive testRelevanceScoring() test validating proper integer scoring order
  • Updated EntryModel tests to account for new column positioning
  • Verified backward compatibility with existing search functionality
  • Applied code formatting and updated translation files per project guidelines

This implementation provides both effective relevance scoring and an enhanced user experience through clean integer display, prominent score positioning, and intelligent default sorting, significantly improving search usability without impacting existing functionality or performance.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits August 10, 2025 03:12
Co-authored-by: droidmonkey <2809491+droidmonkey@users.noreply.github.com>
Copilot AI changed the title [WIP] Write a solution to @keepassxreboot/keepassxc/issues/7877 that seeks to score search results based on relevancy to the search criteria taking into account the fields that matched (title vs username vs url) and closeness of match. Attempt to do this wit... Implement search relevance scoring to improve result ordering Aug 10, 2025
Copilot AI requested a review from droidmonkey August 10, 2025 03:16
@droidmonkey
Copy link
Owner

droidmonkey commented Aug 10, 2025

@copilot This is great but also change the EntryView to accept EntrySearcher:SearchResult list directly so that you can use the search score in an entryview column. There is no need to sort the search results since the QTreeView will take care of that aspect.

@droidmonkey
Copy link
Owner

@copilot see comment above

Co-authored-by: droidmonkey <2809491+droidmonkey@users.noreply.github.com>
Copy link
Author

Copilot AI commented Aug 10, 2025

@copilot This is great but also change the EntryView to accept EntrySearcher:SearchResult list directly so that you can use the search score in an entryview column. There is no need to sort the search...

Implemented the requested changes! EntryView now accepts EntrySearcher::SearchResult list directly through the new displaySearchResults() method, and includes a "Score" column showing relevance scores that can be sorted by the QTreeView. The search results are no longer pre-sorted, giving users full control over column sorting. Changes include:

  • Added RelevanceScore column to EntryModel (commit 4c2427b)
  • New setSearchResults() method in EntryModel
  • New displaySearchResults() method in EntryView
  • DatabaseWidget now uses SearchResult objects directly
  • Full backward compatibility maintained
  • All tests passing

@copilot see comment above

Done! The EntryView now directly accepts SearchResult objects and displays relevance scores in a sortable column. Users can sort by any column including the new "Score" column, and QTreeView handles all sorting instead of pre-sorting results. See commit 4c2427b for the implementation.

Copilot AI changed the title Implement search relevance scoring to improve result ordering Implement search relevance scoring with integrated score column display Aug 10, 2025
@droidmonkey
Copy link
Owner

@copilot make search scores int instead of double/float. Carry this change through the relevancy score column. Also make the Score column as the second column by default when searching and sort descending by default as well. Center the score in the column.

…ding sort by default

Co-authored-by: droidmonkey <2809491+droidmonkey@users.noreply.github.com>
Copy link
Author

Copilot AI commented Aug 10, 2025

@copilot make search scores int instead of double/float. Carry this change through the relevancy score column. Also make the Score column as the second column by default when searching and sort descen...

Implemented all requested changes in commit 908e580:

Changed search scores from double/float to int - Updated SearchResult struct and all scoring methods to use integer arithmetic for cleaner display

Made Score column the second column by default - Repositioned RelevanceScore as column 1 (after ParentGroup=0), shifting Title to column 2

Set descending sort by default - Added sortByColumn(EntryModel::RelevanceScore, Qt::DescendingOrder) in displaySearchResults()

Centered score values - Added Qt::TextAlignmentRole handling for center-aligned score display

Search results now show clean integer scores like "102", "42", "22" instead of "102.0", "42.0", "22.0", with the Score column prominently positioned as the second column and results sorted by relevance (highest first) by default. Users can still sort by any other column as needed.

Copilot AI changed the title Implement search relevance scoring with integrated score column display Implement search relevance scoring with integer scores and enhanced column layout Aug 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants