/    Sign up×
Community /Pin to ProfileBookmark

Search Results

Okay, this is related to my other topic but has become something bigger and different.

I have a JSON file filled with products. Each product broken down into different nodes, Name, Model, Version etc.

Via a search field I want to return the best matches. More words will return a more refined result, comparing different words over different elements in my JSON file.

What’s the best way of doing this in PHP?

Am I best to combine all my Name, Model and Version into a new string within my foreach loop and then doing some kind of match, comparison?

Open to ideas.

https://www.webdeveloper.com/d/397121-regex-help/2

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogOct 10.2021 — > @kiwis80#1638061 I have a JSON file filled with products.

How many products? Any process based on reading and parsing a JSON file and then doing various search actions against it is not going to scale well. On the other hand, if you imported that data into a database (whether SQL or NoSQL) and use its built-in fuzzy search tools, it's bound to be faster and cleaner. For instance, [u][MySQL Full Text Search](https://dev.mysql.com/doc/refman/8.0/en/fulltext-natural-language.html)[/u]
Copy linkTweet thisAlerts:
@kiwisauthorOct 10.2021 — @NogDog#1638062

Ironically, the data comes from mySQL, and I can likely build in a function to search for it.

So if a user enter a search red honda civic saloon

How can I search a products table, using each word to search against different columns?

Also, I want to do a second search for parts table doing the same logic, using each work to search over multiple columns.
Copy linkTweet thisAlerts:
@NogDogOct 11.2021 — You can define a fulltext index to span multiple columns, as in the first example on https://dev.mysql.com/doc/refman/8.0/en/fulltext-natural-language.html (where it matches against title and text columns).
×

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 3.29,
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: @darkwebsites540,
tipped: article
amount: 10 SATS,

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

tipper: Anonymous,
tipped: article
amount: 10 SATS,
)...