aartiles
aartiles

Reputation: 1489

Search for people by name in FQL

I'm trying to develop a search for people by name feature using the Facebook API.

I'm trying this FQL query:

SELECT uid, username, name, pic_square FROM user WHERE strpos(name, 'Alfredo Artiles') >= 0

But I get an "Your statement is not indexable. The WHERE clause must contain an indexable column." error.

I also tried to add a "and uid > 0" condition, but that didn't work too.

Any idea?

Upvotes: 3

Views: 11317

Answers (4)

YES, YOU CAN!!!

Try to search in profile table, instead of user table. In profile table, the name field is indexable, so your statement would have to change only a bit:

SELECT id, username, name, pic_square FROM profile WHERE contains('alfredo artiles') and type='user'

Contains is not case-sensitive while strpos is. You could still use lower and strpos, but you would also have the problem of special characters. Contains is the solution.

You can find all fields of profile table in facebook doc:

Hope it helps!

Upvotes: 0

misterjinx
misterjinx

Reputation: 2616

later edit

Ok, sorry for the mistake regarding strpos, I didn't remeber it existence last time i checked the fql docs. The thing about it is that it can be used just in certain cases. You need to have a primar indexable column in your where clause and a second condition with strpos (at least this is how I succeded using it). For example:

SELECT actor_id, message FROM stream WHERE source_id = me() AND strpos(message, 'stuff') > 0 limit 50

I hope this clarifies a little bit the confusion with this function.

Upvotes: 4

Prabin Tp
Prabin Tp

Reputation: 766

U need to specify the uid in where clause fetch details in facebook user table. we don't get the the all user details.here get the details of currently logged in user

"SELECT name FROM user WHERE uid IN(SELECT uid2 FROM 
friend WHERE uid1 = me()) AND strpos(name,'Alfredo Artiles') >=0"

Upvotes: 0

Narcolessico
Narcolessico

Reputation: 1941

SELECT uid, username, name, pic_square FROM user WHERE contains('Alfredo Artiles')

I have no idea why it works, as it violates the "at least and indexable field in WHERE", but it does.

EDIT: this is where I read it: link

Upvotes: 6

Related Questions