log = logging.getLogger('search')
+if os.path.isfile(settings.SOLR_STOPWORDS):
+ stopwords = set(
+ line.decode('utf-8').strip()
+ for line in open(settings.SOLR_STOPWORDS) if not line.startswith('#'))
+else:
+ stopwords = set()
+
class SolrIndex(object):
def __init__(self, mode=None):
def search_words(self, words, fields, book=True):
filters = []
for word in words:
- word_filter = None
- for field in fields:
- q = self.index.Q(**{field: word})
- if word_filter is None:
- word_filter = q
- else:
- word_filter |= q
- filters.append(word_filter)
+ if word not in stopwords:
+ word_filter = None
+ for field in fields:
+ q = self.index.Q(**{field: word})
+ if word_filter is None:
+ word_filter = q
+ else:
+ word_filter |= q
+ filters.append(word_filter)
+ if not filters:
+ return []
if book:
query = self.index.query(is_book=True)
else:
SOLR = "http://localhost:8983/solr/wl/"
SOLR_TEST = "http://localhost:8983/solr/wl_test/"
+SOLR_STOPWORDS = "/path/to/solr/data/conf/lang/stopwords_pl.txt"
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name