當前位置: 首頁>>代碼示例>>Python>>正文


Python ZCTextIndex.query方法代碼示例

本文整理匯總了Python中Products.ZCTextIndex.ZCTextIndex.ZCTextIndex.query方法的典型用法代碼示例。如果您正苦於以下問題:Python ZCTextIndex.query方法的具體用法?Python ZCTextIndex.query怎麽用?Python ZCTextIndex.query使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Products.ZCTextIndex.ZCTextIndex.ZCTextIndex的用法示例。


在下文中一共展示了ZCTextIndex.query方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: testReindex

# 需要導入模塊: from Products.ZCTextIndex.ZCTextIndex import ZCTextIndex [as 別名]
# 或者: from Products.ZCTextIndex.ZCTextIndex.ZCTextIndex import query [as 別名]
 def testReindex(self):
     caller = LexiconHolder(self.lexicon)
     zc_index = ZCTextIndex('name',
                            None,
                            caller,
                            self.IndexFactory,
                            'text',
                            'lexicon')
     doc = Indexable('Hello Tim')
     zc_index.index_object(1, doc)
     nbest, total = zc_index.query('glorious')
     self.assertEqual(len(nbest), 0)
     nbest, total = zc_index.query('Tim')
     self.assertEqual(len(nbest), 1)
     # reindex with another value
     doc.text = 'Goodbye George'
     zc_index.index_object(1, doc)
     nbest, total = zc_index.query('Tim')
     self.assertEqual(len(nbest), 0)
     nbest, total = zc_index.query('Goodbye')
     self.assertEqual(len(nbest), 1)
     # reindex with an empty value
     doc.text = ''
     zc_index.index_object(1, doc)
     nbest, total = zc_index.query('George')
     self.assertEqual(len(nbest), 0)
開發者ID:zopefoundation,項目名稱:Products.ZCatalog,代碼行數:28,代碼來源:testZCTextIndex.py

示例2: testMultipleAttributes

# 需要導入模塊: from Products.ZCTextIndex.ZCTextIndex import ZCTextIndex [as 別名]
# 或者: from Products.ZCTextIndex.ZCTextIndex.ZCTextIndex import query [as 別名]
 def testMultipleAttributes(self):
     caller = LexiconHolder(self.lexicon)
     zc_index = ZCTextIndex('name',
                            None,
                            caller,
                            self.IndexFactory,
                            'text1,text2',
                            'lexicon')
     doc = Indexable2('foo bar', 'alpha omega')
     zc_index.index_object(1, doc)
     nbest, total = zc_index.query('foo')
     self.assertEqual(len(nbest), 1)
     nbest, total = zc_index.query('foo alpha')
     self.assertEqual(len(nbest), 1)
     nbest, total = zc_index.query('foo alpha gamma')
     self.assertEqual(len(nbest), 0)
開發者ID:zopefoundation,項目名稱:Products.ZCatalog,代碼行數:18,代碼來源:testZCTextIndex.py

示例3: testListAttributes

# 需要導入模塊: from Products.ZCTextIndex.ZCTextIndex import ZCTextIndex [as 別名]
# 或者: from Products.ZCTextIndex.ZCTextIndex.ZCTextIndex import query [as 別名]
 def testListAttributes(self):
     caller = LexiconHolder(self.lexicon)
     zc_index = ZCTextIndex('name',
                            None,
                            caller,
                            self.IndexFactory,
                            'text1,text2',
                            'lexicon')
     doc = Indexable2('Hello Tim',
                      ['Now is the winter of our discontent',
                       'Made glorious summer by this sun of York', ])
     zc_index.index_object(1, doc)
     nbest, total = zc_index.query('glorious')
     self.assertEqual(len(nbest), 1)
     nbest, total = zc_index.query('York Tim')
     self.assertEqual(len(nbest), 1)
     nbest, total = zc_index.query('Tuesday Tim York')
     self.assertEqual(len(nbest), 0)
開發者ID:zopefoundation,項目名稱:Products.ZCatalog,代碼行數:20,代碼來源:testZCTextIndex.py

