1 # ====================================================================
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at
6 # http://www.apache.org/licenses/LICENSE-2.0
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
13 # ====================================================================
15 from lia.common.LiaTestCase import LiaTestCase
16 from lia.extsearch.filters.TestSpecialsAccessor import TestSpecialsAccessor
17 from lia.extsearch.filters.SpecialsFilter import SpecialsFilter
20 WildcardQuery, FilteredQuery, TermQuery, BooleanQuery, TermRangeQuery, \
21 IndexSearcher, Term, BooleanClause, MatchAllDocsQuery
24 class SpecialsFilterTest(LiaTestCase):
28 super(SpecialsFilterTest, self).setUp()
30 self.allBooks = MatchAllDocsQuery()
31 self.searcher = IndexSearcher(self.directory, True)
33 def testCustomFilter(self):
35 isbns = ["0060812451", "0465026567"]
36 accessor = TestSpecialsAccessor(isbns)
38 filter = SpecialsFilter(accessor)
39 topDocs = self.searcher.search(self.allBooks, filter, 50)
40 self.assertEquals(len(isbns), topDocs.totalHits, "the specials")
42 def testFilteredQuery(self):
44 isbns = ["0854402624"] # Steiner
46 accessor = TestSpecialsAccessor(isbns)
47 filter = SpecialsFilter(accessor)
49 educationBooks = WildcardQuery(Term("category", "*education*"))
50 edBooksOnSpecial = FilteredQuery(educationBooks, filter)
52 logoBooks = TermQuery(Term("subject", "logo"))
54 logoOrEdBooks = BooleanQuery()
55 logoOrEdBooks.add(logoBooks, BooleanClause.Occur.SHOULD)
56 logoOrEdBooks.add(edBooksOnSpecial, BooleanClause.Occur.SHOULD)
58 topDocs = self.searcher.search(logoOrEdBooks, 50)
60 self.assertEqual(2, topDocs.totalHits, "Papert and Steiner")