def test_QueryHighlight(self): q = Search(StringQuery("joe")) q.add_highlight("parsedtext") q.add_highlight("name") resultset = self.conn.search(q, indices=self.index_name) self.assertEquals(resultset.total, 2) self.assertNotEqual(resultset[0].meta.highlight, None)
def test_QueryHighlight(self): q = Search(StringQuery("joe")) q.add_highlight("parsedtext") q.add_highlight("name") result = self.conn.search(q, indexes=["test-index"]) from pprint import pprint pprint(result) self.assertEquals(result['hits']['total'], 2)
def test_QueryHighlight(self): q = Search(StringQuery("joe")) q.add_highlight("parsedtext") q.add_highlight("name") result = self.conn.search(q, indexes=["test-index"]) from pprint import pprint pprint(result) self.assertEquals(result["hits"]["total"], 2)
def test_QueryHighlight(self): q = Search(StringQuery("joe")) q.add_highlight("parsedtext") q.add_highlight("name") resultset = self.conn.search(q, indices=self.index_name) print resultset[0].meta.highlight self.assertEquals(resultset.total, 2) self.assertNotEqual(resultset[0].meta.highlight, None) self.assertEquals(resultset[0].meta.highlight[u"parsedtext"][0], u'<em>Joe</em> Testere nice guy ')
def test_QueryHighlight(self): q = Search(StringQuery("joe")) q.add_highlight("parsedtext") q.add_highlight("name") resultset = self.conn.search(q, indices=self.index_name) print resultset[0]._meta.highlight self.assertEquals(resultset.total, 2) self.assertNotEqual(resultset[0]._meta.highlight, None) self.assertEquals(resultset[0]._meta.highlight[u"parsedtext"][0], u'<em>Joe</em> Testere nice guy ')
def test_QueryHighlightWithHighLighter(self): h = HighLighter(['<b>'], ['</b>']) q = Search(StringQuery("joe"), highlight=h) q.add_highlight("parsedtext") q.add_highlight("name") resultset = self.conn.search(q, indices=self.index_name) print resultset[0].meta.highlight self.assertEquals(resultset.total, 2) self.assertNotEqual(resultset[0].meta.highlight, None) self.assertEquals(resultset[0].meta.highlight[u"parsedtext"][0], u'<b>Joe</b> Testere nice guy ')
def search(searchkey=u"电影"): conn = ES('127.0.0.1:9200') # TextQuery会对searchkey进行分词 qtitle = TextQuery("title", searchkey) h = HighLighter(['<b>'], ['</b>'], fragment_size=500) # 多字段搜索(must=>and,should=>or),高亮,结果截取(分页),排序 q = Search(BoolQuery(should=[qtitle]), highlight=h, start=0, size=3, sort={'id': {'order': 'asc'}}) q.add_highlight("title") results = conn.search(q, "zhihu", "answer") list = [] for r in results: if("title" in r._meta.highlight): r['title'] = r._meta.highlight[u"title"][0] list.append(r) return template('results.html', list=list, count=results.total)
def search(searchkey=u"电影"): conn = ES('127.0.0.1:9200') # TextQuery会对searchkey进行分词 qtitle = TextQuery("title", searchkey) h = HighLighter(['<b>'], ['</b>'], fragment_size=500) # 多字段搜索(must=>and,should=>or),高亮,结果截取(分页),排序 q = Search(BoolQuery(should=[qtitle]), highlight=h, start=0, size=3, sort={'id': { 'order': 'asc' }}) q.add_highlight("title") results = conn.search(q, "zhihu", "answer") list = [] for r in results: if ("title" in r._meta.highlight): r['title'] = r._meta.highlight[u"title"][0] list.append(r) return template('results.html', list=list, count=results.total)
def test_QueryHighlight(self): q = Search(StringQuery("joe")) q.add_highlight("parsedtext") q.add_highlight("name") resultset = self.conn.search(q, indexes=["test-index"]) self.assertEquals(resultset.total, 2)