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 # ====================================================================
17 from lucene import Document, Field
18 from lia.handlingtypes.xml.Digester import Digester
21 class DigesterXMLHandler(object):
25 self.digester = digester = Digester()
27 digester.addSetProperty("address-book/contact", "type", "type")
28 digester.addSetProperty("address-book/contact/name", "name")
29 digester.addSetProperty("address-book/contact/address", "address")
30 digester.addSetProperty("address-book/contact/city", "city")
31 digester.addSetProperty("address-book/contact/province", "province")
32 digester.addSetProperty("address-book/contact/postalcode", "postalcode")
33 digester.addSetProperty("address-book/contact/country", "country")
34 digester.addSetProperty("address-book/contact/telephone", "telephone")
36 def indexFile(self, writer, path):
43 props = self.digester.parse(file)
45 doc.add(Field("type", props['type'],
46 Field.Store.YES, Field.Index.NOT_ANALYZED))
47 doc.add(Field("name", props['name'],
48 Field.Store.YES, Field.Index.NOT_ANALYZED))
49 doc.add(Field("address", props['address'],
50 Field.Store.YES, Field.Index.NOT_ANALYZED))
51 doc.add(Field("city", props['city'],
52 Field.Store.YES, Field.Index.NOT_ANALYZED))
53 doc.add(Field("province", props['province'],
54 Field.Store.YES, Field.Index.NOT_ANALYZED))
55 doc.add(Field("postalcode", props['postalcode'],
56 Field.Store.YES, Field.Index.NOT_ANALYZED))
57 doc.add(Field("country", props['country'],
58 Field.Store.YES, Field.Index.NOT_ANALYZED))
59 doc.add(Field("telephone", props['telephone'],
60 Field.Store.YES, Field.Index.NOT_ANALYZED))
61 doc.add(Field("filename", os.path.abspath(path),
62 Field.Store.YES, Field.Index.NOT_ANALYZED))
63 writer.addDocument(doc)