1
# This module is part of the Lupy project and is Copyright 2005 Florian
2
# Festi. This is free software; you can redistribute
3
# it and/or modify it under the terms of version 2.1 of the GNU Lesser
4
# General Public License as published by the Free Software Foundation.
6
from term import TermQuery
7
from boolean import BooleanQuery, BooleanScorer
8
from phrase import PhraseQuery
9
from MoinMoin.support.lupy.index.term import Term
11
class CamelCaseQuery(TermQuery):
14
A Query that matches documents that contains words
15
the term starts with. This is usefull for CamelCase
16
words. You need to filter the results to make shure
17
the camel case words are really contained within the
20
def sumOfSquaredWeights(self, searcher):
21
self.query = BooleanQuery()
22
self.reader = searcher.reader
23
self.splitToWords(self.term, self.reader, [])
24
return self.query.sumOfSquaredWeights(searcher)
26
def scorer(self, reader):
27
return self.query.scorer(reader)
29
def _add_phrase(self, terms):
30
phrase = PhraseQuery()
33
self.query.add(phrase, False, False)
35
def splitToWords(self, term, reader, terms):
38
for l in xrange(2, len(text)+1):
40
ts = reader.terms(Term(field, prefix))
41
if ((ts.term.text()==prefix and
42
ts.term.field()==field)):
45
self.splitToWords(Term(field, text[l:]), reader, t)
47
ts = reader.terms(term)
52
max_length = len(text) + 3
53
while ts.term.text().startswith(text):
54
if (len(ts.term.text()) < max_length and
55
ts.term.field()==field):
56
self._add_phrase(terms+[ts.term])
62
self._add_phrase(terms)