示例4: ZCIndexTestsBase

# 需要導入模塊: from Products.ZCTextIndex.ZCTextIndex import ZCTextIndex [as 別名]
# 或者: from Products.ZCTextIndex.ZCTextIndex.ZCTextIndex import query [as 別名]
class ZCIndexTestsBase(object):

    def setUp(self):
        self.lexicon = PLexicon('lexicon', '',
                                Splitter(),
                                CaseNormalizer(),
                                StopWordRemover())
        caller = LexiconHolder(self.lexicon)
        self.zc_index = ZCTextIndex('name',
                                    None,
                                    caller,
                                    self.IndexFactory,
                                    'text',
                                    'lexicon')
        self.index = self.zc_index.index

    def parserFailure(self, query):
        self.assertRaises(ParseError, self.zc_index.query, query)

    def parserSuccess(self, query, n):
        r, num = self.zc_index.query(query)
        self.assertEqual(num, n)
        if n:
            self.assertEqual(r[0][0], 1)

    def testMultipleAttributes(self):
        caller = LexiconHolder(self.lexicon)
        zc_index = ZCTextIndex('name',
                               None,
                               caller,
                               self.IndexFactory,
                               'text1,text2',
                               'lexicon')
        doc = Indexable2('foo bar', 'alpha omega')
        zc_index.index_object(1, doc)
        nbest, total = zc_index.query('foo')
        self.assertEqual(len(nbest), 1)
        nbest, total = zc_index.query('foo alpha')
        self.assertEqual(len(nbest), 1)
        nbest, total = zc_index.query('foo alpha gamma')
        self.assertEqual(len(nbest), 0)

    def testListAttributes(self):
        caller = LexiconHolder(self.lexicon)
        zc_index = ZCTextIndex('name',
                               None,
                               caller,
                               self.IndexFactory,
                               'text1,text2',
                               'lexicon')
        doc = Indexable2('Hello Tim',
                         ['Now is the winter of our discontent',
                          'Made glorious summer by this sun of York', ])
        zc_index.index_object(1, doc)
        nbest, total = zc_index.query('glorious')
        self.assertEqual(len(nbest), 1)
        nbest, total = zc_index.query('York Tim')
        self.assertEqual(len(nbest), 1)
        nbest, total = zc_index.query('Tuesday Tim York')
        self.assertEqual(len(nbest), 0)

    def testReindex(self):
        caller = LexiconHolder(self.lexicon)
        zc_index = ZCTextIndex('name',
                               None,
                               caller,
                               self.IndexFactory,
                               'text',
                               'lexicon')
        doc = Indexable('Hello Tim')
        zc_index.index_object(1, doc)
        nbest, total = zc_index.query('glorious')
        self.assertEqual(len(nbest), 0)
        nbest, total = zc_index.query('Tim')
        self.assertEqual(len(nbest), 1)
        # reindex with another value
        doc.text = 'Goodbye George'
        zc_index.index_object(1, doc)
        nbest, total = zc_index.query('Tim')
        self.assertEqual(len(nbest), 0)
        nbest, total = zc_index.query('Goodbye')
        self.assertEqual(len(nbest), 1)
        # reindex with an empty value
        doc.text = ''
        zc_index.index_object(1, doc)
        nbest, total = zc_index.query('George')
        self.assertEqual(len(nbest), 0)

    def testStopWords(self):
        # the only non-stopword is question
        text = ('to be or not to be '
                'that is the question')
        doc = Indexable(text)
        self.zc_index.index_object(1, doc)
        for word in text.split():
            if word != 'question':
                wids = self.lexicon.termToWordIds(word)
                self.assertEqual(wids, [])
        self.assertEqual(len(self.index.get_words(1)), 1)

#.........這裏部分代碼省略.........
開發者ID:zopefoundation,項目名稱:Products.ZCatalog,代碼行數:103,代碼來源:testZCTextIndex.py

示例5: setUp

