Twitter api - search too complex? - search

Any idea why Twitter is throwing this error?
GET https://search.twitter.com/search.json?q=Middle%20Tennessee%20State%20Blue%20Raiders%20Florida%20International%20Golden%20Panthers%20win%20OR%20lose%20-rt%20-from%3Aespn&&lang=en&since=2011-02-09: 403: Sorry, your query is too complex. Please reduce complexity and try again.

As of August 2011, at least, it appears max query string length is quite high. It worked fine for me with a maxlength of 300; when I moved to 500 characters I ended up with three queries, the 2nd of which failed:
q1: OK: 491 characters, 23 OR clauses
q2: FAILED: 493 characters, 39 OR clauses
q3: OK: 203 characters, 17 OR clauses
So, it might turn out to be 492+ characters, or it might be 24+ clauses. I suspect some combination.
I've not spent more time narrowing it down further, as if the guidelines were fixed then Twitter would publish them. I'm going to split my queries at 300 characters or 20 clauses, whichever comes first, and hope that is reasonably future-proof.
UPDATE: Under "Best Practices" on https://dev.twitter.com/docs/using-search they suggest limiting a query to 10 clauses. Obviously from my above results it is not the current hard limit, but 10 should be the future-proof limit I was after.
P.S. Back to the actual question, I notice you have a "&&" typo in your query. It wonder if this could have triggered the complaint? (untested idea)

On 8th February 2018:
Twitter search limites to 50 OR clauses (Notice 50 OR clauses contains 49 OR because for example word1 OR word2 contains two clauses and one OR).
Twitter search limites to 500 characters.
My test for the OR clause is:
This search works: h1 OR h2 OR h3 OR h4 OR h5 OR h6 OR h7 OR h8 OR h9 OR h10 OR h11 OR h12 OR h13 OR h14 OR h15 OR h16 OR h17 OR h18 OR h19 OR h20 OR h21 OR h22 OR h23 OR h24 OR h25 OR h26 OR h27 OR h28 OR h29 OR h30 OR h31 OR h32 OR h33 OR h34 OR h35 OR h36 OR h37 OR h38 OR h39 OR h40 OR h41 OR h42 OR h43 OR h44 OR h45 OR h46 OR h47 OR h48 OR h49 OR h50
However, if we add: OR h51, it fails
My test for the characters count is:
This search works (500 characters): hell1 OR hell2 OR hell3 OR hell4 OR hell5 OR hell6 OR hell7 OR hell8 OR hell9 OR hell10 OR hell11 OR hell12 OR hell13 OR hell14 OR hell15 OR hell16 OR hell17 OR hell18 OR hell19 OR hell20 OR hell21 OR hell22 OR hell23 OR hell24 OR hell25 OR hell26 OR hell27 OR hell28 OR hell29 OR hell30 OR hell31 OR hell32 OR hell33 OR hell34 OR hell35 OR hell36 OR hell37 OR hell38 OR hell39 OR hell40 OR hell41 OR hell42 OR hell43 OR hell44 OR hell45 OR hell46 OR hell47 OR hell48 OR hell49 OR hell50abcdefghijklm
However, if we add the n (501 characters) to the last word (hell50abcdefghijklmn), it fails.
Notice I have just realised that if we remove the character o to the word hello, the result is hell (is the World sending me a message? xD)

Read the documentation. "Queries are limited 140 URL encoded characters." You query string is 156 characters.

Related

Trim, Mid, substitute, len for the word following the space after a ~ character

