Skip to content

fix(rest): Added code to filter user based on givenname lastname emaid.#4105

Open
nikkuma7 wants to merge 1 commit intomainfrom
fix/searchuserby_name_email_lastname
Open

fix(rest): Added code to filter user based on givenname lastname emaid.#4105
nikkuma7 wants to merge 1 commit intomainfrom
fix/searchuserby_name_email_lastname

Conversation

@nikkuma7
Copy link
Copy Markdown
Contributor

@nikkuma7 nikkuma7 commented Apr 21, 2026

Please provide a summary of your changes here.

  • Which issue is this pull request belonging to and how is it solving it? (Refer to issue here)
  • Did you add or update any new dependencies that are required for your change?

Issue: Closes #4095

Suggest Reviewer

You can suggest reviewers here with an @mention.

How To Test?

URL: get : http://localhost:8080/resource/api/users?searchTerm=@sw360.org&page=0&size=5&sort=lastname,asc

NOTE : Please test "Exact Match" scenario as well.

How should these changes be tested by the reviewer?
Have you implemented any additional tests?

Checklist

Must:

  • All related issues are referenced in commit messages and in PR

@nikkuma7 nikkuma7 force-pushed the fix/searchuserby_name_email_lastname branch from a97b53e to f0be599 Compare April 21, 2026 05:53
@nikkuma7 nikkuma7 added needs code review needs general test This is general testing, meaning that there is no org specific issue to check for labels Apr 21, 2026
@nikkuma7 nikkuma7 force-pushed the fix/searchuserby_name_email_lastname branch 4 times, most recently from d390ce3 to f2692dd Compare April 22, 2026 06:23
Comment on lines +143 to +148
if (CommonUtils.isNotNullEmptyOrWhitespace(searchText)) {
if (luceneSearch) {
paginatedUsers = userService.searchUsersByNameOrEmail(searchText.trim(), pageable);
} else {
paginatedUsers = userService.searchUsersByNameOrEmailExact(searchText.trim(), pageable);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, searchText will only work with luceneSearch=true. With lucene as false, the usecase does not make sense!

Comment on lines +186 to +191
public Map<PaginationData, List<User>> searchUsersByNameOrEmailExact(String searchTerm, Pageable pageable) throws TException {
UserService.Iface sw360UserClient = getThriftUserClient();
PaginationData pageData = pageableToPaginationData(pageable);
return sw360UserClient.searchUsersByNameOrEmailExact(searchTerm, pageData);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need this function.

Comment on lines +191 to +196
/**
* Search users by an exact term matched against givenname, lastname, or email.
* Uses CouchDB $eq OR query — no wildcard or regex.
**/
map<PaginationData, list<User>> searchUsersByNameOrEmailExact(1: string searchTerm, 2: PaginationData pageData) throws (1: SW360Exception exp);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need this function.

Comment on lines +153 to +155
// Exception propagated (unlikely as connector swallows it) — fall back immediately
log.warn("Lucene/Nouveau search threw exception for text='{}', falling back to query: {}", text, e.getMessage());
return repository.searchByNameOrEmail(text, pageData);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, no fallback is required. If the nouveau query failed, the entire request must fail.

/**
* Search users where givenname, lastname, or email exactly matches the search term.
*/
public Map<PaginationData, List<User>> searchByNameOrEmailExact(String searchTerm, PaginationData pageData) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned, we don't need this function.

Comment on lines +247 to +249
List<User> users = getConnector().getQueryResultPaginated(
qb, User.class, pageData, sortSelector
);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using query here will not get you results from Nouveau.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please create a function similar to VulnerabilitySearchHandler::search() in UserSearchHandler

public Map<PaginationData, List<Vulnerability>> search(String searchText, String cveId, PaginationData pageData) {
Map<String, Set<String>> subQueryRestrictions = new HashMap<>();
if (CommonUtils.isNotNullEmptyOrWhitespace(searchText)) {
subQueryRestrictions.put(Vulnerability._Fields.TITLE.getFieldName(), Collections.singleton(searchText));
subQueryRestrictions.put(Vulnerability._Fields.EXTERNAL_ID.getFieldName(), Collections.singleton(searchText));
}
if (CommonUtils.isNotNullEmptyOrWhitespace(cveId)) {
subQueryRestrictions.put(Vulnerability._Fields.CVE_REFERENCES.getFieldName(), Collections.singleton(cveId));
}
String sortColumn = getSortColumnName(pageData);
return connector.searchViewWithRestrictionsWithOr(Vulnerability.class,
luceneSearchView.getIndexName(), null, subQueryRestrictions,
pageData, sortColumn, pageData.isAscending());
}

As you can see, this function takes a search string as input and matches it against Title and External ID, which will be the user's name and email in this case.

*/
public Map<PaginationData, List<User>> searchByNameOrEmail(String searchTerm, PaginationData pageData) {
// Escape special regex chars, then build a case-insensitive prefix pattern
String escaped = searchTerm.replaceAll("([.+*?^${}()|\\[\\]\\\\])", "\\\\$1");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using the Nouveau to search as suggested, this filtering will be taken care by NouveauLuceneAwareDatabaseConnector

@GMishx
Copy link
Copy Markdown
Member

GMishx commented Apr 28, 2026

@nikkuma7

  1. We do not want exact search for this parameter. It cannot be done. This is a free text search and thus you cannot make it exact match. For that, we have the individual filters based on name, email, etc.
  2. Please use the suggested VulnerabilitySearchHandler approach using Nouveau. This implementation will have 3 OR conditions on givenname, lastname or email instead of title or externalid in VulnerabilitySearchHandler

@nikkuma7 nikkuma7 force-pushed the fix/searchuserby_name_email_lastname branch 3 times, most recently from 819c09a to 6ed93ae Compare May 6, 2026 04:50
@nikkuma7
Copy link
Copy Markdown
Contributor Author

nikkuma7 commented May 6, 2026

@GMishx , Comment addressed.

@nikkuma7
Copy link
Copy Markdown
Contributor Author

nikkuma7 commented May 6, 2026

image image image

…lid.

Signed-off-by: Nikesh Kumar <kumar.nikesh@siemens.com>
@nikkuma7 nikkuma7 force-pushed the fix/searchuserby_name_email_lastname branch from 6ed93ae to 1b94976 Compare May 6, 2026 05:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs code review needs general test This is general testing, meaning that there is no org specific issue to check for

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Filter the user by firstname, last name or emailId

2 participants