Skip to content

Commit 4942d4a

Browse files
committed
Added Managed Property and Crawled Property to Search Document
Added Managed Property and Crawled Property to Search Document.
1 parent 10204dd commit 4942d4a

17 files changed

+487
-16
lines changed
193 KB
Binary file not shown.

Packages/spoqa.sppkg

5.74 KB
Binary file not shown.

SPFX/SPOQA/config/package-solution.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"solution": {
44
"name": "spoqa-client-side-solution",
55
"id": "029e4fc2-a440-4f5f-a358-b34a0eca54b5",
6-
"version": "1.22.05.20",
6+
"version": "1.22.06.01",
77
"includeClientSideAssets": true,
88
"webApiPermissionRequests": [
99
{

SPFX/SPOQA/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "spoqa",
3-
"version": "1.22.0520",
3+
"version": "1.22.0601",
44
"private": true,
55
"main": "lib/index.js",
66
"scripts": {
5.74 KB
Binary file not shown.

SPFX/SPOQA/src/webparts/Helpers/SPOQAHelper.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export default class SPOQAHelper
137137

138138

139139
//Initialize file format you want csv or xls
140-
var uri = 'data:text/csv;charset=utf-8,' + escape(CSV);
140+
var uri = 'data:text/csv;charset=utf-8,%EF%BB%BF' + encodeURIComponent(CSV);
141141

142142
// Now the little tricky part.
143143
// you can use either>> window.open(uri);

SPFX/SPOQA/src/webparts/Helpers/SearchHelper.ts

+145
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import {SPHttpClient,ISPHttpClientOptions} from '@microsoft/sp-http';
2+
import RestAPIHelper from './RestAPIHelper';
3+
import {Text } from '@microsoft/sp-core-library';
24
// Microsoft.SharePoint.Client.Search.Administration.DocumentCrawlLog
35
export default class SearchHelper
46
{
@@ -69,4 +71,147 @@ export default class SearchHelper
6971
return await responseJson;
7072
}
7173
}
74+
75+
public static async GetManagedProperties(spHttpClient:SPHttpClient,webAbsoluteUrl:string, workId:string)
76+
{
77+
// Get https://chengc.sharepoint.com/_api/search/query?querytext='WorkId%3a%22xxxxxx%22'&rowlimit=1&refiners='ManagedProperties(filter%3d5000%2f0%2f*)'&clienttype='ContentSearchRegular'
78+
// let apiUrl = `${webAbsoluteUrl}/_api/search/query?querytext='WorkId="${workId}"'&rowlimit=1&refiners='ManagedProperties(filter=5000/0/*)'`;
79+
// let apiUrl = `https://chengc.sharepoint.com/_api/search/query?querytext='Path%3ahttps%3a%2f%2fchengc.sharepoint.com%2fExcelLib%2fexcel2.xlsx'&rowlimit=1&refiners='ManagedProperties(filter%3d5000%2f0%2f*)'&sortlist='%5bdocid%5d%3aascending'&hiddenconstraints='WorkId%3a%22157214370457891573%22'&clienttype='ContentSearchRegular'`;
80+
let apiUrl = `${webAbsoluteUrl}/_api/search/postquery`;
81+
const body: string = JSON.stringify({
82+
request: {
83+
ClientType: "ModernWebPart",
84+
Querytext: `WorkId="${workId}"`,
85+
RowLimit: 1,
86+
Refiners:'ManagedProperties(filter=5000/0/*)'
87+
}});
88+
const headers: Headers = new Headers();
89+
headers.append('Accept', 'application/json;odata=nometadata');
90+
headers.append('Content-type', 'application/json;charset=utf-8');
91+
headers.append('OData-Version', '3.0');
92+
93+
const httpClientOptions: ISPHttpClientOptions = {
94+
body: body,
95+
headers:headers
96+
};
97+
98+
var res:any = await spHttpClient.post(apiUrl, SPHttpClient.configurations.v1,httpClientOptions);
99+
var propertiesFirstRequest =[];
100+
if(res.ok)
101+
{
102+
res = await res.json();
103+
if(res.PrimaryQueryResult.RefinementResults.Refiners
104+
&& res.PrimaryQueryResult.RefinementResults.Refiners.length >0
105+
&& res.PrimaryQueryResult.RefinementResults.Refiners[0].Entries.length >0
106+
)
107+
{
108+
var selectProperties = [];
109+
var excludeProperties=["ClassificationContext","ClassificationLastScan","Color","ContentDatabaseId"];
110+
res.PrimaryQueryResult.RelevantResults.Table.Rows[0].Cells.forEach(e=>{propertiesFirstRequest.push(e);});
111+
res.PrimaryQueryResult.RefinementResults.Refiners[0].Entries.forEach(e=>{
112+
var filterMps = propertiesFirstRequest.filter(p=>p.Key == e.RefinementName);
113+
if(filterMps.length== 0 && excludeProperties.indexOf(e.RefinementName)<0)
114+
{
115+
selectProperties.push(e.RefinementName);
116+
}
117+
});
118+
const queryAllMPBody: string = JSON.stringify({
119+
request: {
120+
ClientType: "ModernWebPart",
121+
Querytext: `WorkId="${workId}"`,
122+
RowLimit: 1,
123+
SelectProperties:selectProperties
124+
}});
125+
126+
const queryAllMPhttpClientOptions: ISPHttpClientOptions = {
127+
body: queryAllMPBody,
128+
headers:headers
129+
};
130+
131+
try
132+
{
133+
var allMPRes:any = await spHttpClient.post(apiUrl, SPHttpClient.configurations.v1,queryAllMPhttpClientOptions);
134+
if(allMPRes.ok)
135+
{
136+
res = await allMPRes.json();
137+
}
138+
else
139+
{
140+
console.error("Failed to call /_api/search/postquery when selecting all managed properties");
141+
}
142+
}
143+
catch(ex)
144+
{
145+
console.error(ex);
146+
}
147+
}
148+
}
149+
else
150+
{
151+
console.error("Failed to call /_api/search/postquery, ManagedProperties(filter=5000/0/*)");
152+
}
153+
154+
// res.PrimaryQueryResult.RelevantResults.RowCount
155+
// res.PrimaryQueryResult.RelevantResults.Table.Rows[0].Cells
156+
// res.PrimaryQueryResult.RelevantResults.Table.Rows[0].Cells[0].Value
157+
// res.PrimaryQueryResult.RelevantResults.Table.Rows[0].Cells[0].Key
158+
propertiesFirstRequest.forEach(e=>{
159+
var filterProrpties = res.PrimaryQueryResult.RelevantResults.Table.Rows[0].Cells.filter(pro=>pro.Key == e.Key);
160+
if(filterProrpties.length ==0)
161+
{
162+
res.PrimaryQueryResult.RelevantResults.Table.Rows[0].Cells.push(e);
163+
}
164+
});
165+
166+
return res;
167+
}
168+
169+
public static async GetCrawledProperties(spHttpClient:SPHttpClient,webAbsoluteUrl:string, workId:string)
170+
{
171+
// Get https://chengc.sharepoint.com/_api/search/query?querytext='WorkId%3a%22xxxxx%22'&rowlimit=1&refiners='CrawledProperties(filter%3d5000%2f0%2f*)'&clienttype='ContentSearchRegular'
172+
// let apiUrl = `${webAbsoluteUrl}/_api/search/query?querytext='WorkId="${workId}"'&rowlimit=1&refiners='CrawledProperties(filter=5000/0/*)'`;
173+
let apiUrl = `${webAbsoluteUrl}/_api/search/postquery`;
174+
const body: string = JSON.stringify({
175+
request: {
176+
ClientType: "ModernWebPart",
177+
Querytext: `WorkId="${workId}"`,
178+
RowLimit: 1,
179+
Refiners:'CrawledProperties(filter=5000/0/*)'
180+
}});
181+
const headers: Headers = new Headers();
182+
headers.append('Accept', 'application/json;odata=nometadata');
183+
headers.append('Content-type', 'application/json;charset=utf-8');
184+
headers.append('OData-Version', '3.0');
185+
186+
const httpClientOptions: ISPHttpClientOptions = {
187+
body: body,
188+
headers:headers
189+
};
190+
191+
var res = await spHttpClient.post(apiUrl, SPHttpClient.configurations.v1,httpClientOptions);
192+
if(res.ok)
193+
{
194+
res = await res.json();
195+
}
196+
else
197+
{
198+
console.error("Failed to call /_api/search/postquery, CrawledProperties(filter=5000/0/*)");
199+
}
200+
201+
// res.PrimaryQueryResult.RefinementResults.Refiners[0].Entries[0].RefinementName
202+
return await res;
203+
}
204+
205+
public static async CallOtherDiagnosticsAPIS(spHttpClient:SPHttpClient,webAbsoluteUrl:string, workId:string)
206+
{
207+
// /_api/search/query?querytext='workid:{0}'&properties='QueryIdentityDiagnostics:true'&property='EnableDynamicGroups:true'&TrimDuplicates=false
208+
// /_api/search/query?querytext='workid:{0}'&properties='3SRouted:false,QueryIdentityDiagnostics:true'&property='EnableDynamicGroups:true'&TrimDuplicates=false
209+
var apiTemplates = ["{0}/_api/search/query?querytext='workid:{1}'&properties='QueryIdentityDiagnostics:true'&property='EnableDynamicGroups:true'&TrimDuplicates=false",
210+
"{0}/_api/search/query?querytext='workid:{1}'&properties='3SRouted:false,QueryIdentityDiagnostics:true'&property='EnableDynamicGroups:true'&TrimDuplicates=false"];
211+
for(var index=0; index<apiTemplates.length; index++)
212+
{
213+
var apiUrl = Text.format(apiTemplates[index], webAbsoluteUrl, workId);
214+
await spHttpClient.get(apiUrl, SPHttpClient.configurations.v1);
215+
}
216+
}
72217
}

SPFX/SPOQA/src/webparts/sharePointOnlineQuickAssist/components/Search/CrawlLogGrid.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ICrawlLog,ICrawlLogs } from "./ICrawlLog";
2-
import { DetailsList, DetailsListLayoutMode, ColumnActionsMode, SelectionMode, IColumn,IDetailsHeaderProps } from 'office-ui-fabric-react/lib/DetailsList';
2+
import { DetailsList, DetailsListLayoutMode, SelectionMode, IColumn } from 'office-ui-fabric-react/lib/DetailsList';
33
import * as React from 'react';
44
import * as strings from 'SharePointOnlineQuickAssistWebPartStrings';
55
export default class CrawlLogGrid extends React.Component<ICrawlLogs>
@@ -15,7 +15,7 @@ export default class CrawlLogGrid extends React.Component<ICrawlLogs>
1515
isCollapsible: true,
1616
data: 'string',
1717
onRender: (item: ICrawlLog) => {
18-
return <span>{item.TimeStamp}</span>;
18+
return <div style={{whiteSpace: 'pre-wrap', overflowWrap: 'break-word'}}>{item.TimeStamp}</div>;
1919
},
2020
isPadded: true,
2121
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import { DetailsList, DetailsListLayoutMode, SelectionMode, IColumn } from 'office-ui-fabric-react/lib/DetailsList';
2+
import {
3+
PrimaryButton,
4+
TextField,
5+
} from 'office-ui-fabric-react/lib/index';
6+
import * as React from 'react';
7+
import * as strings from 'SharePointOnlineQuickAssistWebPartStrings';
8+
import { ICrawledProperty,ICrawledProperties } from "./ICrawledProperty";
9+
import SPOQAHelper from '../../../Helpers/SPOQAHelper';
10+
export default class CrawledPropertyGrid extends React.Component<ICrawledProperties>
11+
{
12+
private columns: IColumn[] = [
13+
{
14+
key: 'Name',
15+
name: strings.SD_PropertyName,
16+
fieldName: 'Name',
17+
minWidth: 200,
18+
maxWidth: 400,
19+
isResizable: true,
20+
isCollapsible: true,
21+
data: 'string',
22+
onRender: (item: ICrawledProperty) => {
23+
return <div style={{whiteSpace: 'pre-wrap', overflowWrap: 'break-word'}}>{item.Name}</div>;
24+
},
25+
isPadded: true,
26+
}];
27+
28+
public state = {
29+
items:this.props.items,
30+
columns:this.columns
31+
};
32+
33+
public render():React.ReactElement<ICrawledProperties>
34+
{
35+
const { items, columns} = this.state;
36+
return <div>
37+
<div>
38+
<span>
39+
<TextField
40+
label={strings.SD_PropertyFilter}
41+
multiline={false}
42+
onChange={(e)=>{let text:any = e.target; this.FilterCrawledProperty(text.value);}}
43+
// value={this.state.keywordFilter}
44+
// onKeyDown={(e)=>{if(e.keyCode ===13){}}}
45+
style={{ display: 'inline'}}
46+
/>
47+
<PrimaryButton
48+
text= {strings.RI_Export}
49+
style={{ display: 'inline', marginTop: '10px', marginLeft:"10px"}}
50+
onClick={() => {this.DoExport();}}
51+
/>
52+
</span>
53+
</div>
54+
{this.state.items && this.state.items.length >0 ?
55+
<DetailsList
56+
items={items}
57+
columns={columns}
58+
selectionMode={SelectionMode.none}
59+
layoutMode={DetailsListLayoutMode.fixedColumns}
60+
isHeaderVisible={true}
61+
/>: strings.RI_NoData}
62+
</div>;
63+
}
64+
65+
private DoExport():void
66+
{
67+
// Export CrawledProperty
68+
SPOQAHelper.JSONToCSVConvertor(this.props.items, true, "CrawledProperty");
69+
}
70+
71+
private FilterCrawledProperty(cpFilter:string) {
72+
cpFilter = cpFilter.trim();
73+
if(cpFilter.length >=1)
74+
{
75+
var filteredItems = [];
76+
this.props.items.forEach(e=>{
77+
if((e.Name && e.Name.toLowerCase().indexOf(cpFilter.toLowerCase()) >=0))
78+
{
79+
filteredItems.push(
80+
{
81+
Name:e.Name
82+
}
83+
);
84+
}
85+
});
86+
this.setState({items:filteredItems});
87+
}
88+
else if(!cpFilter || cpFilter=="")
89+
{
90+
this.setState({items:this.props.items});
91+
}
92+
}
93+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export interface ICrawledProperty {
2+
Name:string;
3+
}
4+
5+
export interface ICrawledProperties
6+
{
7+
items:ICrawledProperty[];
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export interface IManagedProperty {
2+
Name:string;
3+
Value:string;
4+
}
5+
6+
export interface IManagedProperties
7+
{
8+
items:IManagedProperty[];
9+
}

0 commit comments

Comments
 (0)