Ejemplo n.º 1
0
 def testTermVectorsForField(self):
     registry = FieldRegistry(termVectorFields=['field1', 'field2'])
     self.assertTrue(registry.isTermVectorField('field1'))
     self.assertTrue(registry.isTermVectorField('field2'))
     self.assertFalse(registry.isTermVectorField('field3'))
     field = registry.createField('field1', 'id:1')
     self.assertEquals({
             "type": "TextField",
             "name": "field1",
             "value": "id:1",
             "termVectors": True,
         }, field)
     field = registry.createField('field2', 'id:1')
     self.assertEquals({
             "type": "TextField",
             "name": "field2",
             "value": "id:1",
             "termVectors": True,
         }, field)
     field = registry.createField('field3', 'id:1')
     self.assertEquals({
             "type": "TextField",
             "name": "field3",
             "value": "id:1",
         }, field)
Ejemplo n.º 2
0
 def testSpecificField(self):
     registry = FieldRegistry()
     field = registry.createField('fieldname', 'value')
     self.assertFalse(field.fieldType().stored())
     registry.register('fieldname', StringField.TYPE_STORED)
     field = registry.createField('fieldname', 'value')
     self.assertTrue(field.fieldType().stored())
Ejemplo n.º 3
0
 def testTermVectorsForField(self):
     registry = FieldRegistry(termVectorFields=['field1', 'field2'])
     self.assertTrue(registry.isTermVectorField('field1'))
     self.assertTrue(registry.isTermVectorField('field2'))
     self.assertFalse(registry.isTermVectorField('field3'))
     field = registry.createField('field1', 'id:1')
     self.assertEquals({
             "type": "TextField",
             "name": "field1",
             "value": "id:1",
             "termVectors": True,
         }, field)
     field = registry.createField('field2', 'id:1')
     self.assertEquals({
             "type": "TextField",
             "name": "field2",
             "value": "id:1",
             "termVectors": True,
         }, field)
     field = registry.createField('field3', 'id:1')
     self.assertEquals({
             "type": "TextField",
             "name": "field3",
             "value": "id:1",
         }, field)
Ejemplo n.º 4
0
 def testReuseCreatedField(self):
     registry = FieldRegistry()
     field = registry.createField('fieldname', 'value')
     self.assertEquals("value", field.stringValue())
     newField = registry.createField('fieldname', 'newvalue', mayReUse=True)
     self.assertEquals("newvalue", newField.stringValue())
     self.assertEquals(field, newField)
     newField2 = registry.createField('fieldname',
                                      'newvalue',
                                      mayReUse=False)
     self.assertEquals("newvalue", newField2.stringValue())
     self.assertNotEqual(newField, newField2)
Ejemplo n.º 5
0
 def testAddWithoutIdentifier(self):
     registry = FieldRegistry()
     fields = [registry.createField("id", "id1")]
     consume(self._lucene.addDocument(fields=fields))
     self.assertEqual(1, len(self.post))
     self.assertEqual('/lucene/update/?', self.post[0]['path'])
     self.assertEqual('[{"type": "TextField", "name": "id", "value": "id1"}]', self.post[0]['data'])
Ejemplo n.º 6
0
 def testSpecificField(self):
     registry = FieldRegistry()
     field = registry.createField('fieldname', 'value')
     self.assertEquals({
             "type": "TextField",
             "name": "fieldname",
             "value": "value",
         }, field)
     registry.register('fieldname', STRINGFIELD_STORED)
     field = registry.createField('fieldname', 'value')
     self.assertEquals({
             "type": "StringField",
             "name": "fieldname",
             "value": "value",
             "stored": True
         }, field)
Ejemplo n.º 7
0
 def testDefault(self):
     registry = FieldRegistry()
     field = registry.createField('__id__', 'id:1')
     self.assertFalse(field.fieldType().tokenized())
     self.assertTrue(field.fieldType().stored())
     self.assertTrue(field.fieldType().indexed())
     self.assertTrue(registry.isUntokenized('__id__'))
Ejemplo n.º 8
0
 def testSpecificField(self):
     registry = FieldRegistry()
     field = registry.createField('fieldname', 'value')
     self.assertEquals({
             "type": "TextField",
             "name": "fieldname",
             "value": "value",
         }, field)
     registry.register('fieldname', STRINGFIELD_STORED)
     field = registry.createField('fieldname', 'value')
     self.assertEquals({
             "type": "StringField",
             "name": "fieldname",
             "value": "value",
             "stored": True
         }, field)
Ejemplo n.º 9
0
 def testAddWithoutIdentifier(self):
     registry = FieldRegistry()
     fields = [registry.createField("id", "id1")]
     consume(self._lucene.addDocument(fields=fields))
     self.assertEqual(1, len(self.post))
     self.assertEqual('/lucene/update/?', self.post[0]['path'])
     self.assertEqual('[{"type": "TextField", "name": "id", "value": "id1"}]', self.post[0]['data'])
Ejemplo n.º 10
0
    def testDefaultDefinition(self):
        registry = FieldRegistry()
        field = registry.createField('aField', 'id:1')
        self.assertEquals({
                "type": "TextField",
                "name": "aField",
                "value": "id:1",
            }, field)
        self.assertFalse(registry.isUntokenized('aField'))

        registry = FieldRegistry(defaultDefinition=STRINGFIELD)
        field = registry.createField('aField', 'id:1')
        self.assertEquals({
                "type": "StringField",
                "name": "aField",
                "value": "id:1",
            }, field)
        self.assertTrue(registry.isUntokenized('aField'))
