Skip to content

Allow blob num_context_lines to be specified

What does this MR do and why?

Adds an optional param num_context_lines to allow users to specify how many lines of code their blob search results should show before and after the matching line, defaulting to 2.

This param is available for web and API.

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Web API
default Screenshot_2024-06-25_at_09.00.31 Screenshot_2024-06-25_at_09.00.40
num_context_lines=10 Screenshot_2024-06-25_at_09.02.56 Screenshot_2024-06-25_at_09.03.36

How to set up and validate locally

Verify that the number of code lines before and after a matching search term changes when specifying num_context_lines:

  1. Run a blob search web request without num_context_lines: http://127.0.0.1:3000/search?scope=blobs&search=test&search_type=advanced
  2. Run a blob search web request with num_context_lines=10: http://127.0.0.1:3000/search?scope=blobs&search=test&search_type=advanced&num_context_lines=10
  3. Run a blob search API request without num_context_lines: http://127.0.0.1:3000/api/v4/search?scope=blobs&search=test&search_type=advanced
  4. Run a blob search API request with num_context_lines=10: http://127.0.0.1:3000/api/v4/search?scope=blobs&search=test&search_type=advanced&num_context_lines=10

Related to #468311 (closed)

Edited by Madelein van Niekerk

Merge request reports

Loading