Codebase Search
Learn how to effectively search across multiple repositories in Factory using powerful regex-based queries
Factory’s codebase search feature allows you to quickly find and reference code across multiple repositories. This powerful tool uses regex-based queries to provide flexible and precise search capabilities, enhancing your ability to navigate and understand large codebases.
Getting Started with Codebase Search
To use the codebase search in Factory, you’ll interact with a running server that indexes multiple repositories. Here’s how to get started:
Access the Context Menu
In your Factory session, switch to the context panel from the upper left corner of any panel.
Enter Your Query
Type your search query into the provided search bar. Remember, every query is treated as a regex pattern.
Review Results
The search results will display matching code snippets, file names, and repository information.
Query Syntax Basics
Understanding the query syntax is key to effective codebase searching. Here are the fundamental concepts:
Basic Regex Patterns
Basic Regex Patterns
-
.
(dot) is a wildcard character matching any single character -
\.
(escaped dot) matches a literal dot -
?
matches zero or one of the preceding character -
*
matches zero or more of the preceding character -
+
matches one or more of the preceding character
Example: print.+
would match “print” followed by one or more characters
Multiline Search
Multiline Search
Use OR[[:space:]]IMPLIED
for multiline search patterns.
Example: function OR[[:space:]]IMPLIED return
would match functions that contain a return statement, even if “return” is on a different line.
Filtering Results
Filtering Results
Narrow down your search using these filters:
-
file:
orf:
- Filter by filename -
repo:
orr:
- Filter by repository name -
branch:
orb:
- Filter by branch name -
lang:
- Filter by programming language
Example: file:README test
searches for “test” in README files
Advanced Search Techniques
Take your codebase search to the next level with these advanced features:
Symbol Search
Search for symbol definitions (as identified by universal-ctags):
Case Sensitivity
By default, all-lowercase queries are case-insensitive, while queries with any uppercase characters are case-sensitive. Override this behavior with case:
:
Quoted Queries
Use double quotes for queries containing spaces:
Logical Composition
Combine search expressions for more complex queries:
Logical Operators
Logical Operators
-
-
(dash) negates an expression -
Implicit
AND
between expressions -
or
for explicit OR operations -
Use parentheses
()
to group expressions
Examples:
Best Practices for Effective Codebase Search
-
Start Broad, Then Refine: Begin with a general search and use filters to narrow down results.
-
Use Regex Wisely: Leverage regex patterns for flexible matching, but be cautious of overly complex patterns.
-
Combine Filters: Use multiple filters together to pinpoint specific code areas.
-
Leverage Symbol Search: For finding function or class definitions quickly.
-
Consider Case Sensitivity: Be explicit about case when it matters for your search.
Common Search Scenarios
Here are some example scenarios and how to approach them with codebase search:
Finding API Usage
Finding API Usage
Search: api\.call\(
Explanation: This finds instances of “api.call(” across the codebase, useful for tracking API usage.
Locating Test Files
Locating Test Files
Search: file:test lang:python def test_
Explanation: This finds Python test function definitions in files with “test” in the name.
Identifying TODO Comments
Identifying TODO Comments
Search: // TODO:
Explanation: Finds TODO comments in code (adjust comment syntax for different languages).
Finding Deprecated Code
Finding Deprecated Code
Search: @deprecated or [Dd]eprecated
Explanation: Locates usage of deprecation markers in comments or annotations.