Ejemplo n.º 11
0
 def testNumericField(self):
     registry = FieldRegistry()
     registry.register('fieldname', NUMERICFIELD)
     field = registry.createField('fieldname', 2010)
     self.assertEquals({
             "type": "NumericField",
             "name": "fieldname",
             "value": 2010,
         }, field)
Ejemplo n.º 12
0
 def testNoTermsFreqField(self):
     registry = FieldRegistry()
     registry.register('fieldname', NO_TERMS_FREQUENCY_FIELD)
     field = registry.createField('fieldname', 'value')
     self.assertEquals({
             "type": "NoTermsFrequencyField",
             "name": "fieldname",
             "value": "value",
         }, field)
Ejemplo n.º 13
0
 def testDefault(self):
     registry = FieldRegistry()
     field = registry.createField('__id__', 'id:1')
     self.assertEquals({
             "type": "StringField",
             "name": "__id__",
             "value": "id:1",
             "stored": True
         }, field)
Ejemplo n.º 14
0
    def testDefaultDefinition(self):
        registry = FieldRegistry()
        field = registry.createField('aField', 'id:1')
        self.assertEquals({
                "type": "TextField",
                "name": "aField",
                "value": "id:1",
            }, field)
        self.assertFalse(registry.isUntokenized('aField'))

        registry = FieldRegistry(defaultDefinition=STRINGFIELD)
        field = registry.createField('aField', 'id:1')
        self.assertEquals({
                "type": "StringField",
                "name": "aField",
                "value": "id:1",
            }, field)
        self.assertTrue(registry.isUntokenized('aField'))
Ejemplo n.º 15
0
 def testNumericField(self):
     registry = FieldRegistry()
     registry.register('fieldname', NUMERICFIELD)
     field = registry.createField('fieldname', 2010)
     self.assertEquals({
             "type": "NumericField",
             "name": "fieldname",
             "value": 2010,
         }, field)
Ejemplo n.º 16
0
 def testNoTermsFreqField(self):
     registry = FieldRegistry()
     registry.register('fieldname', NO_TERMS_FREQUENCY_FIELD)
     field = registry.createField('fieldname', 'value')
     self.assertEquals({
             "type": "NoTermsFrequencyField",
             "name": "fieldname",
             "value": "value",
         }, field)
Ejemplo n.º 17
0
 def testDefault(self):
     registry = FieldRegistry()
     field = registry.createField('__id__', 'id:1')
     self.assertEquals({
             "type": "StringField",
             "name": "__id__",
             "value": "id:1",
             "stored": True
         }, field)
Ejemplo n.º 18
0
    def testSortField(self):
        registry = FieldRegistry()
        registry.register("sorted.longfield", fieldDefinition=LONGFIELD)
        registry.register("sorted.intfield", fieldDefinition=INTFIELD)
        registry.register("sorted.stringfield", fieldDefinition=STRINGFIELD)

        self.assertEqual("Long", registry.sortFieldType("sorted.longfield"))
        self.assertEqual(None, registry.defaultMissingValueForSort("sorted.longfield", True))

        self.assertEqual("Int", registry.sortFieldType("sorted.intfield"))
        self.assertEqual(None, registry.defaultMissingValueForSort("sorted.intfield", True))

        self.assertEqual("String", registry.sortFieldType("sorted.stringfield"))
        self.assertEqual("STRING_FIRST", registry.defaultMissingValueForSort("sorted.stringfield", True))
        self.assertEqual("STRING_LAST", registry.defaultMissingValueForSort("sorted.stringfield", False))
        self.assertEqual(None, registry.defaultMissingValueForSort("score", False))

        field = registry.createField('sorted.longfield', 'id:1')
        self.assertEqual({'name': 'sorted.longfield', 'type': 'LongField', 'value': 'id:1', 'sort': True}, field)
Ejemplo n.º 19
0
    def testSortField(self):
        registry = FieldRegistry()
        registry.register("sorted.longfield", fieldDefinition=LONGFIELD)
        registry.register("sorted.intfield", fieldDefinition=INTFIELD)
        registry.register("sorted.stringfield", fieldDefinition=STRINGFIELD)

        self.assertEqual("Long", registry.sortFieldType("sorted.longfield"))
        self.assertEqual(JAVA_MIN_LONG, registry.defaultMissingValueForSort("sorted.longfield", True))
        self.assertEqual(JAVA_MAX_LONG, registry.defaultMissingValueForSort("sorted.longfield", False))

        self.assertEqual("Int", registry.sortFieldType("sorted.intfield"))
        self.assertEqual(JAVA_MIN_INT, registry.defaultMissingValueForSort("sorted.intfield", True))
        self.assertEqual(JAVA_MAX_INT, registry.defaultMissingValueForSort("sorted.intfield", False))

        self.assertEqual("String", registry.sortFieldType("sorted.stringfield"))
        self.assertEqual("STRING_FIRST", registry.defaultMissingValueForSort("sorted.stringfield", True))
        self.assertEqual("STRING_LAST", registry.defaultMissingValueForSort("sorted.stringfield", False))

        self.assertEqual(None, registry.defaultMissingValueForSort("score", False))

        field = registry.createField('sorted.longfield', '1')
        self.assertEqual({'name': 'sorted.longfield', 'type': 'LongField', 'value': 1, 'sort': True}, field)
Ejemplo n.º 20
0
 def testNoTermsFreqField(self):
     registry = FieldRegistry()
     registry.register('fieldname', NO_TERMS_FREQUENCY_FIELDTYPE)
     field = registry.createField('fieldname', 'value')
     self.assertEquals(FieldInfo.IndexOptions.DOCS_ONLY,
                       field.fieldType().indexOptions())