问题
i am having difficulty to discover how the operator AND function for a research with Youtube API.
At the Youtube.Search i found the method setQ that explaing the logic for the operator NOT and OR but not for the operator AND. The main idea is to make a search that contains exactly both 2 parameters otherelse i can use the OR logic.
Example: i want that 2 "fish" and "sea" should be both part of the metadata of the research.
I have made an analysis on front-end call and it has this form: fish+sea but if i try to implement it in java it looks that it doesn't function correctly cause i have other results. PS: I have ordered all my results by relevance ( by setting the order with "relevance" value as the logic that youtube itself use) For this reason i was wating to have the same result on youtube website and in my local app.
回答1:
I tested some request using the Google Data API Explorer and I found that the word "AND" (uppercase) it will bring you slightly different results:
For example, the following request is for search videos using the query "The ring" (without double quotes) - it will bring the top 10 search results from the US region:
https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=10&q=The+ring®ionCode=US&type=video&fields=items(id(channelId%2Ckind%2CvideoId)%2Csnippet(channelTitle%2Ctitle))%2CnextPageToken%2CpageInfo%2CprevPageToken%2CregionCode%2CtokenPagination&key={YOUR_API_KEY}
These are the results:
{
"nextPageToken": "CAoQAA",
"regionCode": "US",
"pageInfo": {
"totalResults": 1000000,
"resultsPerPage": 10
},
"items": [
{
"id": {
"kind": "youtube#video",
"videoId": "PFsl1cGHzp4"
},
"snippet": {
"title": "The Ring (1/8) Movie CLIP - You Will Die in Seven Days (2002) HD",
"channelTitle": "Movieclips"
}
},
{
"id": {
"kind": "youtube#video",
"videoId": "lbO9LhD9PsI"
},
"snippet": {
"title": "The Ring- final scene!",
"channelTitle": "prochys09"
}
},
{
"id": {
"kind": "youtube#video",
"videoId": "5bXpMRkwm_8"
},
"snippet": {
"title": "SML Movie: The Ring",
"channelTitle": "SuperMarioLogan"
}
},
{
"id": {
"kind": "youtube#video",
"videoId": "V3iJqH9-tQ8"
},
"snippet": {
"title": "Everything Wrong With The Ring In 14 Minutes Or Less",
"channelTitle": "CinemaSins"
}
},
{
"id": {
"kind": "youtube#video",
"videoId": "lm9AoNNWiPc"
},
"snippet": {
"title": "The Ring Evolution in Movies & TV. (Sadako & Samara)",
"channelTitle": "Darwin's Media"
}
},
{
"id": {
"kind": "youtube#video",
"videoId": "hpb2-ZOzc_o"
},
"snippet": {
"title": "Samara Comes to You - The Ring (8/8) Movie CLIP (2002) HD",
"channelTitle": "Movieclips"
}
},
{
"id": {
"kind": "youtube#video",
"videoId": "Baw98nsMvxU"
},
"snippet": {
"title": "scary movie 3 brenda vs the ring lol",
"channelTitle": "maltbydude"
}
},
{
"id": {
"kind": "youtube#video",
"videoId": "6YP1xg8G1o4"
},
"snippet": {
"title": "RINGS behind the scenes",
"channelTitle": "teu davidz"
}
},
{
"id": {
"kind": "youtube#video",
"videoId": "rroMPRc4flw"
},
"snippet": {
"title": "The Ring Two (8/8) Movie CLIP - I'm Not Your Mommy (2005) HD",
"channelTitle": "Movieclips"
}
},
{
"id": {
"kind": "youtube#video",
"videoId": "WcuRPzB4RNc"
},
"snippet": {
"title": "Rings (2017) - TV Store Prank",
"channelTitle": "Paramount Pictures"
}
}
]
}
Here is the demo of the previous request.
Making a test with these modifications:
- Double quote the searchs terms - (i.e.
"the"
,"ring"
). - Adding the "AND" operator (without double quotes).
I can now test the modified version of the previous request:
https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=10&q=%22The%22+AND+%22ring%22®ionCode=US&type=video&fields=items(id(channelId%2Ckind%2CvideoId)%2Csnippet(channelTitle%2Ctitle))%2CnextPageToken%2CpageInfo%2CprevPageToken%2CregionCode%2CtokenPagination&key={YOUR_API_KEY}
And its results:
{
"nextPageToken": "CAoQAA",
"regionCode": "US",
"pageInfo": {
"totalResults": 1000000,
"resultsPerPage": 10
},
"items": [
{
"id": {
"kind": "youtube#video",
"videoId": "PFsl1cGHzp4"
},
"snippet": {
"title": "The Ring (1/8) Movie CLIP - You Will Die in Seven Days (2002) HD",
"channelTitle": "Movieclips"
}
},
{
"id": {
"kind": "youtube#video",
"videoId": "5bXpMRkwm_8"
},
"snippet": {
"title": "SML Movie: The Ring",
"channelTitle": "SuperMarioLogan"
}
},
{
"id": {
"kind": "youtube#video",
"videoId": "lbO9LhD9PsI"
},
"snippet": {
"title": "The Ring- final scene!",
"channelTitle": "prochys09"
}
},
{
"id": {
"kind": "youtube#video",
"videoId": "V3iJqH9-tQ8"
},
"snippet": {
"title": "Everything Wrong With The Ring In 14 Minutes Or Less",
"channelTitle": "CinemaSins"
}
},
{
"id": {
"kind": "youtube#video",
"videoId": "hpb2-ZOzc_o"
},
"snippet": {
"title": "Samara Comes to You - The Ring (8/8) Movie CLIP (2002) HD",
"channelTitle": "Movieclips"
}
},
{
"id": {
"kind": "youtube#video",
"videoId": "rroMPRc4flw"
},
"snippet": {
"title": "The Ring Two (8/8) Movie CLIP - I'm Not Your Mommy (2005) HD",
"channelTitle": "Movieclips"
}
},
{
"id": {
"kind": "youtube#video",
"videoId": "lm9AoNNWiPc"
},
"snippet": {
"title": "The Ring Evolution in Movies & TV. (Sadako & Samara)",
"channelTitle": "Darwin's Media"
}
},
{
"id": {
"kind": "youtube#video",
"videoId": "kcRWyLMVrFM"
},
"snippet": {
"title": "Cardi B - Ring (feat. Kehlani) [Official Video]",
"channelTitle": "Cardi B"
}
},
{
"id": {
"kind": "youtube#video",
"videoId": "uukQ_6szDm8"
},
"snippet": {
"title": "Rings | Trailer #1 | Paramount Pictures International",
"channelTitle": "Paramount Pictures International"
}
},
{
"id": {
"kind": "youtube#video",
"videoId": "3SZu3_HGoWk"
},
"snippet": {
"title": "Samara Sings A Song (The Ring Scary Halloween Parody)",
"channelTitle": "Aaron Fraser-Nash"
}
}
]
}
Here is the demo of the previous request.
If you compare the two results, you'll see that (using the AND operator) does not contain these search results:
N.B: I highlighted the search terms:
- scary movie 3 brenda vs the ring lol
- RINGS behind the scenes
- Rings (2017) - TV Store Prank
Instead, the new results are:
- Cardi B - Ring (feat. Kehlani) [Official Video]
- Samara Sings A Song (The Ring Scary Halloween Parody)
- Rings | Trailer #1 | Paramount Pictures International
I think there is no much variation in the results after all.
来源:https://stackoverflow.com/questions/55064730/youtube-search-operators-in-api-call-booelan-operator-and-or-and-not