@@ 98-128 (lines=31) @@ | ||
95 | } |
|
96 | ||
97 | ||
98 | public function testMultiMatchWithText() { |
|
99 | $qg = new QueryGenerator(); |
|
100 | $qg->setQueryText('New Zealand'); |
|
101 | $fields = array('Title' => 1, 'Description' => 1); |
|
102 | $qg->setFields($fields); |
|
103 | $qg->setSelectedFilters(null); |
|
104 | $qg->setClasses('FlickrPhotoTO'); |
|
105 | ||
106 | //As the query is not empty it should not matter whether or not the show results for empty |
|
107 | //query flag is set or not - test with true and false |
|
108 | ||
109 | $qg->setShowResultsForEmptyQuery(false); |
|
110 | $qs = array('multi_match' => array( |
|
111 | 'fields' => array('Title','Title.*','Description','Description.*'), |
|
112 | 'type' => 'most_fields', |
|
113 | 'query' => 'New Zealand', |
|
114 | 'lenient' => true |
|
115 | ) |
|
116 | ); |
|
117 | $expected = array( |
|
118 | 'query' => $qs, |
|
119 | 'size' => 10, |
|
120 | 'from' => 0, |
|
121 | 'suggest' => $this->getDefaultSuggest('New Zealand') |
|
122 | ); |
|
123 | ||
124 | $this->assertEquals($expected, $qg->generateElasticaQuery()->toArray()); |
|
125 | ||
126 | $qg->setShowResultsForEmptyQuery(true); |
|
127 | $this->assertEquals($expected, $qg->generateElasticaQuery()->toArray()); |
|
128 | } |
|
129 | ||
130 | ||
131 | ||
@@ 132-167 (lines=36) @@ | ||
129 | ||
130 | ||
131 | ||
132 | public function testMultiMatchWithNoText() { |
|
133 | $qg = new QueryGenerator(); |
|
134 | $qg->setQueryText(''); |
|
135 | $fields = array('Title' => 1, 'Description' => 1); |
|
136 | $qg->setFields($fields); |
|
137 | $qg->setSelectedFilters(null); |
|
138 | $qg->setClasses('FlickrPhotoTO'); |
|
139 | ||
140 | //As the query is not empty it should not matter whether or not the show results for empty |
|
141 | //query flag is set or not - test with true and false |
|
142 | ||
143 | //Case of empty query, do not show results |
|
144 | $qg->setShowResultsForEmptyQuery(false); |
|
145 | $qs = array( |
|
146 | 'multi_match' => array( |
|
147 | 'fields' => array('Title','Title.*','Description','Description.*'), |
|
148 | 'type' => 'most_fields', |
|
149 | 'query' => '', |
|
150 | 'lenient' => true |
|
151 | ) |
|
152 | ); |
|
153 | $expected = array( |
|
154 | 'query' => $qs, |
|
155 | 'size' => 10, |
|
156 | 'from' => 0, |
|
157 | 'suggest' => $this->getDefaultSuggest('') |
|
158 | ); |
|
159 | ||
160 | $this->assertEquals($expected, $qg->generateElasticaQuery()->toArray()); |
|
161 | ||
162 | ||
163 | // Now the case of empty query and show results |
|
164 | $qg->setShowResultsForEmptyQuery(true); |
|
165 | unset($expected['query']); |
|
166 | $this->assertEquals($expected, $qg->generateElasticaQuery()->toArray()); |
|
167 | } |
|
168 | ||
169 | ||
170 | // ---- tests with aggregations ---- |