[expansion] Adding the ability to search address dictionary phrases with a NULL language, will return phrases in any language
This commit is contained in:
@@ -140,6 +140,10 @@ exit_key_created:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static trie_prefix_result_t get_language_prefix(char *lang) {
|
static trie_prefix_result_t get_language_prefix(char *lang) {
|
||||||
|
if (lang == NULL) {
|
||||||
|
return ROOT_PREFIX_RESULT;
|
||||||
|
}
|
||||||
|
|
||||||
trie_prefix_result_t prefix = trie_get_prefix(address_dict->trie, lang);
|
trie_prefix_result_t prefix = trie_get_prefix(address_dict->trie, lang);
|
||||||
|
|
||||||
if (prefix.node_id == NULL_NODE_ID) {
|
if (prefix.node_id == NULL_NODE_ID) {
|
||||||
@@ -156,7 +160,7 @@ static trie_prefix_result_t get_language_prefix(char *lang) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
phrase_array *search_address_dictionaries(char *str, char *lang) {
|
phrase_array *search_address_dictionaries(char *str, char *lang) {
|
||||||
if (str == NULL || lang == NULL) return NULL;
|
if (str == NULL) return NULL;
|
||||||
|
|
||||||
trie_prefix_result_t prefix = get_language_prefix(lang);
|
trie_prefix_result_t prefix = get_language_prefix(lang);
|
||||||
|
|
||||||
@@ -168,7 +172,7 @@ phrase_array *search_address_dictionaries(char *str, char *lang) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
phrase_array *search_address_dictionaries_tokens(char *str, token_array *tokens, char *lang) {
|
phrase_array *search_address_dictionaries_tokens(char *str, token_array *tokens, char *lang) {
|
||||||
if (str == NULL || lang == NULL) return NULL;
|
if (str == NULL) return NULL;
|
||||||
|
|
||||||
trie_prefix_result_t prefix = get_language_prefix(lang);
|
trie_prefix_result_t prefix = get_language_prefix(lang);
|
||||||
|
|
||||||
@@ -180,7 +184,7 @@ phrase_array *search_address_dictionaries_tokens(char *str, token_array *tokens,
|
|||||||
}
|
}
|
||||||
|
|
||||||
phrase_t search_address_dictionaries_prefix(char *str, size_t len, char *lang) {
|
phrase_t search_address_dictionaries_prefix(char *str, size_t len, char *lang) {
|
||||||
if (str == NULL || lang == NULL) return NULL_PHRASE;
|
if (str == NULL) return NULL_PHRASE;
|
||||||
|
|
||||||
trie_prefix_result_t prefix = get_language_prefix(lang);
|
trie_prefix_result_t prefix = get_language_prefix(lang);
|
||||||
|
|
||||||
@@ -193,7 +197,7 @@ phrase_t search_address_dictionaries_prefix(char *str, size_t len, char *lang) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
phrase_t search_address_dictionaries_suffix(char *str, size_t len, char *lang) {
|
phrase_t search_address_dictionaries_suffix(char *str, size_t len, char *lang) {
|
||||||
if (str == NULL || lang == NULL) return NULL_PHRASE;
|
if (str == NULL) return NULL_PHRASE;
|
||||||
|
|
||||||
trie_prefix_result_t prefix = get_language_prefix(lang);
|
trie_prefix_result_t prefix = get_language_prefix(lang);
|
||||||
|
|
||||||
@@ -512,8 +516,8 @@ bool address_dictionary_save(char *path) {
|
|||||||
return ret_val;
|
return ret_val;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool address_dictionary_module_setup(void) {
|
inline bool address_dictionary_module_setup(char *filename) {
|
||||||
return address_dictionary_load(DEFAULT_ADDRESS_EXPANSION_PATH);
|
return address_dictionary_load(filename == NULL ? DEFAULT_ADDRESS_EXPANSION_PATH: filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
void address_dictionary_module_teardown(void) {
|
void address_dictionary_module_teardown(void) {
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ void address_dictionary_destroy(address_dictionary_t *self);
|
|||||||
bool address_dictionary_load(char *path);
|
bool address_dictionary_load(char *path);
|
||||||
bool address_dictionary_save(char *path);
|
bool address_dictionary_save(char *path);
|
||||||
|
|
||||||
bool address_dictionary_module_setup(void);
|
bool address_dictionary_module_setup(char *filename);
|
||||||
void address_dictionary_module_teardown(void);
|
void address_dictionary_module_teardown(void);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -163,8 +163,8 @@ inline geonames_generic_t *geodb_get(char *key) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool geodb_module_setup(char *dir) {
|
bool geodb_module_setup(char *dir) {
|
||||||
if (db == NULL && dir != NULL) {
|
if (db == NULL) {
|
||||||
return geodb_load(dir);
|
return geodb_load(dir == NULL ? LIBPOSTAL_GEODB_DIR : dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -563,11 +563,11 @@ bool numex_table_save(char *filename) {
|
|||||||
Must be called only once before the module can be used
|
Must be called only once before the module can be used
|
||||||
*/
|
*/
|
||||||
bool numex_module_setup(char *filename) {
|
bool numex_module_setup(char *filename) {
|
||||||
if (filename == NULL) {
|
if (filename == NULL && numex_table == NULL) {
|
||||||
numex_table = numex_table_new();
|
numex_table = numex_table_new();
|
||||||
return numex_table != NULL;
|
return numex_table != NULL;
|
||||||
} else if (numex_table == NULL) {
|
} else if (numex_table == NULL) {
|
||||||
return numex_table_load(filename);
|
return numex_table_load(filename == NULL ? DEFAULT_NUMEX_PATH : filename);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1909,7 +1909,7 @@ bool transliteration_module_setup(char *filename) {
|
|||||||
trans_table = transliteration_table_new();
|
trans_table = transliteration_table_new();
|
||||||
return true;
|
return true;
|
||||||
} else if (trans_table == NULL) {
|
} else if (trans_table == NULL) {
|
||||||
return transliteration_table_load(filename);
|
return transliteration_table_load(filename == NULL ? DEFAULT_TRANSLITERATION_PATH : filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -129,6 +129,7 @@ typedef struct trie_prefix_result {
|
|||||||
size_t tail_pos;
|
size_t tail_pos;
|
||||||
} trie_prefix_result_t;
|
} trie_prefix_result_t;
|
||||||
|
|
||||||
|
#define ROOT_PREFIX_RESULT (trie_prefix_result_t) {ROOT_NODE_ID, 0}
|
||||||
#define NULL_PREFIX_RESULT (trie_prefix_result_t) {NULL_NODE_ID, 0}
|
#define NULL_PREFIX_RESULT (trie_prefix_result_t) {NULL_NODE_ID, 0}
|
||||||
|
|
||||||
trie_prefix_result_t trie_get_prefix(trie_t *self, char *key);
|
trie_prefix_result_t trie_get_prefix(trie_t *self, char *key);
|
||||||
|
|||||||
Reference in New Issue
Block a user