Changeset 7252

Show
Ignore:
Timestamp:
02/28/08 21:43:51 (5 years ago)
Author:
gyuque
Message:

syobocalplus.user.js: vowel complement

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/javascript/userscripts/syobocalplus.user.js

    r7247 r7252  
    387387                        if (!kw) 
    388388                                return null; 
     389 
     390                        var keywords = [kw, RomKan.to_kana(kw)]; 
     391                        this.addSuggestedKana(kw, keywords); 
     392                        var matchdata = this.multiPathSearch(this.ndb, keywords); 
     393 
     394                        if (matchdata.count < 1) 
     395                                return null; 
     396 
     397                        return {count_all: matchdata.count, titles: matchdata.titles}; 
     398                }, 
     399 
     400                addSuggestedKana: function(roma, arr) 
     401                { 
     402                        if (roma.length < 1) return; 
     403                        if (!roma.match(/([bcdfghjklmprstwyz]|[^n]n)$/)) return; 
     404 
     405                        arr.push(RomKan.to_kana(roma+"a")); 
     406                        arr.push(RomKan.to_kana(roma+"i")); 
     407                        arr.push(RomKan.to_kana(roma+"u")); 
     408                        arr.push(RomKan.to_kana(roma+"e")); 
     409                        arr.push(RomKan.to_kana(roma+"o")); 
     410                }, 
     411 
     412                multiPathSearch: function(target, keywords, matchdata) 
     413                { 
     414                        if (!matchdata) 
     415                                matchdata = {count: 0, titles: [], map:{}}; 
     416 
     417                        if (!keywords || keywords.length < 1) 
     418                                return matchdata; 
    389419                         
    390                         var count = 0; 
    391                          
    392                         var pass1_matched = {}; 
    393                         var matchedTitles = this.ndb.search(kw, function(t){count += t.count; pass1_matched[t.tid]=true; }); 
    394  
    395                         this.ndb.search(RomKan.to_kana(kw), function(t){ if (!pass1_matched[t.tid]){ if (!matchedTitles){matchedTitles=[]} count += t.count; matchedTitles.push(t); } }); 
    396  
    397                         if (!matchedTitles) 
    398                                 return null; 
    399  
    400                         return {count_all: count, titles: matchedTitles}; 
     420                        target.search(keywords.shift(), function(t){ 
     421                                if (!matchdata.map[t.tid]) { 
     422                                        matchdata.count += t.count; 
     423                                        matchdata.titles.push(t); 
     424                                        matchdata.map[t.tid] = true; 
     425                                } 
     426                        }); 
     427 
     428                        return this.multiPathSearch(target, keywords, matchdata); 
    401429                }, 
    402430