« first day (1292 days earlier)      last day (1366 days later) » 

7:24 AM
hi all
anyone?
 
 
7 hours later…
2:02 PM
@Julo0sS howdy! As the topic says, Ask your question, and then hang around a while to see if an expert looks back at their screen and answers it!
@thegreyspot I'm not sure exactly what you mean - can you post an example of your WHERE clause when you search for "'john' or 'Smith'" and an example of your where clause when you search for "John Smith"?
Are you thinking something like (meta_key LIKE 'personnel_%_last_name' AND meta_value LIKE '%john%') OR (meta_key LIKE 'personnel_%_first_name' AND meta_value LIKE '%smith%')?
 
 
5 hours later…
6:56 PM
@TehShrike I am trying to combine the last_name and first_name records so that when a person searches for "john smith" it doesn't return empty.
 
@thegreyspot so what's your case that you're writing queries for?
 
I have the example of the WHERE clause in my original question link. Or are you looking for something else?
 
where the name is a single column? Or two columns?
@thegreyspot you gave one example query, and then said that you had tried two different things
 
I'm working with wordpress so they aren't convenient columns. The values are stored in meta_key and meta_value.
 
And I'm not sure which of those things is what you think you were doing in that query
so, just ignore all that history - moving forward, before I try to give you advice, is the name just a single field, or two fields (first, last)?
 
7:00 PM
Two fields? Not sure. Maybe this will help you: dropbox.com/s/mf7bxd4q4m830tf/…
 
7:11 PM
Sorry, should have @TehShrike you.
 
ok, so, to find that user
what input strings should find that record?
Should both "nancy ramirez" and "ramirez nancy" find that record?
 
Yes that would be nice.
@TehShrike I also have an personnel_%_alias field (it has nicknames) that I would like to be able to include. So say we were looking for Michael Humphries, I should be able to type mike humphries. If we talk about this in programming terms, I'd like to combine all three of the personnel into one string and then run if(stringthatcontainsallthree.indexOf("mike") && stringthatcontainsallthree.indexOf("humphries")) return true;
 
7:28 PM
@thegreyspot so, when building your initial query, you'll first want to do userInputString.split('all whitespace')or whatever
 
Right I have that.
@TehShrike this is what i have: pastebin.com/KNTUaTtM
 
And then, for each word that gets split out of that string, you'll want to do ((meta_key LIKE 'personnel_%_last_name' OR meta_key LIKE 'personnel_%_first_name' OR meta_key LIKE 'personnel_%_nick_name') AND meta_value LIKE '%thatword%')
and you'll want to AND all of those together
But I will say right now that you're using the wrong tool for the job
you should start looking at lucene or elasticsearch or sphinx
because what you have will be slow and will not scale to more than a few rows
 
7:45 PM
@TehShrike Thank you! So this is what i have: pastebin.com/8HCmWRan Look right? It's returning empty though, and Michael Humphries does exist.
 
@thegreyspot does he have published posts?
 
@TehShrike Yes definitely
 
what's the collation of the meta_value column?
or, put another way, does it work if you search for Michael Humphries instead of michael humphries
 
"utf8_general_ci"
@TehShrike No it doesnt. I can search for "michael" and that works
 
what do you get when you SELECT DISTINCT meta_key FROM wp_10_post_meta WHERE meta_value LIKE '%humphries%'
 
7:50 PM
@TehShrike I get the correct results for "%humphries%"
 
which are?
oh I see what's happening
those two bits match different rows
so, ANDing them together will always be false
 
@TehShrike hmm yes...
 
You could SELECT COUNT(wp_10_postmeta. wp_10_postmeta_id) ...
and then compare that to the number of names that you had fed into it (2 in this case) to see if there was a match
 
@TehShrike like this? dropbox.com/s/qjsrr6s6k8dn2qv/… It returned 0
 
@thegreyspot you'll have to change the two name sections to OR instead of AND
and then throw more parens around that whole section
 
8:01 PM
@TehShrike So like this? dropbox.com/s/eb73rslor9tle0v/… There is only one Michael Humphries
 
@thegreyspot right
well wait no
you don't want to count the number of posts
you want to count the number of meta value rows that you found
SELECT COUNT(DISTINCT pm.id)
 
@thegreyspot is meta_id the primary key of the postmeta table?
 
yes sir
 
oh, and you need to group by the user id
then you'll get all the users that matched any of those criteria
and the COUNT will tell you how many of those criteria that they matched
 
8:13 PM
user_id is just the person that created/saved the post
 
8:25 PM
@TehShrike is there no way to AND matching wildcards? The "%" in "personnel_%_first_name" will be the same number as for the same person's "personnel_%_first_name".
 
that's not possible, especially in this case where they're different rows
Did you add in the group by user id?
 
Well like i said, user id is just who saved the post that contains all these fields. it has nothing to do with the field/field row.
@TehShrike the only unique id something like the row "michael Humphries" has, is the number in "personnel_5_first_name", which is consistent across all the fields that michael humphries has. personnel_5_last_name, personnel_5_alias
 
@thegreyspot but aren't you looking for users who published posts?
@thegreyspot yes it does, it's right there in your join
the posts join to the meta rows
 
Wordpress has revisions of posts which is also included in this table, so im filtering out only rows that are published
 
so the post publisher isn't user 5?
 
8:33 PM
I don't care who published the post.
Right
it is not
 
then why are you joining to post?
what do the personnel meta values represent?
what is this query even trying to find?
 
@TehShrike Ok lets start at the beginning
@TehShrike I have this wordpress page this wordpress page dropbox.com/s/jojldif6881anb0/… with custom fields. I'm building a directory of all our employees. These fields are saved into the postmeta table like this: dropbox.com/s/5d3febkhfutqz7t/… <-- this is one employee
Wordpress has multiple revisions history of this page dropbox.com/s/jojldif6881anb0/… stored int he postmeta table, so i join the post table to make sure we are looking at fields that are published and arent just previous revisions
 
but what are you actually trying to retrieve?
users? Pages?
posts? departments?
 
employees/personell
So like in this screenshot, dropbox.com/s/jojldif6881anb0/… , I want to find "john abbot"
@TehShrike
 
9:09 PM
@TehShrike am I out of luck?
 

« first day (1292 days earlier)      last day (1366 days later) »