コード例 #1
0
ファイル: models.py プロジェクト: carlchen0928/rssEngine
 def query(cls, text):
     # user = User.objects.get(pk=user_id)
     text=text.strip()
     cls.ES.refresh()
     q = StringQuery(text)
     highlighter = HighLighter(['<em>'],['</em>'])
     # highlighter = HighLighter()
     s = Search(q,highlight=highlighter)
     s.add_highlight('title')
     s.add_highlight('content')
     results = cls.ES.search(s,indices=['%s-index' % cls.name])
     # logging.user(user, "~FGSearch ~FCsaved stories~FG for: ~SB%s" % text)
     
     if not results.total:
         # logging.user(user, "~FGSearch ~FCsaved stories~FG by title: ~SB%s" % text)
         q = FuzzyQuery('title', text)
         results = cls.ES.search(q)
         
     if not results.total:
         # logging.user(user, "~FGSearch ~FCsaved stories~FG by content: ~SB%s" % text)
         q = FuzzyQuery('content', text)
         results = cls.ES.search(q)
         
     if not results.total:
         # logging.user(user, "~FGSearch ~FCsaved stories~FG by author: ~SB%s" % text)
         q = FuzzyQuery('author', text)
         results = cls.ES.search(q)
         
     return results
コード例 #2
0
ファイル: models.py プロジェクト: cash2one/rssEngine
    def query(cls, text):
        # user = User.objects.get(pk=user_id)
        text = text.strip()
        cls.ES.refresh()
        q = StringQuery(text)
        highlighter = HighLighter(['<em>'], ['</em>'])
        # highlighter = HighLighter()
        s = Search(q, highlight=highlighter)
        s.add_highlight('title')
        s.add_highlight('content')
        results = cls.ES.search(s, indices=['%s-index' % cls.name])
        # logging.user(user, "~FGSearch ~FCsaved stories~FG for: ~SB%s" % text)

        if not results.total:
            # logging.user(user, "~FGSearch ~FCsaved stories~FG by title: ~SB%s" % text)
            q = FuzzyQuery('title', text)
            results = cls.ES.search(q)

        if not results.total:
            # logging.user(user, "~FGSearch ~FCsaved stories~FG by content: ~SB%s" % text)
            q = FuzzyQuery('content', text)
            results = cls.ES.search(q)

        if not results.total:
            # logging.user(user, "~FGSearch ~FCsaved stories~FG by author: ~SB%s" % text)
            q = FuzzyQuery('author', text)
            results = cls.ES.search(q)

        return results
コード例 #3
0
ファイル: test_highlight.py プロジェクト: CGenie/pyes
    def test_QueryHighlight(self):
        q = Search(QueryStringQuery("joe"))
        q.add_highlight("parsedtext")
        q.add_highlight("name")
        resultset = self.conn.search(q, indices=self.index_name)
        self.assertEqual(resultset.total, 2)
        self.assertNotEqual(resultset[0]._meta.highlight, None)

        self.assertEqual(resultset[0]._meta.highlight[u"parsedtext"][0].strip(),
            u'<em>Joe</em> Testere nice guy')
コード例 #4
0
ファイル: test_highlight.py プロジェクト: CGenie/pyes
    def test_QueryHighlightWithHighLighter(self):
        h = HighLighter(['<b>'], ['</b>'])
        q = Search(QueryStringQuery("joe"), highlight=h)
        q.add_highlight("parsedtext")
        q.add_highlight("name")
        resultset = self.conn.search(q, indices=self.index_name)
        self.assertEqual(resultset.total, 2)
        self.assertNotEqual(resultset[0]._meta.highlight, None)

        self.assertEqual(resultset[0]._meta.highlight[u"parsedtext"][0].strip(),
            u'<b>Joe</b> Testere nice guy')
コード例 #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)
        self.assertEquals(resultset.total, 2)
        self.assertNotEqual(resultset[0]._meta.highlight, None)

        self.assertEquals(
            resultset[0]._meta.highlight[u"parsedtext"][0].strip(),
            u'<em>Joe</em> Testere nice guy')
コード例 #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)
        self.assertEquals(resultset.total, 2)
        self.assertNotEqual(resultset[0]._meta.highlight, None)

        self.assertEquals(
            resultset[0]._meta.highlight[u"parsedtext"][0].strip(),
            u'<b>Joe</b> Testere nice guy')