def test_all_terms(): q = QueryParser("a", None).parse(u('hello b:there c:"my friend"')) ts = q.all_terms(phrases=False) assert_equal(sorted(ts), [("a", "hello"), ("b", "there")]) ts = q.all_terms(phrases=True) assert_equal(sorted(ts), [("a", "hello"), ("b", "there"), ("c", "friend"), ("c", "my")])
def test_all_terms(): q = QueryParser("a", None).parse(u('hello b:there c:"my friend"')) ts = q.all_terms(phrases=False) assert sorted(ts) == [("a", "hello"), ("b", "there")] ts = q.all_terms(phrases=True) assert sorted(ts) == [("a", "hello"), ("b", "there"), ("c", "friend"), ("c", "my")]
def test_all_terms(self): q = QueryParser("a").parse(u'hello b:there c:"my friend"') ts = set() q.all_terms(ts, phrases=False) self.assertEqual(sorted(ts), [("a", "hello"), ("b", "there")]) ts = set() q.all_terms(ts, phrases=True) self.assertEqual(sorted(ts), [("a", "hello"), ("b", "there"), ("c", "friend"), ("c", "my")])
def get_query(line, ix): lines = line.strip().split('\t') post = lines[0].decode('utf-8') q2 = QueryParser("post", ix.schema).parse(post) terms = list(q2.all_terms()) query = Or([Term(*x) for x in terms]) return query
def get_query(line, ix): lines = line.strip().split('\t') #context=unicode(' '.join(lines[2:-1]), 'gb18030') post = unicode(lines[0], 'gb18030') #q1=QueryParser("context", ix.schema).parse(context) q2 = QueryParser("post", ix.schema).parse(post) #context=' '.join(lines[2:-1]) #query =QueryParser("post", ix.schema).parse(post) terms = list(q2.all_terms()) query = Or([Term(*x) for x in terms]) return query context = unicode(context, 'gb18030') q1 = QueryParser("context", ix.schema).parse(context) terms = list(q1.all_terms()) + list(q2.all_terms()) query = Or([Term(*x) for x in terms]) return query