gtrendsR icon indicating copy to clipboard operation
gtrendsR copied to clipboard

Or query has less results than individual terms

Open MikeDisher opened this issue 7 years ago • 19 comments

I'm having trouble understanding results from an or-query. When I do the following or-query for searches for dog or cat by DMA, I get results for about 73 DMAs, with 140 or so "NA" results:

res <-gtrends('dog+cat', geo= c("US"), time ="2017-01-01 2018-01-01") res$interest_by_dma

Seemingly, most DMAs don't search cat or dog very much. However, if I run the following commands for just dog, I get results for every single DMA:

res <-gtrends('dog', geo= c("US"), time ="2017-01-01 2018-01-01") res$interest_by_dma

How is it possible that search volume for Cat or Dog is less than that for just Dog? What's wrong here? Thanks so much.

MikeDisher avatar Mar 07 '18 16:03 MikeDisher

Me as well, but this problem exists on the google trends website as well.

genann86 avatar Jun 15 '18 07:06 genann86

Try to compare what Google returns and what we return. If they are the same, then we can't do anything about it.

PMassicotte avatar Jun 15 '18 11:06 PMassicotte

Hi sorry when I check now it works. for example on the website i get 78 cities for gtrends(c("apple + pear"),geo=("GB"), time=("2016-01-01 2016-12-31")) $interest_by_city

but in gtrendsR i get only London. It does indeed seem to be reading it as an 'and' as opposed to an 'OR'. # # #277

genann86 avatar Jun 27 '18 14:06 genann86

Sorry, I am now following the same @genann86 project, and I am stuck in the same problem: it reads the plus as an AND and not as an OR. Does anyone know if it there is a way to fix this?

marcoguidopalladino avatar Sep 11 '18 16:09 marcoguidopalladino

I have the same problem. It seems that + is indeed taken as AND, whereas it is used for OR on Google Trends. Here is the comparison:

res <- gtrends(keyword = c('adidas+nike', 'adidas', 'nike', 'adidas nike'))

This produces the same results for the first and the last keywords, whereas they are vastly different on Google Trends:

image

Anyone with some bright ideas?

tikim1 avatar Oct 06 '18 19:10 tikim1

What would be the "AND" then?

PMassicotte avatar Oct 07 '18 18:10 PMassicotte

Here are the search tips from Google that include various operators:

https://support.google.com/trends/answer/4359582?hl=en

tikim1 avatar Oct 07 '18 21:10 tikim1

For adidas nike:

https://trends.google.fr/trends/api/widgetdata/multiline/csv?req=%7B%22time%22%3A%222017-10-09%202018-10-09%22%2C%22resolution%22%3A%22WEEK%22%2C%22locale%22%3A%22fr%22%2C%22comparisonItem%22%3A%5B%7B%22geo%22%3A%7B%22country%22%3A%22FR%22%7D%2C%22complexKeywordsRestriction%22%3A%7B%22keyword%22%3A%5B%7B%22type%22%3A%22BROAD%22%2C%22value%22%3A%22adidas%20nike%22%7D%5D%7D%7D%5D%2C%22requestOptions%22%3A%7B%22property%22%3A%22%22%2C%22backend%22%3A%22IZG%22%2C%22category%22%3A0%7D%7D&token=APP6_UEAAAAAW73qeTVfoh22C1H8OdqRY0ZrVheexeI6&tz=240

"https://trends.google.fr/trends/api/widgetdata/multiline/csv?req={\"time\":\"2017-10-09 2018-10-09\",\"resolution\":\"WEEK\",\"locale\":\"fr\",\"comparisonItem\":[{\"geo\":{\"country\":\"FR\"},\"complexKeywordsRestriction\":{\"keyword\":[{\"type\":\"BROAD\",\"value\":\"adidas nike\"}]}}],\"requestOptions\":{\"property\":\"\",\"backend\":\"IZG\",\"category\":0}}&token=APP6_UEAAAAAW73qeTVfoh22C1H8OdqRY0ZrVheexeI6&tz=240"

For adidas+nike:

https://trends.google.fr/trends/api/widgetdata/multiline/csv?req=%7B%22time%22%3A%222017-10-09%202018-10-09%22%2C%22resolution%22%3A%22WEEK%22%2C%22locale%22%3A%22fr%22%2C%22comparisonItem%22%3A%5B%7B%22geo%22%3A%7B%22country%22%3A%22FR%22%7D%2C%22complexKeywordsRestriction%22%3A%7B%22keyword%22%3A%5B%7B%22type%22%3A%22BROAD%22%2C%22value%22%3A%22adidas%22%7D%2C%7B%22type%22%3A%22BROAD%22%2C%22value%22%3A%22nike%22%7D%5D%2C%22operator%22%3A%22OR%22%7D%7D%5D%2C%22requestOptions%22%3A%7B%22property%22%3A%22%22%2C%22backend%22%3A%22IZG%22%2C%22category%22%3A0%7D%7D&token=APP6_UEAAAAAW73qU3c1t3b3IFZbUaIT2j4mBKJB2BCD&tz=240

