Twitter search : avoid keyword matching replied username - twitter

The body of a tweet reply is having a list of #username at the beginning.
When you search for a keyword, it can match a username in this list.
For example, searching keyword will match:
Tweet A :
This is an exemple tweet speaking about keyword
Tweet B : (a reply tweet)
#keyword Speaking about random topic
There is multiple solution to exclude tweet replies using -filter:replies or exclude:replies, but it will remove all replies. It won't be possible to match tweet like :
Tweet C :
#username Reply speaking about keyword
Is it possible to search a keyword only within tweet content, without matching to a name in front of a reply tweet ? Having a query to match only Tweet A and C.

Try
[keyword] -from:[keyword] -#[keyword] -to:[keyword]
Where [keyword] is, of course, any keyword you choose.
-from:[keyword] will exclude tweets from the #keyword user
-#[keyword] will exclude tweets mentioning the user #keyword
-to:[keyword] will exclude tweets replying to the user #keyword

Related

Microsoft Graph API: query with $search by multiple fields

I'm trying to query Graph API messages with match on to and subject fields,
i.e.: https://graph.microsoft.com/v1.0/me/mailFolders/SentItems/messages?$search="to:email#example.com AND subject:something"
As I understand strict match search will be performed only if I'll wrap subject in double quotes
$search="to:email#example.com AND subject:"strict match""
This makes query invalid due to " nesting - how should I escape those quotes to make a valid query?
Also assuming I'm looking for a subject like: quote -> ' double quote -> ", how should the search param look like with both: to and subject that contains this example?
Thanks in advance.
You can use backslash operator to escape the double quotes.
https://graph.microsoft.com/v1.0/me/mailFolders/SentItems/messages?$search="to:email#example.com AND subject:\"strict match\""
Have a look at Search Tip and Tricks of the article below for appropriate search query:
https://learn.microsoft.com/en-us/Exchange/policy-and-compliance/ediscovery/message-properties-and-search-operators?view=exchserver-2019#searchable-properties-in-exchange
Search like "subject:\"test\"" returns all the messages where subject line has keyword "test". Strict search "subject:\"my test\"" returns all the messages where subject line has sentence "my test".
Please have a look at Subject searchable property in the article below:
https://learn.microsoft.com/en-us/graph/query-parameters#search-parameter
https://learn.microsoft.com/en-us/Exchange/policy-and-compliance/ediscovery/message-properties-and-search-operators?view=exchserver-2019

How to parse email or phone number parameter?

