mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-10-26 19:15:09 +00:00
Match job names in global search suggestions (#26690)
This commit is contained in:
1 parent
2d99bcf828
commit
f44fdc3082
2 files changed
+26
No files matched your search
@@ -149,6 +149,7 @@ import hudson.search.CollectionSearchIndex;
|
||||
import hudson.search.SearchIndex;
|
||||
import hudson.search.SearchIndexBuilder;
|
||||
import hudson.search.SearchItem;
|
||||
import hudson.search.UserSearchProperty;
|
||||
import hudson.security.ACL;
|
||||
import hudson.security.ACLContext;
|
||||
import hudson.security.AccessControlled;
|
||||
@@ -241,6 +242,7 @@ import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Properties;
|
||||
@@ -2419,6 +2421,28 @@ public class Jenkins extends AbstractCIBase implements DirectlyModifiableTopLeve
|
||||
protected Iterable<TopLevelItem> allAsIterable() {
|
||||
return allItems(TopLevelItem.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void suggest(String token, List<SearchItem> result) {
|
||||
boolean caseInsensitive = UserSearchProperty.isCaseInsensitive();
|
||||
String searchToken = caseInsensitive ? token.toLowerCase(Locale.ROOT) : token;
|
||||
for (TopLevelItem item : allAsIterable()) {
|
||||
if (item != null && (contains(item.getName(), searchToken, caseInsensitive)
|
||||
|| contains(item.getDisplayName(), searchToken, caseInsensitive))) {
|
||||
result.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean contains(String value, String token, boolean caseInsensitive) {
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
if (caseInsensitive) {
|
||||
value = value.toLowerCase(Locale.ROOT);
|
||||
}
|
||||
return value.contains(token);
|
||||
}
|
||||
})
|
||||
.add(getPrimaryView().makeSearchIndex())
|
||||
.add(new CollectionSearchIndex() { // for computers
|
||||
|
||||
@@ -348,6 +348,7 @@ public class SearchTest {
|
||||
@Test
|
||||
void testCompletionOutsideView() throws Exception {
|
||||
FreeStyleProject p = j.createFreeStyleProject("foo-bar");
|
||||
p.setDisplayName("display-name-only");
|
||||
ListView v = new ListView("empty1", j.jenkins);
|
||||
ListView w = new ListView("empty2", j.jenkins);
|
||||
j.jenkins.addView(v);
|
||||
@@ -360,6 +361,7 @@ public class SearchTest {
|
||||
assertFalse(j.jenkins.getPrimaryView().contains(p));
|
||||
|
||||
assertTrue(suggest(j.jenkins.getSearchIndex(), "foo").contains(p));
|
||||
assertTrue(suggest(j.jenkins.getSearchIndex(), "display-name").contains(p));
|
||||
}
|
||||
|
||||
@Issue("SECURITY-385")
|
||||
|
||||
Reference in new issue
Block a user