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

change lunr config #168

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

koilebeit
Copy link

@koilebeit koilebeit commented Oct 24, 2024

Pull request

Proposed changes

would solve #157. unless we replace the search on the browse page with the lunr search (see #167)

Types of changes

  • New feature (non-breaking change which adds functionality).
  • Enhancement (non-breaking change which enhances functionality)
  • Bug Fix (non-breaking change which fixes an issue).
  • Breaking change (fix or feature that would cause existing functionality to change).

Checklist

  • I have read the CONTRIBUTING document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

Summary by CodeRabbit

  • New Features

    • Enhanced search functionality with support for trailing wildcard searches.
    • Improved indexing process for better handling of multiple values.
  • Bug Fixes

    • Disabled the display of child objects in search results.
  • Documentation

    • Updated configuration settings for search behavior.

Copy link

changeset-bot bot commented Oct 24, 2024

⚠️ No Changeset found

Latest commit: 26bd503

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

coderabbitai bot commented Oct 24, 2024

Walkthrough

The pull request introduces modifications to two files: _data/theme.yml and _includes/js/lunr-js.html. In _data/theme.yml, the search-child-objects setting has been changed from true to false, which disables the display of child objects in search results. In _includes/js/lunr-js.html, the search functionality has been enhanced by removing lunr.trimmer and lunr.stemmer, updating the indexing process to handle semicolon-separated values, and implementing a new query method that allows for trailing wildcard searches.

Changes

File Change Summary
_data/theme.yml Updated search-child-objects from true to false, disabling child objects in search results.
_includes/js/lunr-js.html Removed lunr.trimmer, updated indexing for semicolon-separated values, and implemented a new query method for trailing wildcard searches.

Poem

🐰 In the garden where we play,
Child objects now must stay away.
With a search that hops and bounds,
Wildcards lead to treasure found!
So let’s rejoice, both near and far,
For changes made, we raise a carrot star! 🌟🥕


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 58ce62c and 26bd503.

📒 Files selected for processing (1)
  • _includes/js/lunr-js.html (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • _includes/js/lunr-js.html

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (1)
_includes/js/lunr-js.html (1)

24-28: Ensure fieldValue is a string before processing

To prevent potential runtime errors, verify that fieldValue is a string before calling split() on it. This ensures that only valid strings are processed, avoiding exceptions if fieldValue is undefined or not a string.

Apply this diff:

      var fieldValue = store[item][{{ f.field | jsonify }}];
      if (fieldValue) {
+       if (typeof fieldValue === 'string') {
          // Split semicolon-separated values and join them with spaces
          indexedData[{{ f.field | jsonify }}] = fieldValue.split(";").join(" ");
+       }
+     } else {
+       // Handle cases where fieldValue is not a string
+     }
      }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between ca81e24 and 58ce62c.

📒 Files selected for processing (2)
  • _data/theme.yml (1 hunks)
  • _includes/js/lunr-js.html (1 hunks)
🔇 Additional comments (3)
_data/theme.yml (2)

86-86: LGTM! Configuration change aligns with other child object settings.

The change to disable child objects in search results is consistent with the browse-child-objects: false setting, maintaining a coherent user experience across browse and search functionalities.


86-86: Verify the search behavior with this configuration.

Since this change affects search results visibility, let's verify the implementation:

✅ Verification successful

Let me try a different approach to verify the search implementation.

This will help us understand where the search functionality is implemented and how configuration values are handled.


Let me check the search implementation files more specifically.

This will help us understand how the search functionality is implemented and whether it respects the search-child-objects configuration.


The search-child-objects configuration is properly implemented and functional

The implementation in assets/js/lunr-store.js clearly shows that the configuration is respected:

  • When search-child-objects is true, all items are included in the search index:
{% if site.data.theme.search-child-objects == true %}
{%- assign items = site.data[site.metadata] | where_exp: 'item','item.objectid' -%}
  • When false, only parent objects (items without a parent ID) are included:
{% else %}
{%- assign items = site.data[site.metadata] | where_exp: 'item','item.objectid and item.parentid == nil' -%}

Setting it to false will exclude child objects from search results, making the search focus only on parent-level items.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the search implementation respects the search-child-objects setting

# Test 1: Check if the Lunr search implementation references this config
rg -l "search-child-objects" _includes/

# Test 2: Look for any conditional logic handling child objects in search
ast-grep --pattern 'if ($CONDITION) {
  $$$
  search
  $$$
}'

Length of output: 103


Script:

#!/bin/bash
# Let's check for search-related files and their implementation

# Find search-related files
fd "search" --type f

# Look for search implementation in JavaScript files
rg -l "search" --type js

# Check for Lunr.js integration
rg -l "lunr" --type js

# Look for any search configuration handling
rg -A 5 "search.*config" --type js

Length of output: 11337


Script:

#!/bin/bash
# Check the search implementation files for child objects handling

# Check the search layout implementation
cat _layouts/search.html

# Check the Lunr search navigation implementation
cat _includes/nav-search-lunr.html

# Look for any JavaScript that might handle the search configuration
cat assets/js/lunr-store.js

Length of output: 7074

_includes/js/lunr-js.html (1)

40-40: Verify case consistency between indexing and querying

The query is converted to lowercase, but ensure that the indexed data is also in lowercase to maintain consistency and improve search accuracy. If the indexed data maintains original casing, consider removing .toLowerCase() or adjusting the indexing process accordingly.

Would you like to confirm that the indexed data and search queries are case-consistent?

Comment on lines +45 to +49
var result = idx.query(function (q) {
query.split(lunr.tokenizer.separator).forEach(function (term) {
q.term(term, { wildcard: lunr.Query.wildcard.TRAILING });
});
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Handle empty or whitespace query terms to prevent errors

When processing the search query, empty strings or terms with only whitespace can cause issues. It's advisable to trim each term and check for emptiness before adding it to the query.

Apply this diff to filter out empty terms:

      query.split(lunr.tokenizer.separator).forEach(function (term) {
+       term = term.trim();
+       if (term) {
          q.term(term, { wildcard: lunr.Query.wildcard.TRAILING });
+       }
      });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
var result = idx.query(function (q) {
query.split(lunr.tokenizer.separator).forEach(function (term) {
q.term(term, { wildcard: lunr.Query.wildcard.TRAILING });
});
});
var result = idx.query(function (q) {
query.split(lunr.tokenizer.separator).forEach(function (term) {
term = term.trim();
if (term) {
q.term(term, { wildcard: lunr.Query.wildcard.TRAILING });
}
});
});

Comment on lines +17 to +18
this.pipeline.remove(lunr.trimmer)
this.pipeline.remove(lunr.stemmer);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Reconsider removing lunr.trimmer and lunr.stemmer for optimal search performance

By removing lunr.trimmer and lunr.stemmer from the pipeline, you may reduce the effectiveness of search queries. The lunr.trimmer removes unnecessary characters from tokens, and lunr.stemmer reduces words to their root form, allowing for better matching of different word variations. Consider retaining these processes unless there's a specific reason for their removal.

Apply this diff to keep them in the pipeline:

-    this.pipeline.remove(lunr.trimmer)
-    this.pipeline.remove(lunr.stemmer);

Committable suggestion was skipped due to low confidence.

Copy link
Member

@maehr maehr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose we put this on hold until we decided on a solution for browse.html. My research points to a faceted search solution based on lunrjs. I will probably be able to present something mid Nov.

@koilebeit koilebeit marked this pull request as draft October 31, 2024 14:06
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