import collections
import math
import os
import re
import unittest
import redis
NON_WORDS = re.compile("[^a-z0-9' ]")
# stop words pulled from the below url
# http://www.textfixer.com/resources/common-english-words.txt
STOP_WORDS = set('''a able about across after all almost also am among
an and any are as at be because been but by can cannot could dear did
do does either else ever every for from get got had has have he her
hers him his how however i if in into is it its just least let like
likely may me might most must my neither no nor not of off often on
only or other our own rather said say says she should since so some
than that the their them then there these they this tis to too twas us
wants was we were what when where which while who whom why will with
would yet you your'''.split())
class ScoredIndexSearch(object):
def __init__(self, prefix, *redis_settings):
# All of our index keys are going to be prefixed with the provided
# prefix string. This will allow multiple independent indexes to
# coexist in the same Redis db.
self.prefix = prefix.lower().rstrip(':') + ':'
# Create a connection to our Redis server.
self.connection = redis.Redis(*redis_settings)
@staticmethod
def get_index_keys(content, add=True):
# Very simple word-based parser. We skip stop words and single
# character words.
使用Python和Redis创建一个简单的基于分数的文本索引和搜索系统
最新推荐文章于 2025-06-07 09:07:10 发布