OLD | NEW |
(Empty) | |
| 1 # Copyright (c) 202 Mitch Garnaat http://garnaat.org/ |
| 2 # Copyright (c) 2012 Amazon.com, Inc. or its affiliates. |
| 3 # All Rights Reserved |
| 4 # |
| 5 # Permission is hereby granted, free of charge, to any person obtaining a |
| 6 # copy of this software and associated documentation files (the |
| 7 # "Software"), to deal in the Software without restriction, including |
| 8 # without limitation the rights to use, copy, modify, merge, publish, dis- |
| 9 # tribute, sublicense, and/or sell copies of the Software, and to permit |
| 10 # persons to whom the Software is furnished to do so, subject to the fol- |
| 11 # lowing conditions: |
| 12 # |
| 13 # The above copyright notice and this permission notice shall be included |
| 14 # in all copies or substantial portions of the Software. |
| 15 # |
| 16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 17 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- |
| 18 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT |
| 19 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 20 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 22 # IN THE SOFTWARE. |
| 23 |
| 24 class SourceAttribute(object): |
| 25 """ |
| 26 Provide information about attributes for an index field. |
| 27 A maximum of 20 source attributes can be configured for |
| 28 each index field. |
| 29 |
| 30 :ivar default: Optional default value if the source attribute |
| 31 is not specified in a document. |
| 32 |
| 33 :ivar name: The name of the document source field to add |
| 34 to this ``IndexField``. |
| 35 |
| 36 :ivar data_function: Identifies the transformation to apply |
| 37 when copying data from a source attribute. |
| 38 |
| 39 :ivar data_map: The value is a dict with the following keys: |
| 40 * cases - A dict that translates source field values |
| 41 to custom values. |
| 42 * default - An optional default value to use if the |
| 43 source attribute is not specified in a document. |
| 44 * name - the name of the document source field to add |
| 45 to this ``IndexField`` |
| 46 :ivar data_trim_title: Trims common title words from a source |
| 47 document attribute when populating an ``IndexField``. |
| 48 This can be used to create an ``IndexField`` you can |
| 49 use for sorting. The value is a dict with the following |
| 50 fields: |
| 51 * default - An optional default value. |
| 52 * language - an IETF RFC 4646 language code. |
| 53 * separator - The separator that follows the text to trim. |
| 54 * name - The name of the document source field to add. |
| 55 """ |
| 56 |
| 57 ValidDataFunctions = ('Copy', 'TrimTitle', 'Map') |
| 58 |
| 59 def __init__(self): |
| 60 self.data_copy = {} |
| 61 self._data_function = self.ValidDataFunctions[0] |
| 62 self.data_map = {} |
| 63 self.data_trim_title = {} |
| 64 |
| 65 @property |
| 66 def data_function(self): |
| 67 return self._data_function |
| 68 |
| 69 @data_function.setter |
| 70 def data_function(self, value): |
| 71 if value not in self.ValidDataFunctions: |
| 72 valid = '|'.join(self.ValidDataFunctions) |
| 73 raise ValueError('data_function must be one of: %s' % valid) |
| 74 self._data_function = value |
| 75 |
OLD | NEW |