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.
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.
Understanding the query syntax is key to effective codebase searching. Here are the fundamental concepts:
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
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
Narrow down your search using these filters:
file:
or f:
- Filter by filename
repo:
or r:
- Filter by repository name
branch:
or b:
- Filter by branch name
lang:
- Filter by programming language
Example: file:README test
searches for “test” in README files
Take your codebase search to the next level with these advanced features:
Search for symbol definitions (as identified by universal-ctags):
By default, all-lowercase queries are case-insensitive, while queries with any uppercase characters are case-sensitive. Override this behavior with case:
:
Use double quotes for queries containing spaces:
Combine search expressions for more complex queries:
Logical Operators
-
(dash) negates an expression
Implicit AND
between expressions
or
for explicit OR operations
Use parentheses ()
to group expressions
Examples:
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.
Here are some example scenarios and how to approach them with codebase search:
Finding API Usage
Search: api\.call\(
Explanation: This finds instances of “api.call(” across the codebase, useful for tracking API usage.
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
Search: // TODO:
Explanation: Finds TODO comments in code (adjust comment syntax for different languages).
Finding Deprecated Code
Search: @deprecated or [Dd]eprecated
Explanation: Locates usage of deprecation markers in comments or annotations.