Im looking at a way of doing a partial match using a binary search. Here is my code:
public void checkCardIndexForMatches(List<String> wordsToCheck) throws IOException {
String[] cardIndexCache = cardIndexCreator.getCardIndexCache();
for (String text: wordsToCheck){
int i = Arrays.binarySearch(cardIndexCache, text.getText().toLowerCase().trim());
if (i > 0){
text.setCardIndexMatch(true);
}
//check if partial match
// else if
}
}
So its pretty simple stuff so far - there is basically an external file which gets fed in, each line in the file is stored as an array in the cardIndexCache. The problem comes when the user wants to be able to match a 'phrase' in the array (a phrase being more than one word e.g. Mohammed Ali). The words in the wordsToCheck parameter are only passed in as individual words. So the first word will be Mohammed but the binary search fails as it doesnt know what the second word is. I cant think of a simple way of getting the binary search to indicate that a word has the potential to be a match (first part matches, just append the next word and see if that matches).
Any ideas much appreciated!