I have various strings with varying length and word placement. The pattern is however, every time a word is found with "~" in front of it, I need to pull the word after the space following it. I've researched quite a bit on mid, left, right, etc functions, but have still not been able to come up with the result I need.
Here are 2 examples of strings:
TRANSACTION FEE: SOLD -1 1/1/2/2 ~IRON_CONDOR MA 100 18 MAR 22 385/390/305/300 CALL/PUT #2.37
TRANSACTION FEE: BOT +1 ~VERTICAL
ANTM 100 (Weeklys) 4 MAR 22 480/485 CALL #.63
For number 1, "MA" should be the result. For number 2, "ANTM" should be the result.
Below are two formulas that seem to get me close to what I'm looking for, but I'm unable to connect the finished result because I just don't understand enough about them. My trials often result in errors haha erg.
=MID(A2,FIND("~",A2)+1,FIND(" ",A2,FIND(" ",A2)+1)-FIND(" ",A2)) '//This doesn't work because it returns "Iron_" for number 1 and "Verti" for number 2
=TRIM(MID(SUBSTITUTE(TRIM($A2)," ",REPT(" ",LEN($A2))), (7-1)*LEN($A2)+1, LEN($A2))) '//This doesn't work because the word needed isn't always the 7th word.
=TRIM(MID(SUBSTITUTE(A2," ",REPT(" ",99)),MAX(1,FIND("~",SUBSTITUTE(A2," ",REPT(" ",99)))-50),99)) '//This returns the word that starts with the "~", but I need the word following it
I'm looking for an efficient formula that will 1st search for the word position that starts with the tilde "~" and then return the word following the space after that.
Anyone familiar with this that could offer a working solution?
In B2, formula copied down :
=TRIM(MID(SUBSTITUTE(MID(A2,FIND("~",A2),99)," ",REPT(" ",99)),99,99))
And,
Your 3rd formula could be modified to this in obtain the target result :
=TRIM(MID(SUBSTITUTE($A2," ",REPT(" ",99)),MAX(1,FIND("~",SUBSTITUTE($A2," ",REPT(" ",99)))+99),99))
Try this:
=LEFT(MID(RIGHT(A1,LEN(A1)-FIND("~",A1)),FIND(" ",RIGHT(A1,LEN(A1)-FIND("~",A1)+1)),LEN(A1)),FIND(" ",MID(RIGHT(A1,LEN(A1)-FIND("~",A1)),FIND(" ",RIGHT(A1,LEN(A1)-FIND("~",A1)+1)),LEN(A1))))

Finding Last Name while ignoring Suffixes

