当前位置: 首页>>代码示例>>Python>>正文


Python SearchQuery.add_boost方法代码示例

本文整理汇总了Python中haystack.backends.xapian_backend.SearchQuery.add_boost方法的典型用法代码示例。如果您正苦于以下问题:Python SearchQuery.add_boost方法的具体用法?Python SearchQuery.add_boost怎么用?Python SearchQuery.add_boost使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在haystack.backends.xapian_backend.SearchQuery的用法示例。


在下文中一共展示了SearchQuery.add_boost方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: XapianSearchQueryTestCase

# 需要导入模块: from haystack.backends.xapian_backend import SearchQuery [as 别名]
# 或者: from haystack.backends.xapian_backend.SearchQuery import add_boost [as 别名]
class XapianSearchQueryTestCase(TestCase):
    def setUp(self):
        super(XapianSearchQueryTestCase, self).setUp()
        self.sq = SearchQuery(backend=SearchBackend())
    
    def tearDown(self):
        if os.path.exists(settings.HAYSTACK_XAPIAN_PATH):
            shutil.rmtree(settings.HAYSTACK_XAPIAN_PATH)
        
        super(XapianSearchQueryTestCase, self).tearDown()
    
    def test_build_query_all(self):
        self.assertEqual(str(self.sq.build_query()), u'Xapian::Query(<alldocuments>)')
    
    def test_build_query_single_word(self):
        self.sq.add_filter(SQ(content='hello'))
        self.assertEqual(str(self.sq.build_query()), u'Xapian::Query((Zhello OR hello))')
    
    def test_build_query_single_word_not(self):
        self.sq.add_filter(~SQ(content='hello'))
        self.assertEqual(str(self.sq.build_query()), u'Xapian::Query((<alldocuments> AND_NOT (Zhello OR hello)))')
    
    def test_build_query_single_word_field_exact(self):
        self.sq.add_filter(SQ(foo='hello'))
        self.assertEqual(str(self.sq.build_query()), u'Xapian::Query((ZXFOOhello OR XFOOhello))')
    
    def test_build_query_single_word_field_exact_not(self):
        self.sq.add_filter(~SQ(foo='hello'))
        self.assertEqual(str(self.sq.build_query()), u'Xapian::Query((<alldocuments> AND_NOT (ZXFOOhello OR XFOOhello)))')
    
    def test_build_query_boolean(self):
        self.sq.add_filter(SQ(content=True))
        self.assertEqual(str(self.sq.build_query()), u'Xapian::Query((Ztrue OR true))')
    
    def test_build_query_date(self):
        self.sq.add_filter(SQ(content=datetime.date(2009, 5, 8)))
        self.assertEqual(str(self.sq.build_query()), u'Xapian::Query((Z20090508000000 OR 20090508000000))')
    
    def test_build_query_date_not(self):
        self.sq.add_filter(~SQ(content=datetime.date(2009, 5, 8)))
        self.assertEqual(str(self.sq.build_query()), u'Xapian::Query((<alldocuments> AND_NOT (Z20090508000000 OR 20090508000000)))')

    def test_build_query_datetime(self):
        self.sq.add_filter(SQ(content=datetime.datetime(2009, 5, 8, 11, 28)))
        self.assertEqual(str(self.sq.build_query()), u'Xapian::Query((Z20090508112800 OR 20090508112800))')
    
    def test_build_query_datetime_not(self):
        self.sq.add_filter(~SQ(content=datetime.datetime(2009, 5, 8, 11, 28)))
        self.assertEqual(str(self.sq.build_query()), u'Xapian::Query((<alldocuments> AND_NOT (Z20090508112800 OR 20090508112800)))')

    def test_build_query_float(self):
        self.sq.add_filter(SQ(content=25.52))
        self.assertEqual(str(self.sq.build_query()), u'Xapian::Query((Z25.52 OR 25.52))')
    
    def test_build_query_multiple_words_and(self):
        self.sq.add_filter(SQ(content='hello'))
        self.sq.add_filter(SQ(content='world'))
        self.assertEqual(str(self.sq.build_query()), u'Xapian::Query(((Zhello OR hello) AND (Zworld OR world)))')
    
    def test_build_query_multiple_words_not(self):
        self.sq.add_filter(~SQ(content='hello'))
        self.sq.add_filter(~SQ(content='world'))
        self.assertEqual(str(self.sq.build_query()), u'Xapian::Query(((<alldocuments> AND_NOT (Zhello OR hello)) AND (<alldocuments> AND_NOT (Zworld OR world))))')
    
    def test_build_query_multiple_words_or(self):
        self.sq.add_filter(SQ(content='hello') | SQ(content='world'))
        self.assertEqual(str(self.sq.build_query()), u'Xapian::Query((Zhello OR hello OR Zworld OR world))')
    
    def test_build_query_multiple_words_or_not(self):
        self.sq.add_filter(~SQ(content='hello') | ~SQ(content='world'))
        self.assertEqual(str(self.sq.build_query()), u'Xapian::Query(((<alldocuments> AND_NOT (Zhello OR hello)) OR (<alldocuments> AND_NOT (Zworld OR world))))')
    
    def test_build_query_multiple_words_mixed(self):
        self.sq.add_filter(SQ(content='why') | SQ(content='hello'))
        self.sq.add_filter(~SQ(content='world'))
        self.assertEqual(str(self.sq.build_query()), u'Xapian::Query(((Zwhi OR why OR Zhello OR hello) AND (<alldocuments> AND_NOT (Zworld OR world))))')
    
    def test_build_query_multiple_word_field_exact(self):
        self.sq.add_filter(SQ(foo='hello'))
        self.sq.add_filter(SQ(bar='world'))
        self.assertEqual(str(self.sq.build_query()), u'Xapian::Query(((ZXFOOhello OR XFOOhello) AND (ZXBARworld OR XBARworld)))')
    
    def test_build_query_multiple_word_field_exact_not(self):
        self.sq.add_filter(~SQ(foo='hello'))
        self.sq.add_filter(~SQ(bar='world'))
        self.assertEqual(str(self.sq.build_query()), u'Xapian::Query(((<alldocuments> AND_NOT (ZXFOOhello OR XFOOhello)) AND (<alldocuments> AND_NOT (ZXBARworld OR XBARworld))))')
    
    def test_build_query_phrase(self):
        self.sq.add_filter(SQ(content='hello world'))
        self.assertEqual(str(self.sq.build_query()), u'Xapian::Query((hello PHRASE 2 world))')
    
    def test_build_query_phrase_not(self):
        self.sq.add_filter(~SQ(content='hello world'))
        self.assertEqual(str(self.sq.build_query()), u'Xapian::Query((<alldocuments> AND_NOT (hello PHRASE 2 world)))')
    
    def test_build_query_boost(self):
        self.sq.add_filter(SQ(content='hello'))
        self.sq.add_boost('world', 5)
        self.assertEqual(str(self.sq.build_query()), u'Xapian::Query(((Zhello OR hello) AND_MAYBE 5 * world))')
    
#.........这里部分代码省略.........
开发者ID:Pandolfo87,项目名称:xapian-haystack,代码行数:103,代码来源:xapian_query.py


注:本文中的haystack.backends.xapian_backend.SearchQuery.add_boost方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。