The parameter email_or_phone_number comes from a client side and I need this for an authentication. However, the model has email and phone number fields separately.
What is the right way to parse the email_or_phone_number attribute, so then I could use find_by to find a user?
find_by(email: email, phone_number: phone_number)
If it's number, then it should become phone_number, but if it's not, then that is supposed to be an email.
A simple readable solution for your question would be using an OR query
Mongoid
User.where(email: params[:email_or_phone_number])
.or(phone_number: params[:email_or_phone_number])
.first
UPDATE Active Record
User.where(email: params[:email_or_phone_number])
.or(User.where(phone_number: params[:email_or_phone_number]))
The other method could be using a Regex for identifying Email Format or Phone Number Format of the value in params[:email_or_phone_number] but I have not come across any which are full proof in case of identifying there formats.
You can split email or number with a regex.
x = {email_or_phone_number:"3333"}
x[:email_or_phone_number].match(/^\d+/)
if x is nil, then
x[:email_or_phone_number].match(/\A([\w+\-]\.?)+#[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i)
else: is not valid input! Save result and pass res to find_by
Assuming that the desired behavior is that searching for 123 matches both greg123#example.com (an email) and 123123123 (a phone number) then the correct query would be:
User.where('email ILIKE :q OR phone ILIKE :q',
q: "%#{params[:email_or_phone]}%")
I'm not sure what your database is but keep in mind that this query may perform poorly on larger datasets. If that's the case I recommend you take a look at pg_trgm (Postgres-only) or full-text search solutions.

Filtering results of a set of matches (Beyond filtering Union)

Here's the scenario. I'm trying to create an inbox of the most recent (multi message) conversations between users in which the most recent message (sent OR received) has a brief preview in the listing.
(as an aside I'm aware of the post UNION filtering issue that's open: https://github.com/neo4j/neo4j/issues/2725) but I'm not sure if my question is fully answered by that.
Let's imagine it displays like this:
User 1's inbox:
user03 - "hey hows it going I..."
user02 - "yo user 2, I saw wh..."
user04 - "did you know I foun..."
user26 - "dear user01 I just ..."
In the graph database conversations are represented with this relationship:
(:User)<-[s:SENDER]-(m:Message)-[r:RECEIVER]->(:User)
Matching this and ordering by m.created_at gets you conversations.
I can easily find messages between specific users and I can easily find all messages that include a given user such as in the following query (given a username of "brendanh":
MATCH (u:User)<-[s:SENDER]-(m:Message)-[r:RECEIVER]->(u2:User)
WHERE (u.username = "brendanh") OR (u2.username = "brendanh")
RETURN m.body, u.username as sender, u2.username as receiver ORDER BY m.created_at DESC
Obviously that previous query gets me ALL messages from or to "brendanh"
Example result rows:
body sender receiver
blah blah blah brendanh user2
foo foo foo user3 brendanh
bar bar bar user2 brendanh
test test brendanh user4
i do not know user3 brendan
Where as what I want is this:
body sender receiver
blah blah blah brendanh user2
foo foo foo user3 brendanh
test test brendanh user4
I can get just a set of unique conversational participants with the following:
MATCH (u:User {username:'brendanh'})<-[]-(m:Message)-[]->(u2:User)
return distinct(u2.username)
But it's not like I can take that list of single usernames and do a "For" match on it returning the first message match for each. (Within the cypher query I mean)
I could collect that list of conversational participants (I'm running this in Golang) and then run a query to the graphdb for each individual result but that seems messy.
I've tried using UNWIND and a list of the usernames from that previously described query that listed conversational partners but again I get every message not just the first message for each user.
Is there something extremely obvious I'm missing here?
Any help is appreciated, thanks!
P.S. Ideally I'd like to limit the number of responses such that if I want to display only the first ten results assuming the user has >10 conversations but that's less important
Not so easy to understand what you want, but I think I got it.
You want each partner to only occur once in the list with their first? message.
Perhaps like this:
MATCH (u:User)<-[r:SENDER|:RECEIVER]-(m:Message)-[:SENDER|:RECEIVER]->(u2:User)
WHERE (u.username = "brendanh")
WITH u2,m,type(r) as action ORDER BY m.created_at DESC
WITH u2,head(collect({type:type(r), msg: m})) as conv
RETURN u2.username, conv.msg.body, conv.type

Query in Rails to fetch from database

I have a table Info(:name, :friend_id) and another table Friends(:id, :network). The attribute :network can be Facebook/Gmail/Linkedin. I want to count all my friends from all services like count of friends from FB, Gmail and Linkedin. I have a friends_list
friends_list = Info.where(:name => my_name)
I don't want to iterate over friends_list and find for each friend_id the normal way. Is there a single line query which can give me the count of all friends from Facebook?
You can use #count with #group, the query might need a little tweaking, but it's generally possible.
friends_counts = Friends.joins(:info).group(:network).where(infos: {name: my_name}).count
This should return an array of hashes, the hash key is the network id, and the hash value is the number of friends in that network.

Get who retweeted me using twitter apis

I want to get users who retweeted my tweets
$tweets2 = $connection->get("https://api.twitter.com/1.1/statuses/retweets_of_me.json");
Gives me list of my tweets which are retweed by other.
But it does not provide me details about who retweeted it. Any way to do this?
CAn I get this details using tweet ID?
In version 1.o
https://api.twitter.com/1/statuses/21947795900469248/retweeted_by.json
it was there but not present in version 2.:
I tried this:
https://api.twitter.com/1.1/statuses/retweet/241259202004267009.json
but does not show anny response
Any idea or help is appreciated.
Scenaraio is like this:
user1 retweets me 5 times, user2 retweets me 7 times, that means I had 12 retweets.
User1 has 500 followers, user2 has 100 followers, that means my retweet reach was 5x500 + 7x100 = 3200. So, on my webpage, I would like to see 12 retweets and 3200 retweet reach.
Use this api https://dev.twitter.com/docs/api/1.1/get/statuses/retweets_of_me to get the ID of the users.
Pass comma-separated user_id or screen_name to this https://dev.twitter.com/docs/api/1.1/get/users/lookup to get the info about the users.

Resources