Imported version 0.2-5 v0.2-5
authorRoman Moravcik <roman.moravcik@gmail.com>
Thu, 18 Feb 2010 16:36:09 +0000 (17:36 +0100)
committerRoman Moravcik <roman.moravcik@gmail.com>
Thu, 18 Feb 2010 16:36:09 +0000 (17:36 +0100)
debian/changelog
src/libwrapper.cpp
src/libwrapper.hpp
src/mstardict.cpp

index b84aade..58eefc0 100644 (file)
@@ -1,3 +1,9 @@
+mstardict (0.2-5) unstable; urgency=low
+
+  * Reimplemented lookup with Fuzzy and Rule (not working yet)
+
+ -- Roman Moravcik <roman.moravcik@gmail.com>  Fri, 29 Jan 2010 18:22:29 +0100
+
 mstardict (0.2-4) unstable; urgency=low
 
   * sdcv search mechanism replaced by ported search from stardict.
index 28b068e..fcb53fb 100644 (file)
@@ -257,33 +257,45 @@ bool Library::SimpleLookup(const gchar* sWord, CurrentIndex* piIndex)
        return bFound;
 }
 
-void Library::LookupWithFuzzy(const string &str, TSearchResultList& res_list)
+void Library::LookupWithFuzzy(const gchar* sWord)
 {
-       static const int MAXFUZZY=10;
+       static const int MAX_FUZZY_MATCH_ITEM=100;
+       gchar *fuzzy_reslist[MAX_FUZZY_MATCH_ITEM];
+       bool bFound = false;
 
-       gchar *fuzzy_res[MAXFUZZY];
-       if (!Libs::LookupWithFuzzy(str.c_str(), fuzzy_res, MAXFUZZY, query_dictmask))
-               return;
-       
-       for (gchar **p=fuzzy_res, **end=fuzzy_res+MAXFUZZY; 
-            p!=end && *p; ++p) {
-//             SimpleLookup(*p, res_list);
-               g_free(*p);
+       pMStarDict->ResultsListClear();
+
+       bFound = Libs::LookupWithFuzzy(sWord, fuzzy_reslist, MAX_FUZZY_MATCH_ITEM, query_dictmask);
+       if (bFound) {
+               SimpleLookup(fuzzy_reslist[0], iCurrentIndex);
+
+               for (int i=0; i<MAX_FUZZY_MATCH_ITEM && fuzzy_reslist[i]; i++) {
+                       pMStarDict->ResultsListInsertLast(fuzzy_reslist[i]);
+                       g_free(fuzzy_reslist[i]);
+               }
+               pMStarDict->ReScroll();
        }
 }
 
-void Library::LookupWithRule(const string &str, TSearchResultList& res_list)
+void Library::LookupWithRule(const gchar* sWord)
 {
-       std::vector<gchar *> match_res((MAX_MATCH_ITEM_PER_LIB) * query_dictmask.size());
+       gint iMatchCount=0;
+       gchar **ppMatchWord = (gchar **)g_malloc(sizeof(gchar *) * (MAX_MATCH_ITEM_PER_LIB) * query_dictmask.size());
 
-       gint nfound=Libs::LookupWithRule(str.c_str(), &match_res[0], query_dictmask);
-       if (!nfound)
-               return;
+       pMStarDict->ResultsListClear();
+
+       iMatchCount=Libs::LookupWithRule(sWord, ppMatchWord, query_dictmask);
+       if (iMatchCount) {
+               for (gint i=0; i<iMatchCount; i++)
+                       pMStarDict->ResultsListInsertLast(ppMatchWord[i]);
+
+               SimpleLookup(ppMatchWord[0], iCurrentIndex);
+               pMStarDict->ReScroll();
 
-       for (gint i=0; i<nfound; ++i) {
-//             SimpleLookup(match_res[i], res_list);
-               g_free(match_res[i]);
+               for(gint i=0; i<iMatchCount; i++)
+                       g_free(ppMatchWord[i]);
        }
+       g_free(ppMatchWord);
 }
 
 void Library::LookupData(const string &str, TSearchResultList& res_list)
index cc76aa8..20a7acc 100644 (file)
@@ -40,9 +40,9 @@ public:
        bool BuildResultData(std::vector<InstantDictIndex> &dictmask, const char* sWord, CurrentIndex *iIndex, int iLib, TSearchResultList& res_list);
 
        bool SimpleLookup(const gchar* sWord, CurrentIndex* piIndex);
+       void LookupWithFuzzy(const gchar* sWord);
+       void LookupWithRule(const gchar* sWord);
 private:
-       void LookupWithFuzzy(const string &str, TSearchResultList& res_list);
-       void LookupWithRule(const string &str, TSearchResultList& res_lsit);
        void LookupData(const string &str, TSearchResultList& res_list);
 };
 
index 9a0d964..f52d81e 100644 (file)
@@ -146,17 +146,22 @@ MStarDict::onSearchEntryChanged (GtkEditable *editable,
                switch (analyse_query(sWord, query)) {
                        case qtFUZZY:
                                g_debug ("FUZZY");
-//                             oLibs->LookupWithFuzzy(query, res_list);
+                               mStarDict->oLibs->LookupWithFuzzy(sWord);
                                break;
                        case qtREGEX:
                                g_debug ("REGEX");
-//                             oLibs->LookupWithRule(query, res_list);
+                               mStarDict->oLibs->LookupWithRule(sWord);
                                break;
                        case qtSIMPLE:
                                g_debug ("SIMPLE");
                                bFound = mStarDict->oLibs->SimpleLookup(sWord, mStarDict->oLibs->iCurrentIndex);
                                if (!bFound) {
-                                       /* suggested */
+                                       const gchar *sugWord = mStarDict->oLibs->GetSuggestWord(sWord, mStarDict->oLibs->iCurrentIndex, mStarDict->oLibs->query_dictmask, 0);
+                                       if (sugWord) {
+                                               gchar *sSugWord = g_strdup(sugWord);
+                                               bFound = mStarDict->oLibs->SimpleLookup(sSugWord, mStarDict->oLibs->iCurrentIndex);
+                                               g_free(sSugWord);
+                                       }
                                }
                                mStarDict->oLibs->ListWords(mStarDict->oLibs->iCurrentIndex);
                                break;