admin 管理员组文章数量: 1086019
I am using graph api - for content search in the documents of sharepoint. My search request is -
string searchQuery = this.GetContentSearchQuery(request);
var searchRequest = new
{
requests = new[]
{
new
{
entityTypes = new[] { "listItem" },
query = new
{
query_string = new
{
query = searchQuery,
},
},
from = 0,
size = 25,
fields = new[] { "ID" },
},
},
};
I tried by encoding the characters but it did not work.
private string GetContentSearchQuery(ContentSearchDTO request)
{
StringBuilder queryString = new();
if (!string.IsNullOrEmpty(request.ClientId))
{
// I am appending all the properties needed for the request and then later sending the search text to the body.
string escapedSearchText = this.EscapeSpecialCharacters(request.SearchText);
queryString.Append($" AND body:{escapedSearchText}");
}
return this.EscapeSpecialCharacters(queryString.ToString());
}
below is the EscapeSpecialCharacters method for encoding
private string EscapeSpecialCharacters(string input)
{
StringBuilder escapedString = new StringBuilder();
foreach (char c in input)
{
switch (c)
{
case '(':
case ')':
case '{':
case '}':
escapedString.Append(Uri.EscapeDataString(c.ToString()));
break;
default:
escapedString.Append(c);
break;
}
}
return escapedString.ToString();
}
I am using graph api - https://graph.microsoft/beta/search/query for content search in the documents of sharepoint. My search request is -
string searchQuery = this.GetContentSearchQuery(request);
var searchRequest = new
{
requests = new[]
{
new
{
entityTypes = new[] { "listItem" },
query = new
{
query_string = new
{
query = searchQuery,
},
},
from = 0,
size = 25,
fields = new[] { "ID" },
},
},
};
I tried by encoding the characters but it did not work.
private string GetContentSearchQuery(ContentSearchDTO request)
{
StringBuilder queryString = new();
if (!string.IsNullOrEmpty(request.ClientId))
{
// I am appending all the properties needed for the request and then later sending the search text to the body.
string escapedSearchText = this.EscapeSpecialCharacters(request.SearchText);
queryString.Append($" AND body:{escapedSearchText}");
}
return this.EscapeSpecialCharacters(queryString.ToString());
}
below is the EscapeSpecialCharacters method for encoding
private string EscapeSpecialCharacters(string input)
{
StringBuilder escapedString = new StringBuilder();
foreach (char c in input)
{
switch (c)
{
case '(':
case ')':
case '{':
case '}':
escapedString.Append(Uri.EscapeDataString(c.ToString()));
break;
default:
escapedString.Append(c);
break;
}
}
return escapedString.ToString();
}
Share
Improve this question
edited Mar 28 at 11:21
Aria
asked Mar 28 at 11:15
AriaAria
12 bronze badges
1 Answer
Reset to default 0Here are the URL-encoded representations of the special characters you mentioned:
(
becomes%28
)
becomes%29
{
becomes%7B
}
becomes%7D
An example in the documentation can be found here- https://learn.microsoft/en-us/graph/query-parameters?tabs=http#encoding-query-parameters This explains the ( and ) .
Another example is this queryhttps://graph.microsoft/v1.0/me/messages?$search="subject:example%28test%29%7Bsample%7D"
where the search query is looking for messages with a subject that includes the termexample(testsample}
.
本文标签: How to include Special characters search like ( ) in graph api searchStack Overflow
版权声明:本文标题:How to include Special characters search like (,),{,} in graph api search - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744041240a2523297.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论