def test_wild(): qp = default.QueryParser( "t", None, [plugins.WhitespacePlugin(), plugins.WildcardPlugin()]) assert repr(qp.process( "a b*c? d")) == "<AndGroup <None:'a'>, <None:Wild 'b*c?'>, <None:'d'>>" assert repr( qp.process("a * ? d") ) == "<AndGroup <None:'a'>, <None:Wild '*'>, <None:Wild '?'>, <None:'d'>>" # qp = default.QueryParser("content", None) q = qp.parse(u("hello *the?e* ?star*s? test")) assert len(q) == 4 assert q[0].__class__ == query.Term assert q[0].text == "hello" assert q[1].__class__ == query.Wildcard assert q[1].text == "*the?e*" assert q[2].__class__ == query.Wildcard assert q[2].text == "?star*s?" assert q[3].__class__ == query.Term assert q[3].text == "test" # qp = default.QueryParser("content", None) q = qp.parse(u("*the?e*")) assert q.__class__ == query.Wildcard assert q.text == "*the?e*"
def search(self, pattern): qp = QueryParser('symbol', schema=self._ix.schema, plugins=[ plugins.WildcardPlugin()]) q = qp.parse('*%s*' % pattern) items = [] with self._ix.searcher() as s: results = s.search(q, limit=50, sortedby='sort', reverse=True) for item in results: items.append(item.fields()) return items
def default_set(self): """Returns the default list of plugins to use. """ from whoosh.qparser import plugins return [plugins.WhitespacePlugin(), plugins.SingleQuotePlugin(), plugins.FieldsPlugin(), plugins.WildcardPlugin(), plugins.PhrasePlugin(), plugins.RangePlugin(), plugins.GroupPlugin(), plugins.OperatorsPlugin(), plugins.BoostPlugin(), plugins.EveryPlugin(), ]
def test_wild(): p = default.QueryParser("t", None, [plugins.WhitespacePlugin(), plugins.WildcardPlugin()]) assert_equal(repr(p.process("a b*c? d")), "<AndGroup <None:'a'>, <None:Wild 'b*c?'>, <None:'d'>>")