Changeset 14401 for lang/python

Show
Ignore:
Timestamp:
06/22/08 08:57:12 (5 months ago)
Author:
ayu
Message:
  • completed
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/python/incsearch/incsearch/indexer.py

    r14277 r14401  
    77from  incsearch.db import DocDbWriter 
    88 
     9TITLE = re.compile(r'<title>([^<]+)</title>') 
     10TITLENUM = re.compile('^[0-9\. ]+') 
    911FUNC = re.compile(r'<tt id[^>]*>([^<]+)</tt>') 
    1012def extractor(cont): 
     13    t = TITLE.search(cont) 
     14    title = "" 
     15    if t: 
     16        title = unicode(t.group(1), "euc_jp", "ignore").encode("utf-8", "ignore") 
     17    titlehead = TITLENUM.sub("", title) 
     18    yield dict(pos=None, title=title, word=titlehead.lower()) 
    1119    scanner = FUNC.scanner(cont) 
    1220    m = scanner.search() 
    1321    while m: 
    14         yield dict(pos=m.start(), title=m.group(1), word=m.group(1)) 
     22        yield dict(pos=m.start(), title=m.group(1)+" - "+titlehead, word=m.group(1).lower()) 
    1523        m = scanner.search() 
    1624 
     
    4452        pre = 0 
    4553        for i, ipoint in enumerate(extractor(whole)): 
    46             ipoint.update({"fname": fname}) 
    47             db.put(ipoint["word"], "%s\t%d\t%s" % (fname, ipoint["pos"], ipoint["title"])) 
    48             nametag = "<a name='incsearch_%d'/>" % i 
    49             tagged.append(whole[pre:ipoint["pos"]]) 
    50             tagged.append(nametag) 
    51             pre = ipoint["pos"] 
     54            if ipoint["pos"]: 
     55                db.put(ipoint["word"], "%s\t%d\t%s" % (fname, i, ipoint["title"])) 
     56                nametag = "<a name='incsearch_%d'/>" % i 
     57                tagged.append(whole[pre:ipoint["pos"]]) 
     58                tagged.append(nametag) 
     59                pre = ipoint["pos"] 
     60            else: 
     61                db.put(ipoint["word"], "%s\t-\t%s" % (fname, ipoint["title"])) 
    5262        tagged.append(whole[pre:]) 
    5363        gp = file(os.path.join(outdir, os.path.basename(fname)), "w")