[geodb] Adding trie search methods for finding geodb phrases

This commit is contained in:
Al
2015-09-16 22:11:10 -04:00
parent e62c75b9c6
commit 87ed7d9a0f
2 changed files with 47 additions and 13 deletions

View File

@@ -61,9 +61,7 @@ geodb_t *geodb_init(char *dir) {
char_array_clear(path);
char_array_cat(path, dir);
char_array_cat(path, PATH_SEPARATOR);
char_array_cat(path, GEODB_BLOOM_FILTER_FILENAME);
char_array_cat_joined(path, PATH_SEPARATOR, PATH_SEPARATOR_LEN, true, 2, dir, GEODB_BLOOM_FILTER_FILENAME);
char *bloom_path = char_array_get_string(path);
@@ -74,17 +72,13 @@ geodb_t *geodb_init(char *dir) {
char_array_clear(path);
char_array_cat(path, dir);
char_array_cat(path, PATH_SEPARATOR);
char_array_cat(path, GEODB_HASH_FILENAME);
char_array_cat_joined(path, PATH_SEPARATOR, PATH_SEPARATOR_LEN, true, 2, dir, GEODB_HASH_FILENAME);
char *hash_file_path = strdup(char_array_get_string(path));
char_array_clear(path);
char_array_cat(path, dir);
char_array_cat(path, PATH_SEPARATOR);
char_array_cat(path, GEODB_LOG_FILENAME);
char_array_cat_joined(path, PATH_SEPARATOR, PATH_SEPARATOR_LEN, true, 2, dir, GEODB_LOG_FILENAME);
char *log_path = char_array_get_string(path);
@@ -133,6 +127,41 @@ bool geodb_load(char *dir) {
}
bool search_geodb_with_phrases(char *str, phrase_array **phrases) {
if (str == NULL) return false;
return trie_search_with_phrases(address_dict->trie, str, phrases);
}
phrase_array *search_geodb(char *str) {
phrase_array *phrases = NULL;
if (!search_geodb_with_phrases(str, &phrases)) {
return NULL;
}
return phrases;
}
bool search_geodb_tokens_with_phrases(char *str, token_array *tokens, phrase_array **phrases) {
if (str == NULL) return false;
return trie_search_tokens_with_phrases(address_dict->trie, str, tokens, phrases);
}
phrase_array *search_geodb_tokens(char *str, token_array *tokens) {
phrase_array *phrases = NULL;
if (!search_address_dictionaries_tokens_with_phrases(str, tokens, &phrases)) {
return NULL;
}
return phrases;
}
geonames_generic_t *geodb_get_len(char *key, size_t len) {
if (db == NULL || db->hash_reader == NULL || db->log_iter == NULL) return NULL;
sparkey_returncode ret = sparkey_hash_get(db->hash_reader, (uint8_t *)key, len, db->log_iter);
@@ -162,6 +191,8 @@ inline geonames_generic_t *geodb_get(char *key) {
return geodb_get_len(key, strlen(key));
}
bool geodb_module_setup(char *dir) {
if (db == NULL) {
return geodb_load(dir == NULL ? LIBPOSTAL_GEODB_DIR : dir);

View File

@@ -1,8 +1,6 @@
#ifndef GEONAMES_DICTIONARY_H
#define GEONAMES_DICTIONARY_H
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
@@ -59,9 +57,14 @@ void geodb_module_teardown(void);
void geodb_destroy(geodb_t *self);
// Trie search
bool search_geodb_with_phrases(char *str, phrase_array **phrases);
phrase_array *search_geodb(char *str);
bool search_geodb_tokens_with_phrases(char *str, token_array *tokens, phrase_array **phrases);
phrase_array *search_geodb_tokens(char *str, token_array *tokens);
geonames_generic_t *geodb_get_len(char *key, size_t len);
geonames_generic_t *geodb_get(char *key);
#endif