Fixed the search when the search key includes space between the words.
This commit is contained in:
parent
e56db11bf4
commit
daba21b919
|
@ -53,7 +53,6 @@ export class spservices implements ISPServices {
|
|||
}
|
||||
|
||||
public async searchUsersNew(searchString: string, srchQry: string, isInitialSearch: boolean, pageNumber?: number): Promise<SearchResults> {
|
||||
//const _search = !isInitialSearch ? srchQry : `FirstName:${searchString}*`;
|
||||
let qrytext: string = '';
|
||||
if (isInitialSearch) qrytext = `FirstName:${searchString}* OR LastName:${searchString}*`;
|
||||
else {
|
||||
|
@ -63,7 +62,6 @@ export class spservices implements ISPServices {
|
|||
}
|
||||
if (qrytext.length <= 0) qrytext = `*`;
|
||||
}
|
||||
console.log(qrytext);
|
||||
const searchProperties: string[] = ["FirstName", "LastName", "PreferredName", "WorkEmail", "OfficeNumber", "PictureURL", "WorkPhone", "MobilePhone", "JobTitle", "Department", "Skills", "PastProjects", "BaseOfficeLocation", "SPS-UserType", "GroupId"];
|
||||
try {
|
||||
let users = await sp.search(<SearchQuery>{
|
||||
|
@ -74,7 +72,6 @@ export class spservices implements ISPServices {
|
|||
SourceId: 'b09a7990-05ea-4af9-81ef-edfab16c4e31',
|
||||
SortList: [{ "Property": "LastName", "Direction": SortDirection.Ascending }],
|
||||
});
|
||||
console.log(users);
|
||||
if (users && users.PrimarySearchResults.length > 0) {
|
||||
for (let index = 0; index < users.PrimarySearchResults.length; index++) {
|
||||
let user: any = users.PrimarySearchResults[index];
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
"properties": {
|
||||
"title": "Directory",
|
||||
"searchFirstName": 0,
|
||||
"searchProps": "FirstName,LastName,WorkEmail,Department",
|
||||
"searchProps": "FirstName,LastName,PreferredName,WorkEmail,Department",
|
||||
"pageSize": 10
|
||||
}
|
||||
}]
|
||||
|
|
|
@ -124,23 +124,22 @@ const DirectoryHook: React.FC<IDirectoryProps> = (props) => {
|
|||
};
|
||||
|
||||
let _searchUsers = async (searchText: string) => {
|
||||
try {
|
||||
console.log("Search Users: ", searchText);
|
||||
try {
|
||||
setstate({ ...state, searchText: searchText, isLoading: true });
|
||||
if (searchText.length > 0) {
|
||||
let searchProps: string[] = props.searchProps && props.searchProps.length > 0 ?
|
||||
props.searchProps.split(',') : ['FirstName', 'LastName', 'WorkEmail', 'Department'];
|
||||
let qryText: string = '';
|
||||
let finalSearchText: string = searchText ? searchText.replace(/ /g, '+') : searchText;
|
||||
searchProps.map((srchprop, index) => {
|
||||
if (index == searchProps.length - 1)
|
||||
qryText += `${srchprop}:${searchText}*`;
|
||||
else qryText += `${srchprop}:${searchText}* OR `;
|
||||
qryText += `${srchprop}:${finalSearchText}*`;
|
||||
else qryText += `${srchprop}:${finalSearchText}* OR `;
|
||||
});
|
||||
const users = await _services.searchUsersNew('', qryText, false);
|
||||
setstate({
|
||||
...state,
|
||||
searchText: searchText,
|
||||
//indexSelectedKey: (searchText.length > 0) ? searchText.substring(0, 1).toLocaleUpperCase() : 'A',
|
||||
indexSelectedKey: '0',
|
||||
users:
|
||||
users && users.PrimarySearchResults
|
||||
|
|
Loading…
Reference in New Issue