@@ -474,18 +474,41 @@ class PagesSearchTest(BaseGrappleTest):
474474 @classmethod
475475 def setUpTestData (cls ):
476476 cls .home = HomePage .objects .first ()
477- BlogPageFactory (title = "Alpha" , parent = cls .home , show_in_menus = True )
478- BlogPageFactory (title = "Alpha Alpha" , parent = cls .home )
479- BlogPageFactory (title = "Alpha Beta" , parent = cls .home )
480- BlogPageFactory (title = "Alpha Gamma" , parent = cls .home )
481- BlogPageFactory (title = "Beta" , parent = cls .home )
482- BlogPageFactory (title = "Beta Alpha" , parent = cls .home )
483- BlogPageFactory (title = "Beta Beta" , parent = cls .home )
484- BlogPageFactory (title = "Beta Gamma" , parent = cls .home )
485- BlogPageFactory (title = "Gamma" , parent = cls .home )
486- BlogPageFactory (title = "Gamma Alpha" , parent = cls .home )
487- BlogPageFactory (title = "Gamma Beta" , parent = cls .home )
488- BlogPageFactory (title = "Gamma Gamma" , parent = cls .home )
477+ BlogPageFactory (
478+ title = "Alpha" ,
479+ body = [("heading" , "Sigma" )],
480+ parent = cls .home ,
481+ show_in_menus = True ,
482+ )
483+ BlogPageFactory (
484+ title = "Alpha Alpha" , body = [("heading" , "Sigma Sigma" )], parent = cls .home
485+ )
486+ BlogPageFactory (
487+ title = "Alpha Beta" , body = [("heading" , "Sigma Theta" )], parent = cls .home
488+ )
489+ BlogPageFactory (
490+ title = "Alpha Gamma" , body = [("heading" , "Sigma Delta" )], parent = cls .home
491+ )
492+ BlogPageFactory (title = "Beta" , body = [("heading" , "Theta" )], parent = cls .home )
493+ BlogPageFactory (
494+ title = "Beta Alpha" , body = [("heading" , "Theta Sigma" )], parent = cls .home
495+ )
496+ BlogPageFactory (
497+ title = "Beta Beta" , body = [("heading" , "Theta Theta" )], parent = cls .home
498+ )
499+ BlogPageFactory (
500+ title = "Beta Gamma" , body = [("heading" , "Theta Delta" )], parent = cls .home
501+ )
502+ BlogPageFactory (title = "Gamma" , body = [("heading" , "Delta" )], parent = cls .home )
503+ BlogPageFactory (
504+ title = "Gamma Alpha" , body = [("heading" , "Delta Sigma" )], parent = cls .home
505+ )
506+ BlogPageFactory (
507+ title = "Gamma Beta" , body = [("heading" , "Delta Theta" )], parent = cls .home
508+ )
509+ BlogPageFactory (
510+ title = "Gamma Gamma" , body = [("heading" , "Delta Delta" )], parent = cls .home
511+ )
489512
490513 @unittest .skipIf (
491514 connection .vendor != "sqlite" ,
@@ -530,7 +553,6 @@ def test_searchQuery_order_by_relevance(self):
530553 }
531554 }
532555 """
533-
534556 executed = self .client .execute (query , variables = {"searchQuery" : "Alpha" })
535557 page_data = executed ["data" ].get ("pages" )
536558 self .assertEqual (len (page_data ), 6 )
@@ -559,7 +581,6 @@ def test_explicit_order(self):
559581 query , variables = {"searchQuery" : "Gamma" , "order" : "-title" }
560582 )
561583 page_data = executed ["data" ].get ("pages" )
562-
563584 self .assertEqual (len (page_data ), 6 )
564585 self .assertEqual (page_data [0 ]["title" ], "Gamma Gamma" )
565586 self .assertEqual (page_data [1 ]["title" ], "Gamma Beta" )
@@ -593,6 +614,64 @@ def test_search_not_in_menus(self):
593614 page_data = executed ["data" ].get ("pages" )
594615 self .assertEqual (len (page_data ), 12 ) # 11 blog pages + home page
595616
617+ def test_search_operator_default (self ):
618+ """default operator is and"""
619+ query = """
620+ query($searchQuery: String) {
621+ pages(searchQuery: $searchQuery) {
622+ title
623+ searchScore
624+ }
625+ }
626+ """
627+ executed = self .client .execute (query , variables = {"searchQuery" : "Alpha Beta" })
628+ page_data = executed ["data" ].get ("pages" )
629+ self .assertEqual (len (page_data ), 2 )
630+ self .assertEqual (page_data [0 ]["title" ], "Alpha Beta" )
631+ self .assertEqual (page_data [1 ]["title" ], "Beta Alpha" )
632+
633+ def test_search_operator_and (self ):
634+ query = """
635+ query($searchQuery: String, $searchOperator: SearchOperatorEnum) {
636+ pages(searchQuery: $searchQuery, searchOperator: $searchOperator) {
637+ title
638+ searchScore
639+ }
640+ }
641+ """
642+ executed = self .client .execute (
643+ query , variables = {"searchQuery" : "Alpha Beta" , "searchOperator" : "AND" }
644+ )
645+ page_data = executed ["data" ].get ("pages" )
646+ self .assertEqual (len (page_data ), 2 )
647+ self .assertEqual (page_data [0 ]["title" ], "Alpha Beta" )
648+ self .assertEqual (page_data [1 ]["title" ], "Beta Alpha" )
649+
650+ def test_search_operator_or (self ):
651+ query = """
652+ query($searchQuery: String, $searchOperator: SearchOperatorEnum) {
653+ pages(searchQuery: $searchQuery, searchOperator: $searchOperator) {
654+ title
655+ searchScore
656+ }
657+ }
658+ """
659+ executed = self .client .execute (
660+ query , variables = {"searchQuery" : "Alpha Beta" , "searchOperator" : "OR" }
661+ )
662+ page_data = executed ["data" ].get ("pages" )
663+ self .assertEqual (len (page_data ), 10 )
664+ self .assertEqual (page_data [0 ]["title" ], "Alpha" )
665+ self .assertEqual (page_data [1 ]["title" ], "Alpha Alpha" )
666+ self .assertEqual (page_data [2 ]["title" ], "Alpha Beta" )
667+ self .assertEqual (page_data [3 ]["title" ], "Alpha Gamma" )
668+ self .assertEqual (page_data [4 ]["title" ], "Beta" )
669+ self .assertEqual (page_data [5 ]["title" ], "Beta Alpha" )
670+ self .assertEqual (page_data [6 ]["title" ], "Beta Beta" )
671+ self .assertEqual (page_data [7 ]["title" ], "Beta Gamma" )
672+ self .assertEqual (page_data [8 ]["title" ], "Gamma Alpha" )
673+ self .assertEqual (page_data [9 ]["title" ], "Gamma Beta" )
674+
596675
597676class PageUrlPathTest (BaseGrappleTest ):
598677 def _query_by_path (self , path , * , in_site = False ):
0 commit comments