Exemple #1
0
 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)
Exemple #2
0
 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)
Exemple #3
0
    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)
Exemple #4
0
    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 ')
Exemple #5
0
    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 ')
Exemple #6
0
    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 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 ')
Exemple #8
0
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)
Exemple #9
0
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)
Exemple #10
0
 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)