# 需要導入模塊: from Products.ZCTextIndex.ZCTextIndex import ZCTextIndex [as 別名]
# 或者: from Products.ZCTextIndex.ZCTextIndex.ZCTextIndex import query [as 別名]
class ZCIndexTestsBase:

    def setUp(self):
        self.lexicon = PLexicon('lexicon', '',
                                Splitter(),
                                CaseNormalizer(),
                                StopWordRemover())
        caller = LexiconHolder(self.lexicon)
        self.zc_index = ZCTextIndex('name',
                                    None,
                                    caller,
                                    self.IndexFactory,
                                    'text',
                                    'lexicon')
        self.index = self.zc_index.index


    def parserFailure(self, query):
        self.assertRaises(ParseError, self.zc_index.query, query)

    def parserSuccess(self, query, n):
        r, num = self.zc_index.query(query)
        self.assertEqual(num, n)
        if n:
            self.assertEqual(r[0][0], 1)

    def testMultipleAttributes(self):
        lexicon = PLexicon('lexicon', '',
                            Splitter(),
                            CaseNormalizer(),
                            StopWordRemover())
        caller = LexiconHolder(self.lexicon)
        zc_index = ZCTextIndex('name',
                                None,
                                caller,
                                self.IndexFactory,
                               'text1,text2',
                               'lexicon')
        doc = Indexable2('foo bar', 'alpha omega')
        zc_index.index_object(1, doc)
        nbest, total = zc_index.query('foo')
        self.assertEqual(len(nbest), 1)
        nbest, total = zc_index.query('foo alpha')
        self.assertEqual(len(nbest), 1)
        nbest, total = zc_index.query('foo alpha gamma')
        self.assertEqual(len(nbest), 0)

    def testListAttributes(self):
        lexicon = PLexicon('lexicon', '',
                            Splitter(),
                            CaseNormalizer(),
                            StopWordRemover())
        caller = LexiconHolder(self.lexicon)
        zc_index = ZCTextIndex('name',
                                None,
                                caller,
                                self.IndexFactory,
                               'text1,text2',
                               'lexicon')
        doc = Indexable2('Hello Tim', \
                         ['Now is the winter of our discontent',
                          'Made glorious summer by this sun of York', ])
        zc_index.index_object(1, doc)
        nbest, total = zc_index.query('glorious')
        self.assertEqual(len(nbest), 1)
        nbest, total = zc_index.query('York Tim')
        self.assertEqual(len(nbest), 1)
        nbest, total = zc_index.query('Tuesday Tim York')
        self.assertEqual(len(nbest), 0)

    def testStopWords(self):
        # the only non-stopword is question
        text = ("to be or not to be "
                "that is the question")
        doc = Indexable(text)
        self.zc_index.index_object(1, doc)
        for word in text.split():
            if word != "question":
                wids = self.lexicon.termToWordIds(word)
                self.assertEqual(wids, [])
        self.assertEqual(len(self.index.get_words(1)), 1)

        self.parserSuccess('question', 1)
        self.parserSuccess('question AND to AND be', 1)
        self.parserSuccess('to AND question AND be', 1)
        self.parserSuccess('question AND NOT gardenia', 1)
        self.parserSuccess('question AND gardenia', 0)
        self.parserSuccess('gardenia', 0)
        self.parserSuccess('question OR gardenia', 1)
        self.parserSuccess('question AND NOT to AND NOT be', 1)
        self.parserSuccess('question OR to OR be', 1)
        self.parserSuccess('question to be', 1)

        self.parserFailure('to be')
        self.parserFailure('to AND be')
        self.parserFailure('to OR be')
        self.parserFailure('to AND NOT be')
        self.parserFailure('to AND NOT question')
        self.parserFailure('to AND NOT gardenia')

#.........這裏部分代碼省略.........
開發者ID:nacho22martin,項目名稱:tesis,代碼行數:103,代碼來源:testZCTextIndex.py


注:本文中的Products.ZCTextIndex.ZCTextIndex.ZCTextIndex.query方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。