I have a field that has first and last names. Some names include a middle initial, some names include a suffix.
I am trying to find a formula that only pulls the last name regardless of which format it is in.
Example format
Donald P Bellisario --> Bellisario
Dale Earnhardt Jr --> Earnhardt
Jimmy M Butler III--> Butler
Kanye E West--> West
Joseph Biden--> Biden
Formula 1: =TRIM(RIGHT(SUBSTITUTE(AS9," ",REPT(" ",LEN(AS9))),LEN(AS9)))
Formula 2:=RIGHT(AS9,LEN(AS9)-FIND("*",SUBSTITUTE(AS9," ","*",LEN(AS9)-LEN(SUBSTITUTE(AS9," ","")))))
Formula 1 and 2 do not ignore suffixes and will list those if existent Jack Smith Jr--> Jr
Formula 3: =SUBSTITUTE(TRIM(RIGHT(SUBSTITUTE(TRIM(SUBSTITUTE($AS9,IFERROR(RIGHT($AS9,LEN(AS9)-FIND(" ",$AS9)-10),""),""))," ",REPT(" ","99")),99)),",","")
Formula 3 will only include 10 characters after the end of the first name without displaying the middle initial. E.G(Heisenberger--> Heisenberg)
Truth is, working with names can be subject to various edge-cases that will prove a working solution wrong at some point. But for those samples shown I'd use FILTERXML() to "split" these input strings on the spaces and use xpath expressions to filter out those substrings:
Formula in B1:
=FILTERXML("<t><s>"&SUBSTITUTE(A1," ","</s><s>")&"</s></t>","//s[translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ.', '')!=''][translate(., 'aeiouAEIOU', '')!=.][last()]")
The trick here is that there are three coherent xpath expressions working together:
[translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ.', '')!=''] - Assert that node is not nothing when all uppercase and dots have been substituted with nothing.
[translate(., 'aeiouAEIOU', '')!=.] - Assert that node is not equal to its original node when all vowels (upper- and lowercase) have been substituted with nothing.
[last()] - The last() function returns an integer equal to the context size from the expression evaluation context, and thus it will return the last node that compiled testing against previous expressions.
I'd guess that depending on possible edge-cases you could add more rules to the equation. For a more comprehensive insight on these expressions you could have a look here.
Good luck.

Nesting 6 IF statements in excel 2017 and get the #NAME? error

Im trying to nest 6 IF statements in my excel spread sheet but I get the error #NAME? which I know is most likely a syntax error.
However I cant find the syntax error. I read online that you can nest up to 7 IF statements, does this not apply to Excel 2017?
Heres my function:
=IF(AND(F2=KWILA, B14=0.14), B38, IF(AND(F2=KWILA, B14=0.9), C38, IF(AND(F2=VITEX, B14=0.9), C39, IF(AND(F2=PINE, B14=0.14), B40, IF(AND(F2=PINE, B14=0.9), C40, IF(AND(F2=MACRO, B14=0.14), B41, H2))))))
Can someone help me please?
When combining functions in a formula, start simple, with a single function. Get it working and producing the result you want before making it more complex by adding a second function (or five more).
Since your question doesn't include an example of the data you're working with, I can't be sure of the issue, but I suspect you're trying to compare the text (strings) like KWILA to the cells (like A2).
If so, the problem is that text (strings) needs to be enclosed in "Quotation Marks".
Almost every time I more than 2 nested IF's, there's usually a more efficient way to accomplish the same thing.
In this cas, I split up the formula in Notepad to see what the goal is:
=IF(
AND(F2=KWILA, B14=0.14), B38
AND(F2=KWILA, B14=0.9), C38,
AND(F2=VITEX, B14=0.9), C39,
AND(F2=PINE, B14=0.14), B40,
AND(F2=PINE, B14=0.9), C40,
AND(F2=MACRO, B14=0.14), B41,
...if none of the above: H2
I encourage you to double check your criteria above - since, at first glance, it looks like a "broken pattern". For example there are two 38's, one 39, two 40's and one 41.
Assuming it's correct, I look for anything I can group, and I see that there are only 2 options for B14. So I regroup:
=IF(B14=0.14,
IF( F2=KWILA, B38
F2=PINE, B40,
F2=MACRO, B41,
IF(B14=0.9,
IF( F2=KWILA, C38,
F2=VITEX, C39,
F2=PINE, C40,
...if none of the above: H2
I also noticed that there are only 4 options for F2, so I considered using CHOOSE instead of IF but I'm not sure how B14 relates the the rest of the data (since it wasn't posted) so we'll stick with this simplification for now.
Midway through putting it "back together" I have:
=IF(B14=0.14,
IF( F2=KWILA, B38, if( F2=PINE, B40, if( F2=MACRO, B41, h2 ))),
IF(B14=0.9,
IF( F2=KWILA, C38, if( F2=VITEX, C39, if( F2=PINE, C40, h2 )))
h2 )
basically 2 set of IF statements. Note that I used H2 three times for "else confitions" -I'm not happy with this and I can almost guarantee there's a better way, but again, without seeing your data.....
Put back into a formula, we get a slightly more manageable:
=IF(B14=0.14,IF(F2="KWILA",B38,IF(F2="PINE",B40,IF(F2="MACRO",B41,H2))),
IF(B14=0.9,IF(F2="KWILA",C38,IF(F2="VITEX",C39,IF(F2="PINE",C40,H2))),H2))
I can't guarantee this will work since I wasn't able to test it, since... no data included in the question. You don't need to switch to this if your method works after adding the quotes.
There are still other alternate way this could have been simplified (and easier to understand or change later) which I won't get into now. Personally, I would have put the values in a table on another worksheet, and used INXDEX/MATCH to get the values I needed.
-

VLOOKUP with conditions

I have an issue at the moment which I'm not able to resolve even with multiple combinations of If and Vlookups. I'm not doing this right.
I have a sheet which has the names of the products and an empty column for the Sl Number. The Sl number needs to be retrieved from Sheet 2 if it matches the value in the adjacent cell of the formula (This I know can be possible with Vlookup). However, I am trying to display the value even if the match is not exact. By that I mean if the product name has all the values as on the sheet 1 but also has additional information in brackets, then the value should still be displayed.
Sheet 1
Formula in A2 - A7 = "=VLOOKUP(B2, Sheet2!B:E, 2, 0)"
Sheet 2
The complete data
Is this possible?
Thanks in advance.
Apologies, I'm new here and not sure how this works. So trying to do the right thing but may take some time.
Thanks Frank and Tim. I have another extended question to this.
Is there a way to retrieve the value by ignoring text in brackets on the lookup cell itself?
For example:
Sheet 1
Sl Number Name
123454 Cream SPF 30+ 50g
**NA** Bar Chocolate 70g X 6 (Sample)
234256 Hand Wash 150ml
26786 Toothpaste - Whitening 110g
Sheet 2
ID Name Sl number Manufacturer Quantity
8 Collagen Essence 10ml 456788 AL 87
9 Hand Wash 150ml 234256 AD 23
10 Bar Chocolate 70g X 6 835424 AU 234
Row 2 on Sheet 1 has the name that includes (Sample) and the same product on sheet 2 does not contain the (Sample) for that product. Is there a way I can use lookup in the above scenario?
Thank you
Tim's comment
=VLOOKUP(B2 & "*", Sheet2!B:E, 2, 0) as long as the "Extra" info is tagged onto the end of the name, and none of your product names is a
substring of another product name. – Tim Williams 53 mins ago
Will get what you are looking for, as for getting rid of text between "(...)" use
=IFERROR(IF(FIND("(",A2),LEFT(A2,FIND("(",A2)-1),A2),A2)
To create a new column that will cut out anything that has parentheses "(...)" this presumes that all of your entries has the "(...)" at the end, i.e. far right side.
As you are new, I presume you might be interested in an explanation. I'll explain what Tim and I did. If I am incorrect, anyone is free to edit.
Based on your question, it would appear that you are familiar with Excel but not the site. This said, my understanding of the key difference between your attempt and Tim's was =VLOOKUP(B2 & "*", Sheet2!B:E, 2, 0) or specifically & "*". This introduces a Wildcard to the search parameter. So if you typed "Bob" but the actual reference was "Bob's Burger" That "*" would allow ['s Burger] to be included as part of the possible search given that you set vLookup to search for Approximate rather than exact matches. =VLOOKUP(B2 & "*", Sheet2!B:E, 2, 0) specifically , 0).
As for my part, IFERROR is effectively an catch-all for errors in IF functions. If there is a error, then X. In this case, if it does not find "(" in the cell, then it will throw an error. Since it is an error, display the original cell.
As for IF(FIND("(",A2),LEFT(A2,FIND("(",A2)-1),A2) It asks Excel to look for "(" in the cell A2, if it finds it, then it it counts from the LEFT until it finds the "(" and deletes the text one space to the left of the first "(". Thus removing the "(...)".

Excel: Overcome value error with MID

I want to check if the second digit in a number is 0
Example:
101 --> yes
605 --> yes
234 --> no
I wrote this formula
=IF(AND(C9>100;C9<909;VALUE(MID(C9;2;1))=0);"Yes";"No")
when the number I'm checking is less than 12 I get a #Value error. I know it has to do with MID, but I thought that the first 2 conditions are calculated first.
#Value error come from VALUE function feed invalid text so it can generate valid result, good news is it can be removed in this case, but 0 must be quoted so treated as text
=IF(AND(C9>100;C9<909;MID(C9;2;1)="0");"Yes";"No")

Resources