Gradle-mcp gradle_mcp_search_and_indexing_expert
install
source · Clone the upstream repo
git clone https://github.com/rnett/gradle-mcp
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/rnett/gradle-mcp "$T" && mkdir -p ~/.claude/skills && cp -r "$T/.agents/skills/gradle_mcp_search_and_indexing_expert" ~/.claude/skills/rnett-gradle-mcp-gradle-mcp-search-and-indexing-expert && rm -rf "$T"
manifest:
.agents/skills/gradle_mcp_search_and_indexing_expert/SKILL.mdsource content
Skill: Gradle MCP Search and Indexing Expert
This skill provides deep technical guidance on the search and indexing infrastructure of the Gradle MCP project, specifically focusing on Lucene 10+ usage, Tree-sitter extraction, and performance optimizations.
Search Conventions
Lucene Field Management
- Field Constants: For Lucene-based search providers (e.g.,
), field names MUST be extracted to a nestedDeclarationSearch
object. This ensures consistency and prevents typos across indexing and searching logic.Fields - Lucene 10+ API: Use
to retrieve the current document count from anwriter.docStats.numDocs
.IndexWriter - Metadata Caching: Always cache expensive metadata (like document counts) in a lightweight file (e.g.,
) within the index directory. This enables instantaneous preparation phases and provides immediate progress reporting feedback..count
Search Implementation
- Regex Search:
supports full string regex queries on the FQN field when the query is wrapped inDeclarationSearch
(e.g.,/
). This should be preferred for complex, precise symbol discovery./.*MyClass/ - Search Error Handling:
andSourcesService.search
MUST return aIndexService.search
with anSearchResponse
string instead of throwing anerror
when an index is missing. This prevents unexpected crashes in tool handlers and allows for graceful error reporting.IllegalStateException - Targeted Indexing:
(and related methods) require an explicitSourcesService.resolveAndProcessAllSources
to be passed whenproviderToIndex: SearchProvider
. This ensures that indexing is targeted and efficient. Callers must specify which provider's index they intend to use.index = true - Index Versioning: When updating Lucene index versions and directory constants in search providers (like
), ALWAYS grep the codebase for the old directory constant name (e.g.,FullTextSearch
) to ensure hardcoded references in unit tests are updated.v6IndexDirName
Advanced Search Features
- Boilerplate Scoring Penalties: When implementing boilerplate/structural scoring penalties in Lucene where multi-line phrase search support requires exact offset preservation, use parallel fields (e.g.,
andcontents
). Replace the penalized lines in the specialized field with exact-length whitespace, and search across both usingcontents_code
.parseBoostedQuery - Match Expansion: When using file-level indexing in Lucene, always use the
API to iterate through multiple hits within a single document to ensure granular match reporting (offsets and line numbers).Matches - Match Deduplication: Always deduplicate match offsets within a single document when searching across multiple Lucene fields (e.g.,
andCONTENTS
) using aCODE
. This prevents duplicate results for the same term matching in different analyzer fields.Set
Extraction and Indexing
- Object Pooling: For heavy, non-thread-safe objects like
, prefer aTreeSitterDeclarationExtractor
-based pool overConcurrentLinkedQueue
when using Kotlin Coroutines. This ensures better resource management and predictability across diverse threading environments.ThreadLocal - Fail Fast: ALWAYS propagate exceptions in indexing, extraction, and search operations. NEVER swallow errors silently. "Well-documented failures" are preferred over silent partial successes.
- Extraction Tests: When writing tests for source extraction, avoid using empty or invalid ZIP files. Since extraction failures are no longer swallowed, these will now cause
and fail the test.ZipException
Examples
Implementing a new Lucene field
- Add the field name to the
object in the search provider.Fields - Update the indexing logic to populate the new field.
- Update the search logic to query the new field if necessary.
- If the field needs scoring penalties, use the parallel field strategy.
Debugging a search crash
- Check if the index exists using
.IndexService.search - Verify that the tool handler catches the
error.SearchResponse - Ensure no
is thrown from the service layer.IllegalStateException