def search(query, page = 1, size=10): lasttime = time.clock() suggestor.add_query(query) tokens = stop_and_stem_seq(parse(query, '')) result = get_doc_list(query, tokens) result = collect(result[(page - 1)*size:page*size], tokens, len(result), lasttime) return result
def search(query, page=1, size=10): lasttime = time.clock() suggestor.add_query(query) tokens = stop_and_stem_seq(parse(query, '')) result = get_doc_list(query, tokens) result = collect(result[(page - 1) * size:page * size], tokens, len(result), lasttime) return result
def save_and_segment(doc_id, html, url): import suggestor title, text, words = analyze(html) l = len(words) r.hmset('doc:%s'%doc_id, {'title': title, 'text': text, 'len': l, 'url': url}) r.incrbyfloat('total_len', l) for token in words: suggestor.add_query(token.word, token.weight) r.zadd(u'word:%s'%token.word, token.weight, doc_id) r.hmset(u'dw:%s:%s:%s'%(doc_id, token.word, token.fieldname), { 'pos': token.pos, 'len': token.len, 'weight': token.weight, })
def save_and_segment(doc_id, html, url): import suggestor title, text, words = analyze(html) l = len(words) r.hmset('doc:%s' % doc_id, { 'title': title, 'text': text, 'len': l, 'url': url }) r.incrbyfloat('total_len', l) for token in words: suggestor.add_query(token.word, token.weight) r.zadd(u'word:%s' % token.word, token.weight, doc_id) r.hmset(u'dw:%s:%s:%s' % (doc_id, token.word, token.fieldname), { 'pos': token.pos, 'len': token.len, 'weight': token.weight, })