Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP - Search array of sentences for search term(s)?
    primarykey
    data
    text
    <p>So, suppose I have a simple array of sentences. What would be the best way to search it based on user input, and return the closest match?</p> <p>The Levenshtein functions seem promising, but I don't think I want to use them. User input may be as simple as <code>highest mountain</code>, in which case I'd want to search for the sentence in the array that has <code>highest mountain</code>. If that exact phrase does not exist, then I'd want to search for the sentence that has <code>highest</code> AND <code>mountain</code>, but not back-to-back, and so on. The Levenshtein functions work on a per-character basis, but what I really need is a per-word basis.</p> <p>Of course, to some degree, Levenshtein functions may still be useful, as I'd also want to take into account the possibility of the sentence containing the phrase <code>highest mountains</code> (notice the S) or similar.</p> <p>What do you suggest? Are there any systems for PHP that do this that already exist? Would Levenshtein functions alone be an adequate solution? Is there a word-based Levenshtein function that I don't know about?</p> <p>Thanks!</p> <p><strong>EDIT</strong> - I have considered both MySQL fulltext search, and have also considered the possibility of breaking both A) input and B) each sentence into separate arrays of words, and then compared that way, using Levenshtein functions to account for variations in words. (color, colour, colors, etc) However, I am concerned that this method, though possibly clever, may be computationally taxing.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload