- Notifications
You must be signed in to change notification settings - Fork2.7k
Fix duplicate filter issues across all search tools#828
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
a0b5e3a
4deed67
bc817a1
a9c00e1
3c97c6b
5b57b2e
25985df
2b62f50
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -6,11 +6,35 @@ import ( | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"regexp" | ||
"github.com/google/go-github/v74/github" | ||
"github.com/mark3labs/mcp-go/mcp" | ||
) | ||
func hasFilter(query, filterType string) bool { | ||
// Match filter at start of string, after whitespace, or after non-word characters like '(' | ||
pattern := fmt.Sprintf(`(^|\s|\W)%s:\S+`, regexp.QuoteMeta(filterType)) | ||
matched, _ := regexp.MatchString(pattern, query) | ||
gokhanarkan marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
return matched | ||
} | ||
gokhanarkan marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
func hasSpecificFilter(query, filterType, filterValue string) bool { | ||
// Match specific filter:value at start, after whitespace, or after non-word characters | ||
// End with word boundary, whitespace, or non-word characters like ')' | ||
pattern := fmt.Sprintf(`(^|\s|\W)%s:%s($|\s|\W)`, regexp.QuoteMeta(filterType), regexp.QuoteMeta(filterValue)) | ||
matched, _ := regexp.MatchString(pattern, query) | ||
gokhanarkan marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
return matched | ||
} | ||
gokhanarkan marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
func hasRepoFilter(query string) bool { | ||
return hasFilter(query, "repo") | ||
} | ||
func hasTypeFilter(query string) bool { | ||
return hasFilter(query, "type") | ||
} | ||
func searchHandler( | ||
ctx context.Context, | ||
getClient GetClientFn, | ||
@@ -22,7 +46,10 @@ func searchHandler( | ||
if err != nil { | ||
return mcp.NewToolResultError(err.Error()), nil | ||
} | ||
if !hasSpecificFilter(query, "is", searchType) { | ||
query = fmt.Sprintf("is:%s %s", searchType, query) | ||
} | ||
owner, err := OptionalParam[string](request, "owner") | ||
if err != nil { | ||
@@ -34,7 +61,7 @@ func searchHandler( | ||
return mcp.NewToolResultError(err.Error()), nil | ||
} | ||
if owner != "" && repo != ""&& !hasRepoFilter(query){ | ||
query = fmt.Sprintf("repo:%s/%s %s", owner, repo, query) | ||
} | ||
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.