Esempio n. 1
0
 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
Esempio n. 2
0
    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
Esempio n. 3
0
    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')
Esempio n. 4
0
    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')
Esempio n. 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')
Esempio n. 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')