Check spelling before making a query [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am writing a small program where I want to extract user input strings from MySQL database. But I am not looking for exact matching strings. For example
If user types amazon then it should extract amazon from the database. But if user types amazonn or amazo or amozon it should still retrive amazon because it is the nearest word to the misspelled word.
This is something similar to google suggestions while searching. Is there anyway to define a function like this in PHP? Do i have to import dictionary and compare with it?

You could use strpos() in two ways
How do I check if a string contains a specific word in PHP?
Search for the DB string in the string that the user inputted.
And the other way around:
Search for the string that the user inputted in the DB string.
The problem with this is that you only cover differences at the outside of the string
such as amazo or amazonn but not amozon
Or you could use levenshtein() and similar_text() as stated in the comments.
Good example code with suggestions:
https://codereview.stackexchange.com/questions/27173/php-spell-checker-with-suggestions-for-misspelled-words
That should be covered in an entirely different way...
I think you want both checks but everything is going to be difficult without a dicitonary so I suggest importing one ;)

Related

MongoDB/PHP: search for string with query [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
EDIT: I solved it. Just need to use "MongoDB\BSON\Regex".
I'm storing books as documents in MongoDB, with the individual pages stored as strings in an array. I'm trying to implement a search page that can take a string and return all documents that contain it. Can this be done directly with a MongoDB query called using PHP (i.e searching for a substring within the string arrays)?
I'm using MongoDB\Driver ( http://php.net/manual/en/book.mongodb.php ) because it was the only option that worked on my machine, and I couldn't find detailed documentation or tutorials for this particular driver. Can anyone help?
Something like
db.table.find({"bookTextField": /.*(the string).*/})
EDIT: Of course, replace table by the table name and bookTextField by the field of the table containing the text

How to find popular search from a set of search strings in php? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have a data set of searches made on a website. I have to find top searches from that data set. The problem is, i cannot think of a way to do it. The search terms are long sentences. How could i find what are users interested in? It seems to be a problem of counting and i am using php. Any suggestion would be appreciated.
You can create a table in database, which will contain columns search_phrase and counter. Each time when user will search same phrase, you'll just increase counter instead of creating new row.
You can also create a script which will take all records from this table, and find similar phrases.
You can make counter corresponding to each phrase. Suppose You have a queries in long sentence format , divide your sentence into smaller parts and identify the most meaningful word and avoid the conjuctions and other verbs. Particularly focus on Nouns. For an eg, Query is : How to Make account on stackoverflow? Possible Solutions[words] : account, stackoverflow,make. Possibly in this way you can solve it.

how to create a better search algorithm than just simple match and search [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
what algorithm will be best suited for the following situation:
Suppose the user enters in search box :- Dell Computers
But in the database this term doesn't exist but what exist is :- Dell
or just :-Computers
so how/what alogrithm can work for the above scenario.
Steps required:
1) Find to see if an exact match exists for "Dell Computers"
2) If not, then check for each word like "Dell" and "Computers"
Moreover i want to implement this in PHP. Any ideas how to do it?
This has been done extensively in the area of Full text searching. Look at Lucene, ElasticSearch, MySQL Full-Text Search, or PostgreSQL Full Text Search.
The basic idea is to create a trie of single keywords pointing to the resulting set of articles/documents, then look up each word separately and do a set intersection of the results to find articles matching both - and fall back on the individual result sets if there are no good intersections.
Add to that stemming of the lookup words, and you're on your way to reimplementing Lucene and friends.

MySQL Algorithm vs Query [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
You find a lot of info on this online. But not what the exact work around of the use of Algorithm is in MySQL. The real basics, if you will..
What a query is, is obvious, of course. What Algorithm does, remains unclear.
Main reason for this question is: to improve profiling & matching records to known users. (In this case: to match docs in a database to users that need them)
Some examples of the usage of it are highly appreciated!
Algorithm is a keyword used with create view in MySQL. The documentation does a pretty good job of explaining it.
The short answer is that MySQL supports two methods of handling views: either "merging" the view definition in the calling code or creating a temporary table. The first is called MERGE and the second TEMPTABLE. In general, MERGE is faster, but most views are TEMPTABLE because of the restrictions on `MERGE.

PHP - Searching for a variable match within another variable [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm stuck with this problem which seems relatively simple. I have a table full of product id numbers stored as variable $partnumber. When processing changes in inventory I need to know if an entire $partnumber string is within another $partnumber string.
For example, I need to know if PRA-LGL70-B2-BKWH-EC-L69A7330 exists within other variable strings such as the ones below.
PRA-LGL70-B2-BKWH-EC-L69A7330
PRA-LGL70-B2-BKWH-EC-L69A7330-L6901
PRA-LGL70-B2-BKWH-EC-L69A7330-L6901-L5156
There are tens of thousands of these partnumbers in a table and I've been told that preg_match might be too slow. Unfortunately, I cannot change the actual data so the only potential delimiter is "-". I'm sorry that I don't have any source code because I just started on this problem. Can anyone point me in right direction?
Without more details it is hard to know the requirements of your problem. As mentioned in the comments, it is probably better to do this in the database. But to directly answer your question - PHP - Searching for a variable match within another variable use strpos():
$partnumber = 'PRA-LGL70-B2-BKWH-EC-L69A7330-L6901';
$search_for = 'PRA-LGL70-B2-BKWH-EC-L69A7330';
if (strpos($partnumber, $search_for)!==false)
echo "Match found";
Note: stripos() will do the same thing, but will not consider case.

Categories