CountryCode Searching

22 views
Skip to first unread message

Ali Shahbour

unread,
Oct 17, 2016, 3:22:56 AM10/17/16
to concurrent-trees-discuss
I am using ConcurrentRadixTree to get the Country Code out of a phone number , by adding all country code numbers to the radixtree and they using getClosestKeys it is working perfectly except when i receive a wrong number (i mean i number that is fake and does not have a valid country code) for example :

The Tree is filled with countryCode 81,82,84,85 .. and i am trying to get the code of 83123123123

In this case i am getting back a list of keys 81,82,84,85 . as they all start with 8 but to me it is wrong i need the whole key to be included in the text i am searching for so i should get null

Is their any method that can do that directly ?


Ali Shahbour

unread,
Oct 17, 2016, 3:36:43 AM10/17/16
to concurrent-trees-discuss
An example of what i am doing and how i am fixing it

 RadixTree<Integer> operatorsTree = new ConcurrentRadixTree<Integer>(new DefaultCharArrayNodeFactory());
operatorsTree.put(Integer.toString(81),1);
operatorsTree.put(Integer.toString(82),2);

Iterable<KeyValuePair<Integer>> result = operatorsTree.getKeyValuePairsForClosestKeys("84344434");

if(result.iterator().hasNext()) {
KeyValuePair<Integer> firstresult = result.iterator().next();
// Wrong result to my case to fix it i am checking if the return code is a substring of the initial value
if("84344434".startsWith(firstresult.getKey().toString()))
log.info("{}",firstresult.getValue());
}

result = operatorsTree.getKeyValuePairsForClosestKeys("812323232");

if(result.iterator().hasNext()) {
KeyValuePair<Integer> firstresult = result.iterator().next();
if("812323232".startsWith(firstresult.getKey().toString()))
log.info("{}",firstresult.getValue());
}
}

Niall

unread,
Nov 2, 2016, 5:44:41 PM11/2/16
to concurrent-trees-discuss
I'm not sure I understand the problem completely, but have you tried to use the InvertedRadixTree's InvertedRadixTree.getKeysPrefixing() method for this?

It will return the set of keys in the tree which prefix the given document.
Reply all
Reply to author
Forward
0 new messages