"https://trends.google.fr/trends/api/widgetdata/multiline/csv?req={\"time\":\"2017-10-09 2018-10-09\",\"resolution\":\"WEEK\",\"locale\":\"fr\",\"comparisonItem\":[{\"geo\":{\"country\":\"FR\"},\"complexKeywordsRestriction\":{\"keyword\":[{\"type\":\"BROAD\",\"value\":\"adidas\"},{\"type\":\"BROAD\",\"value\":\"nike\"}],\"operator\":\"OR\"}}],\"requestOptions\":{\"property\":\"\",\"backend\":\"IZG\",\"category\":0}}&token=APP6_UEAAAAAW73qU3c1t3b3IFZbUaIT2j4mBKJB2BCD&tz=240"

Looking at the decoded URL, the interesting part is:

{\"keyword\":[{\"type\":\"BROAD\",\"value\":\"adidas\"},{\"type\":\"BROAD\",\"value\":\"nike\"}],\"operator\":\"OR\"}

One would need to split the query string into subsets. Any help welcome :)

PMassicotte avatar Oct 09 '18 12:10 PMassicotte

Also the "quoted" case of "adidas nike":

https://trends.google.fr/trends/api/widgetdata/multiline/csv?req=%7B%22time%22%3A%222017-10-09%202018-10-09%22%2C%22resolution%22%3A%22WEEK%22%2C%22locale%22%3A%22fr%22%2C%22comparisonItem%22%3A%5B%7B%22geo%22%3A%7B%22country%22%3A%22FR%22%7D%2C%22complexKeywordsRestriction%22%3A%7B%22keyword%22%3A%5B%7B%22type%22%3A%22PHRASE%22%2C%22value%22%3A%22adidas%20nike%22%7D%5D%7D%7D%5D%2C%22requestOptions%22%3A%7B%22property%22%3A%22%22%2C%22backend%22%3A%22IZG%22%2C%22category%22%3A0%7D%7D&token=APP6_UEAAAAAW73sT2fGMYWP73FEj12B2R9DyIRc0y5l&tz=240

"https://trends.google.fr/trends/api/widgetdata/multiline/csv?req={\"time\":\"2017-10-09 2018-10-09\",\"resolution\":\"WEEK\",\"locale\":\"fr\",\"comparisonItem\":[{\"geo\":{\"country\":\"FR\"},\"complexKeywordsRestriction\":{\"keyword\":[{\"type\":\"PHRASE\",\"value\":\"adidas nike\"}]}}],\"requestOptions\":{\"property\":\"\",\"backend\":\"IZG\",\"category\":0}}&token=APP6_UEAAAAAW73sT2fGMYWP73FEj12B2R9DyIRc0y5l&tz=240"

But it looks like we can do it already:


library(gtrendsR)
res <- gtrends(keyword = c("adidas nike", "\"adidas nike\""))
plot(res)

Created on 2018-10-09 by the reprex package (v0.2.1)

PMassicotte avatar Oct 09 '18 12:10 PMassicotte

hi, sorry to post again on that issue but I didn't find if the query1 + query2 is now possible with the package? cheers

lemairev avatar Dec 26 '18 20:12 lemairev

Not right now bt working on it.

PMassicotte avatar Dec 26 '18 20:12 PMassicotte

thank you very much for working on it and the prompt reply

lemairev avatar Dec 26 '18 20:12 lemairev

Thank you for providing this great package! I was wandering if there are updates on the "or query".

'res <- gtrends(keyword = c("adidas nike", ""adidas nike"")) ' does not work for me, when i use other serach terms, e.g. 'res <- gtrends(keyword = c("vienna feldkirch", ""vienna feldkirch""))'.

best

seschaub avatar Dec 03 '19 09:12 seschaub

Use res <- gtrends(keyword = c("adidas nike", "\"adidas nike\"")) as mentioned above. It should work.

JBleher avatar Dec 03 '19 21:12 JBleher

Concerning the OR operator + should be supported now since #311. E.g. plot(gtrends(keyword=c("opel + astra", "opel", "astra"),time='2004-01-01 2018-05-31', gprop ='web', geo ='' ,hl='en-US',cat = "0"))

JBleher avatar Dec 03 '19 21:12 JBleher

Thanks for the fast answer. I tried it today for the tennis example. Unfortunately it doesnt work. Also not when installing the developer version.

I used: plot(gtrends(c("tennis","tennis shoes","tennis+shoes","tennis -shoes"),time = "all"))

Do I miss something?

Cheers

tennis

seschaub avatar Dec 05 '19 17:12 seschaub

Try it again. The dev version, did not include my PR yet. Sorry for that. My result for the example is the following. Rplot

JBleher avatar Dec 11 '19 10:12 JBleher

Hey! thanks for the efforts.

For now I am running into issues loading the developer version:

Error in i.p(...) : (converted from warning) installation of package ‘FILE_PATH' had non-zero exit status in R’ had non-zero exit status

Thanks a lot.

seschaub avatar Dec 19 '19 12:12 seschaub

Most likely not related to the package.

PMassicotte avatar Dec 19 '19 15:12 PMassicotte