/    Sign up×
Community /Pin to ProfileBookmark

Person Search

I’ve got a list of people objects, the person has a lastname and firstname field.

I’m looking to do a person look up function.

My plan is to loop through and find possible matches on last and then first name based on the search string.

I’m considering using the similar_text method and return results over 65% for example. I’m not sure on that value yet.

Obvious issue is spelling errors.

Are there any other ideas/options out there

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@NogDogMay 27.2021 — What sort of "thing" would you be searching (database, CSV file, JSON file, form input,...)? How many names would that "thing" typically have in it?

Most databases these days -- whether SQL or NoSQL -- have "fuzzy search" mechanisms you could leverage that are likely much more efficient than what we might come up with on the PHP side; so that would be my general preference unless we're talking a pretty small amount of data (for some undefined value of "pretty small").
Copy linkTweet thisAlerts:
@kiwisauthorMay 27.2021 — @NogDog#1632177

The data is stored in a SQL database but populated into a object list. I was just going to create a function searching that list but do you believe searching the database and making a list of objects that match is better?
Copy linkTweet thisAlerts:
@NogDogMay 27.2021 — @kiwis80#1632194 That would be my initial approach -- but then I'm kind of a database-centric developer, so I may be biased. :) Assuming MySQL, the first fairly recent article I found on the FULLTEXT mechanism is https://severalnines.com/database-blog/full-text-searches-mysql-good-bad-and-ugly, and seems like a good quick intro in case it looks attractive to you. (I haven't messed with that stuff in several years now, as at work we're PostgreSQL, and I haven't really had to do fuzzy stuff in it yet.)
Copy linkTweet thisAlerts:
@kiwisauthorMay 27.2021 — @NogDog#1632199

It just seems counter productive to create a person object when it's already created.

Could I get my query string, conduct a SQL search as above - return matched ID's and the pluck them out of my already created list?
Copy linkTweet thisAlerts:
@kiwisauthorMay 27.2021 — Also be honest, this returns zero results even though I have 43 ""JONES" in my database, it's the double SS. similar text would work better or LIKE "%JON%" for shorter would too.

SELECT * FROM table WHERE MATCH(column) AGAINST(“JONESS” WITH QUERY EXPANSION);
Copy linkTweet thisAlerts:
@NogDogMay 28.2021 — Hmm...yeah, I think fulltext match is more for finding relevant matches is larger text strings (like text documents). The [soundex function](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_soundex) might be more applicable for this sort of thing.
[code=sql]
select * from whatever
where last_name sounds like 'joness' and first_name sounds like 'Thom'
[/code]

As to whether it makes sense to do it via MySQL, or use PHP's similar soundex() function is more for you to decide, as you know how your app is structured.
Copy linkTweet thisAlerts:
@kiwisauthorMay 28.2021 — @NogDog#1632209

I've never heard of sounds like. That seems to work okay, the issue is JONESS also finds JAMES so might return too many results this time.
×

Success!

Help @kiwis spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...