summaryrefslogtreecommitdiff
path: root/src/storage/phrase_large_table3_bdb.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/storage/phrase_large_table3_bdb.cpp')
-rw-r--r--src/storage/phrase_large_table3_bdb.cpp61
1 files changed, 59 insertions, 2 deletions
diff --git a/src/storage/phrase_large_table3_bdb.cpp b/src/storage/phrase_large_table3_bdb.cpp
index 1576ca2..da2e6f2 100644
--- a/src/storage/phrase_large_table3_bdb.cpp
+++ b/src/storage/phrase_large_table3_bdb.cpp
@@ -41,8 +41,7 @@ inline int compare_phrase(ucs4_t * lhs, ucs4_t * rhs, int phrase_length) {
/* keep dbm key compare function inside the corresponding dbm file
to get more flexibility. */
-static bool bdb_phrase_continue_search(DB *db,
- const DBT *dbt1,
+static bool bdb_phrase_continue_search(const DBT *dbt1,
const DBT *dbt2) {
ucs4_t * lhs_phrase = (ucs4_t *) dbt1->data;
int lhs_phrase_length = dbt1->size / sizeof(ucs4_t);
@@ -208,6 +207,64 @@ int PhraseLargeTable3::search(int phrase_length,
return result;
}
+int PhraseLargeTable3::search_suggestion(int phrase_length,
+ /* in */ const ucs4_t phrase[],
+ /* out */ PhraseTokens tokens) const {
+ int result = SEARCH_NONE;
+
+ if (NULL == m_db)
+ return result;
+ assert(NULL != m_entry);
+
+ DBC * cursorp = NULL;
+ /* Get a cursor */
+ int ret = m_db->cursor(m_db, NULL, &cursorp, 0);
+ if (ret != 0)
+ return result;
+
+ DBT db_key1;
+ memset(&db_key1, 0, sizeof(DBT));
+ db_key1.data = (void *) phrase;
+ db_key1.size = phrase_length * sizeof(ucs4_t);
+
+ DBT db_data;
+ memset(&db_data, 0, sizeof(DBT));
+ /* Get the prefix entry */
+ ret = cursorp->c_get(cursorp, &db_key1, &db_data, 0);
+ if (ret != 0) {
+ cursorp->c_close(cursorp);
+ return result;
+ }
+
+ /* Get the next entry */
+ DBT db_key2;
+ memset(&db_key2, 0, sizeof(DBT));
+ memset(&db_data, 0, sizeof(DBT));
+ ret = cursorp->c_get(cursorp, &db_key2, &db_data, DB_NEXT);
+ if (ret != 0) {
+ cursorp->c_close(cursorp);
+ return result;
+ }
+
+ while(bdb_phrase_continue_search(&db_key1, &db_key2)) {
+
+ m_entry->m_chunk.set_chunk(db_data.data, db_data.size, NULL);
+ result = m_entry->search(tokens) | result;
+ m_entry->m_chunk.set_size(0);
+
+ memset(&db_key2, 0, sizeof(DBT));
+ memset(&db_data, 0, sizeof(DBT));
+ ret = cursorp->c_get(cursorp, &db_key2, &db_data, DB_NEXT);
+ if (ret != 0) {
+ cursorp->c_close(cursorp);
+ return result;
+ }
+ }
+
+ cursorp->c_close(cursorp);
+ return result;
+}
+
/* add_index/remove_index method */
int PhraseLargeTable3::add_index(int phrase_length,
/* in */ const ucs4_t phrase[],