예제 #1
0
    def test_geo_point(self):
        index = self._create_index('test')
        doc_type = index.get_doc_type('test')
        doc_type.mapping = {
            'point': {
                'type': 'geo_point'
            }
        }
        doc_type.add_document(pylastica.Document(1, {'name': 'Linn'}).add_geopoint('point', 17, 19))
        doc_type.add_document(pylastica.Document(2, {'name': 'Linn'}).add_geopoint('point', 30, 40))
        index.refresh()
        query = pylastica.query.Query()
        points = [
            [16, 16],
            [16, 20],
            [20, 20],
            [20, 16],
            [16, 16]
        ]
        geo_filter = pylastica.filter.GeoPolygon('point', points)
        query.set_filter(geo_filter)
        self.assertEqual(1, len(doc_type.search(query)))

        query = pylastica.query.Query()
        points = [
            [16, 16],
            [16, 40],
            [40, 40],
            [40, 16],
            [16, 16]
        ]
        geo_filter = pylastica.filter.GeoPolygon('point', points)
        query.set_filter(geo_filter)
        self.assertEqual(2, len(doc_type.search(query)))
        index.delete()
예제 #2
0
    def test_query(self):
        client = self._get_client()
        index = client.get_index('test')
        index.create(options=True)
        doc_type = index.get_doc_type('test')

        doc_type.add_document(pylastica.Document(1, {
            'age': 16,
            'height': 140
        }))
        doc_type.add_document(pylastica.Document(2, {
            'age': 21,
            'height': 155
        }))
        doc_type.add_document(pylastica.Document(3, {
            'age': 33,
            'height': 160
        }))
        doc_type.add_document(pylastica.Document(4, {
            'age': 68,
            'height': 160
        }))

        index.optimize()
        index.refresh()

        query = pylastica.query.Range('age', {'from': 10, 'to': 20})
        result = doc_type.search(query)
        self.assertEqual(1, len(result))

        query = pylastica.query.Range('height', {'gte': 160})
        result = doc_type.search(query)
        self.assertEqual(2, len(result))
        index.delete()
예제 #3
0
    def test_filter(self):
        index = self._create_index('geohash_filter_test')
        doc_type = index.get_doc_type('test')
        mapping = pylastica.doc_type.Mapping(doc_type, {
            'pin': {
                'type': 'geo_point',
                'geohash': True,
                'geohash_prefix': True
            }
        })
        doc_type.mapping = mapping

        doc_type.add_document(pylastica.Document(1, {'pin': '9q8yyzm0zpw8'}))
        doc_type.add_document(pylastica.Document(2, {'pin': '9mudgb0yued0'}))
        index.refresh()

        geohash_cell_filter = pylastica.filter.GeohashCell(
            'pin', {
                'lat': 32.828326,
                'lon': -117.255854
            })
        query = pylastica.query.Query().set_filter(geohash_cell_filter)
        results = doc_type.search(query)

        self.assertEqual(1, len(results.results))

        geohash_cell_filter = pylastica.filter.GeohashCell('pin', '9', 1)
        query = pylastica.query.Query().set_filter(geohash_cell_filter)
        results = doc_type.search(query)

        self.assertEqual(2, len(results.results))

        index.delete()
예제 #4
0
    def test_different_prefixes(self):
        index = self._create_index('test')
        doc_type = index.get_doc_type('test')
        mapping = pylastica.doc_type.Mapping(doc_type, {
            'name': {
                'type': 'string',
                'store': 'no',
                'index': 'not_analyzed'
            }
        })
        doc_type.mapping = mapping

        doc_type.add_document(pylastica.Document(1, {'name': 'San Diego'}))
        doc_type.add_document(
            pylastica.Document(2, {'name': 'San Luis Obispo'}))
        doc_type.add_document(pylastica.Document(3, {'name': 'San Francisco'}))
        doc_type.add_document(pylastica.Document(4, {'name': 'New Orleans'}))
        doc_type.add_document(pylastica.Document(5, {'name': 'New York'}))

        index.refresh()

        query = pylastica.filter.Prefix('name', 'Sa')
        self.assertEqual(3, len(doc_type.search(query)))

        query = pylastica.filter.Prefix('name', 'sa')
        self.assertEqual(0, len(doc_type.search(query)))

        query = pylastica.filter.Prefix('name', 'San D')
        self.assertEqual(1, len(doc_type.search(query)))

        query = pylastica.filter.Prefix('name', 'San Db')
        self.assertEqual(0, len(doc_type.search(query)))
        index.delete()
예제 #5
0
    def test_facet_script(self):
        client = self._get_client()
        index = client.get_index('test')
        index.create(options=True)
        doc_type = index.get_doc_type('helloworld')

        doc_type.add_document(
            pylastica.Document(1, {
                'name': 'Tyler',
                'last_name': 'Durden'
            }))
        doc_type.add_document(
            pylastica.Document(2, {
                'name': 'Marla',
                'last_name': 'Singer'
            }))

        index.refresh()
        facet = pylastica.facet.Terms('test')
        facet.set_field('name')
        facet.set_script(
            pylastica.Script('term + " " + doc["last_name"].value'))
        query = pylastica.query.Query()
        query.add_facet(facet)
        response = doc_type.search(query)
        facets = response.get_facets()
        self.assertEqual(2, len(facets['test']['terms']))
        index.delete()
예제 #6
0
    def test_highlight_search(self):
        index = self._create_index()
        doc_type = index.get_doc_type('helloworld')
        phrase = 'My name is Joe'
        doc_type.add_document(pylastica.Document(1, {'id': 1, 'phrase': phrase, 'username': '******', 'test': ['2', '3', '5']}))
        doc_type.add_document(pylastica.Document(2, {'id': 2, 'phrase': phrase, 'username': '******', 'test': ['2', '3', '5']}))
        index.refresh()

        query_string = pylastica.query.QueryString('jo*')
        query = pylastica.query.Query(query_string)
        query.set_highlight({
            'pre_tags': ['<em class="highlight">'],
            'post_tags': ['</em>'],
            'fields': {
                'phrase': {
                    'fragment_size': 200,
                    'number_of_fragments': 1
                }
            }
        })
        result_set = doc_type.search(query)
        for result in result_set:
            highlight = result.get_highlights()
            self.assertEqual({'phrase': ['My name is <em class="highlight">Joe</em>']}, highlight)
        self.assertEqual(2, len(result_set))
        index.delete()
예제 #7
0
 def test_parent(self):
     index = self._create_index()
     type_blog = pylastica.doc_type.DocType(index, 'blog')
     type_comment = pylastica.doc_type.DocType(index, 'comment')
     mapping = pylastica.doc_type.Mapping()
     mapping.set_param('_parent', {'type': 'blog'})
     type_comment.mapping = mapping
     entry_1 = pylastica.Document(1)
     entry_1.set('title', "Hello world!")
     type_blog.add_document(entry_1)
     entry_2 = pylastica.Document(2)
     entry_2.set('title', 'Foo bar')
     type_blog.add_document(entry_2)
     entry_3 = pylastica.Document(3)
     entry_3.set('title', 'Till dawn')
     type_blog.add_document(entry_3)
     comment = pylastica.Document(1)
     comment.set('author', 'Max')
     comment.parent = 2
     type_comment.add_document(comment)
     index.optimize()
     query = pylastica.query.HasChild('Max', 'comment')
     result_set = type_blog.search(query)
     self.assertEqual(1, len(result_set))
     self.assertEqual({'title': 'Foo bar'}, result_set[0].data)
     index.delete()
예제 #8
0
 def test_search_request(self):
     if not self._has_thrift:
         self.skipTest('The transport-thrift plugin is not installed.')
     index = self._client.get_index('pylastica_test1')
     index.create(options=True)
     doc_type = index.get_doc_type('user')
     doc_type.add_document(
         pylastica.Document(1, {
             'username': '******',
             'test': ['2', '3', '5']
         }))
     docs = [
         pylastica.Document(2, {
             'username': '******',
             'test': ['1', '3', '6']
         }),
         pylastica.Document(3, {
             'username': '******',
             'test': ['2', '3', '7']
         })
     ]
     doc_type.add_documents(docs)
     index.refresh()
     result_set = doc_type.search('jim')
     self.assertEqual(1, result_set.get_total_hits())
     index.delete()
예제 #9
0
    def test_geo_point(self):
        index = self._create_index('test')
        doc_type = index.get_doc_type('test')
        doc_type.mapping = {'point': {'type': 'geo_point'}}
        doc_type.add_document(
            pylastica.Document(1, {
                'name': 'Linn'
            }).add_geopoint('point', 17, 19))
        doc_type.add_document(
            pylastica.Document(2, {
                'name': 'Linn'
            }).add_geopoint('point', 30, 40))
        index.refresh()

        query = pylastica.query.Query()
        geo_filter = pylastica.filter.GeoDistance('point', {
            'lat': 30,
            'lon': 40
        }, '1km')
        query.set_filter(geo_filter)
        self.assertEqual(1, len(doc_type.search(query)))

        query = pylastica.query.Query()
        geo_filter = pylastica.filter.GeoDistance('point', {
            'lat': 30,
            'lon': 40
        }, '40000km')
        query.set_filter(geo_filter)
        self.assertEqual(2, len(doc_type.search(query)))
        index.delete()
예제 #10
0
 def test_upsert(self):
     doc = pylastica.Document()
     upsert = pylastica.Document()
     upsert.data = {'someproperty': 'somevalue'}
     self.assertFalse(doc.has_upsert())
     doc.upsert = upsert
     self.assertTrue(doc.has_upsert())
     self.assertEqual(upsert, doc.upsert)
예제 #11
0
    def test_search(self):
        client = self._get_client()
        index = client.get_index('test')
        index.create(options=True)
        doc_type = index.get_doc_type('helloworld')

        doc_type.add_document(
            pylastica.Document(
                1, {
                    'id': 1,
                    'email': '*****@*****.**',
                    'username': '******',
                    'test': ['2', '3', '5']
                }))
        doc_type.add_document(
            pylastica.Document(
                2, {
                    'id': 2,
                    'email': '*****@*****.**',
                    'username': '******',
                    'test': ['1', '3', '6']
                }))
        doc_type.add_document(
            pylastica.Document(
                3, {
                    'id': 3,
                    'email': '*****@*****.**',
                    'username': '******',
                    'test': ['2', '3', '7']
                }))

        index.refresh()
        bool_query = pylastica.query.Bool()
        term_query1 = pylastica.query.Term({'test': '2'})
        bool_query.add_must(term_query1)
        result_set = doc_type.search(bool_query)

        self.assertEqual(2, len(result_set))

        term_query2 = pylastica.query.Term({'test': '5'})
        bool_query.add_must(term_query2)
        result_set = doc_type.search(bool_query)

        self.assertEqual(1, len(result_set))

        term_query3 = pylastica.query.Term({'username': '******'})
        bool_query.add_must(term_query3)
        result_set = doc_type.search(bool_query)

        self.assertEqual(1, len(result_set))

        term_query4 = pylastica.query.Term({'username': '******'})
        bool_query.add_must(term_query4)
        result_set = doc_type.search(bool_query)

        self.assertEqual(0, len(result_set))
        index.delete()
예제 #12
0
 def setUp(self):
     index = self._create_index('test')
     doc_type = index.get_doc_type('test')
     doc_type.add_document(pylastica.Document(1, {'name': 'San Diego'}))
     doc_type.add_document(
         pylastica.Document(2, {'name': 'San Luis Obispo'}))
     doc_type.add_document(pylastica.Document(3, {'name': 'San Francisco'}))
     doc_type.add_document(pylastica.Document(4, {'name': 'Chicago'}))
     index.refresh()
     self._index = index
예제 #13
0
파일: test_sum.py 프로젝트: jlinn/pylastica
 def setUp(self):
     super(SumTest, self).setUp()
     self._index = self._create_index("test_aggregation_sum")
     docs = [
         pylastica.Document("1", {"price": 5}),
         pylastica.Document("2", {"price": 8}),
         pylastica.Document("3", {"price": 1}),
         pylastica.Document("4", {"price": 3})
     ]
     self._index.get_doc_type("test").add_documents(docs)
     self._index.refresh()
예제 #14
0
 def setUp(self):
     super(PhraseTest, self).setUp()
     self._index = self._create_index("test_suggest_phrase")
     docs = [
         pylastica.Document(1, {'text': 'Github is pretty cool'}),
         pylastica.Document(2, {'text': 'Elasticsearch is bonsai cool'}),
         pylastica.Document(3, {'text': 'This is a test phrase'}),
         pylastica.Document(4, {'text': 'Another phrase for testing'}),
         pylastica.Document(5, {'text': 'Some more words here'})
     ]
     self._index.get_doc_type("testSuggestType").add_documents(docs)
     self._index.refresh()
예제 #15
0
    def test_facet(self):
        client = self._get_client()
        index = client.get_index('test')
        index.create(options=True)
        doc_type = index.get_doc_type('helloworld')
        mapping = pylastica.doc_type.Mapping(
            doc_type, {
                'name': {
                    'type': 'string',
                    'store': 'no'
                },
                'dtmPosted': {
                    'type': 'date',
                    'store': 'no',
                    'format': 'yyyy-MM-dd HH:mm:ss'
                }
            })
        doc_type.mapping = mapping

        doc_type.add_document(
            pylastica.Document(1, {
                'name': 'Joe Linn',
                'dtmPosted': '2013-05-17 03:44:00'
            }))
        doc_type.add_document(
            pylastica.Document(2, {
                'name': 'Sterling Archer',
                'dtmPosted': '2013-04-17 00:14:00'
            }))
        doc_type.add_document(
            pylastica.Document(3, {
                'name': 'Cyril Figgis',
                'dtmPosted': '2013-05-17 10:54:00'
            }))
        doc_type.add_document(
            pylastica.Document(4, {
                'name': 'Lana Kane',
                'dtmPosted': '2013-01-02 18:37:00'
            }))
        index.refresh()

        facet = pylastica.facet.DateHistogram('dateHist1')
        facet.set_interval('day')
        facet.set_field('dtmPosted')

        query = pylastica.query.Query()
        query.add_facet(facet)
        response = doc_type.search(query)
        facets = response.get_facets()
        self.assertEqual(4, response.get_total_hits())
        self.assertEqual(3, len(facets['dateHist1']['entries']))
        index.delete()
예제 #16
0
    def test_query(self):
        index = self._create_index('test')
        doc_type = index.get_doc_type('test')
        doc_type.add_document(pylastica.Document(1, {'name': 'San Diego'}))
        doc_type.add_document(
            pylastica.Document(2, {'name': 'San Luis Obispo'}))
        doc_type.add_document(pylastica.Document(3, {'name': 'San Francisco'}))
        doc_type.add_document(pylastica.Document(4, {'name': 'Chicago'}))
        index.refresh()

        query = pylastica.query.Fuzzy('name', 'San')
        result_set = doc_type.search(query)
        self.assertEqual(3, len(result_set))
        index.delete()
예제 #17
0
파일: test_ids.py 프로젝트: jlinn/pylastica
    def setUp(self):
        index = self._create_index('test')
        doc_type1 = index.get_doc_type('helloworld1')
        doc_type2 = index.get_doc_type('helloworld2')

        doc_type1.add_documents(
            [pylastica.Document(i, {'name': 'Linn'}) for i in range(100)])
        doc_type2.add_documents(
            [pylastica.Document(i, {'name': 'Linn'}) for i in range(100)])

        doc_type2.add_document(pylastica.Document(101, {'name': 'Linn'}))
        index.optimize()
        index.refresh()
        self._doc_type = doc_type1
        self._index = index
예제 #18
0
    def test_search(self):
        client = self._get_client()
        index = pylastica.index.Index(client, 'test')
        index.create(options=True)
        doc_type = index.get_doc_type('helloworldmlt')
        mapping = pylastica.doc_type.Mapping(
            doc_type, {
                'email': {
                    'store': 'yes',
                    'type': 'string',
                    'index': 'analyzed'
                },
                'content': {
                    'store': 'yes',
                    'type': 'string',
                    'index': 'analyzed'
                }
            })
        mapping.set_source({'enabled': False})
        doc_type.set_mapping(mapping)
        doc_type.add_document(
            pylastica.Document(
                1000, {
                    'email':
                    '*****@*****.**',
                    'content':
                    'This is a sample post. Hello World Fuzzy Like This!'
                }))
        doc_type.add_document(
            pylastica.Document(
                1001, {
                    'email': '*****@*****.**',
                    'content': 'This is a fake nospam email address for gmail'
                }))
        index.refresh()

        mlt_query = pylastica.query.MoreLikeThis()
        mlt_query.set_like_text('fake gmail sample')
        mlt_query.set_fields(['email', 'content'])
        mlt_query.set_max_query_terms(1)
        mlt_query.set_min_doc_frequency(1)
        mlt_query.set_min_term_frequency(1)

        query = pylastica.query.Query(mlt_query)
        query.set_fields(['email', 'content'])
        result_set = doc_type.search(query)
        self.assertEqual(2, len(result_set))
        index.delete()
예제 #19
0
    def test_mapping_store_fields(self):
        index = self._create_index('test')
        doc_type = index.get_doc_type('test')

        mapping = pylastica.doc_type.Mapping(doc_type, {
            'firstname': {'type': 'string', 'store': 'yes'},
            'lastname': {'type': 'string'}
        })
        mapping.disable_source()

        doc_type.set_mapping(mapping)

        firstname = 'Joe'
        doc_type.add_document(pylastica.Document(1, {'firstname': firstname, 'lastname': 'Linn'}))
        index.refresh()

        query_string = pylastica.query.QueryString('linn')
        query = pylastica.query.Query.create(query_string)
        query.set_fields(['*'])

        result_set = doc_type.search(query)
        result = result_set[0]
        fields = result.get_fields()

        self.assertEqual(firstname, fields['firstname'][0])
        self.assertFalse('lastname' in fields)
        self.assertEqual(1, len(fields))

        index.flush()
        document = doc_type.get_document('1')
        self.assertEqual(0, len(document.data))
        index.delete()
예제 #20
0
    def test_add_remove_alias(self):
        client = self._get_client()
        index_name_1 = 'test1'
        alias_name = 'test-alias'
        type_name = 'test'
        index = client.get_index(index_name_1)
        index.create(
            {'index': {
                'number_of_shards': 1,
                'number_of_replicas': 0
            }}, True)
        doc = pylastica.Document(1, {
            'id': 1,
            'email': '*****@*****.**',
            'username': '******'
        })
        doc_type = index.get_doc_type(type_name)
        doc_type.add_document(doc)
        index.refresh()
        result_set = doc_type.search('ruflin')
        self.assertEqual(1, len(result_set))

        data = index.add_alias(alias_name, True).data
        self.assertTrue(data['acknowledged'])
        index_2 = client.get_index(alias_name)
        type_2 = index_2.get_doc_type(type_name)
        result_set_2 = type_2.search('ruflin')
        self.assertEqual(1, len(result_set_2))
        response = index.remove_alias(alias_name).data
        self.assertTrue(response['acknowledged'])
        index.delete()
예제 #21
0
    def test_query(self):
        client = self._get_client()
        index = pylastica.index.Index(client, 'test')
        index.create(options=True)
        doc_type = index.get_doc_type('multi_match')
        doc_type.add_document(
            pylastica.Document(1, {
                'id': 1,
                'name': 'Tyler',
                'last_name': 'Durden'
            }))
        index.refresh()

        multi_match = pylastica.query.MultiMatch()
        query = pylastica.query.Query()
        multi_match.set_query('Tyler')
        multi_match.set_fields(['name', 'last_name'])
        query.query = multi_match
        result_set = index.search(query)
        self.assertEqual(1, len(result_set))

        multi_match.set_query('Durden')
        multi_match.set_fields(['name', 'last_name'])
        query.query = multi_match
        result_set = index.search(query)
        self.assertEqual(1, len(result_set))
        index.delete()
예제 #22
0
 def test_to_dict(self):
     doc_id = '17'
     data = {'hello': 'world'}
     doc_type = 'testtype'
     index = 'testindex'
     doc = pylastica.Document(doc_id, data, doc_type, index)
     result = {'_index': index, '_type': doc_type, '_id': doc_id, '_source': data}
     self.assertEqual(result, doc.to_dict())
예제 #23
0
 def setUp(self):
     index = self._create_index('pylastica_test_filter_nested')
     doc_type = index.get_doc_type('user')
     mapping = pylastica.doc_type.Mapping()
     mapping.set_properties({
         'firstname': {
             'type': 'string',
             'store': 'yes'
         },
         'lastname': {
             'type': 'string'
         },
         'hobbies': {
             'type': 'nested',
             'include_in_parent': True,
             'properties': {
                 'hobby': {
                     'type': 'string'
                 }
             }
         }
     })
     doc_type.mapping = mapping
     doc_type.add_documents([
         pylastica.Document(
             1, {
                 'firstname': 'Andrew',
                 'lastname': 'Wiggin',
                 'hobbies': [{
                     'hobby': 'games'
                 }]
             }),
         pylastica.Document(
             2, {
                 'firstname': 'Bonzo',
                 'lastname': 'Madrid',
                 'hobbies': [{
                     'hobby': 'games'
                 }, {
                     'hobby': 'bullying'
                 }]
             })
     ])
     index.refresh()
     self._index = index
     self._doc_type = doc_type
예제 #24
0
 def test_query(self):
     client = self._get_client()
     index = client.get_index('test')
     index.create(options=True)
     doc_type = index.get_doc_type('helloworld')
     doc_type.add_document(pylastica.Document(1, {'color': 'red'}))
     doc_type.add_document(pylastica.Document(2, {'color': 'green'}))
     doc_type.add_document(pylastica.Document(3, {'color': 'blue'}))
     index.refresh()
     term_query = pylastica.query.Term({'color': 'red'})
     facet = pylastica.facet.Query('test')
     facet.set_query(term_query)
     query = pylastica.query.Query()
     query.add_facet(facet)
     result_set = doc_type.search(query)
     facets = result_set.get_facets()
     self.assertEqual(1, facets['test']['count'])
     index.delete()
예제 #25
0
 def test_has_id(self):
     doc = pylastica.Document()
     self.assertFalse(doc.has_id())
     doc.doc_id = ''
     self.assertFalse(doc.has_id())
     doc.doc_id = 0
     self.assertTrue(doc.has_id())
     doc.doc_id = 'hello'
     self.assertTrue(doc.has_id())
예제 #26
0
    def test_add_pdf_file(self):
        if not self._has_attachment_plugin:
            self.skipTest('Plugin mapper-attachments is not installed.')
        index_mapping = {
            'file': {
                'type': 'attachment',
                'store': 'no'
            },
            'text': {
                'type': 'string',
                'store': 'no'
            }
        }
        index_params = {
            'index': {
                'number_of_shards': 1,
                'number_of_replicas': 0
            }
        }
        index = self._create_index()
        doc_type = pylastica.doc_type.DocType(index, 'test')
        index.create(index_params, True)
        doc_type.mapping = index_mapping

        doc_1 = pylastica.Document(1)
        doc_1.add_file('file', self._data_path + 'test.pdf', 'application/pdf')
        doc_1.set('text', 'base1 world')
        doc_type.add_document(doc_1)

        doc_2 = pylastica.Document(2)
        doc_2.set('text', 'running in base1')
        doc_type.add_document(doc_2)

        index.optimize()

        result_set = doc_type.search('xodoa')
        self.assertEqual(1, len(result_set))
        result_set = doc_type.search('base1')
        self.assertEqual(2, len(result_set))
        result_set = doc_type.search('ruflin')
        self.assertEqual(1, len(result_set))
        result_set = doc_type.search('owef')
        self.assertEqual(0, len(result_set))
        index.delete()
예제 #27
0
 def test_match_all_indices_types(self):
     #this test assumes that your ES instance has no documents
     index1 = self._create_index('test1')
     index2 = self._create_index('test2')
     client = index1.client
     result_set1 = index1.search(pylastica.query.MatchAll())
     index1.get_doc_type('test').add_document(
         pylastica.Document(1, {'name': 'Linn'}))
     index2.get_doc_type('test').add_document(
         pylastica.Document(1, {'name': 'Linn'}))
     index1.refresh()
     index2.refresh()
     result_set2 = index1.search(pylastica.query.MatchAll())
     result_set3 = index2.search(pylastica.query.MatchAll())
     self.assertEqual(
         len(result_set1) + 2,
         len(result_set2) + len(result_set3))
     index2.delete()
     index1.delete()
예제 #28
0
 def test_set_index(self):
     doc = pylastica.Document()
     doc.index = 'index2'
     doc.doc_type = 'type2'
     self.assertEqual('index2', doc.index)
     self.assertEqual('type2', doc.doc_type)
     index = pylastica.index.Index(self._get_client(), 'index')
     doc.index = index
     self.assertEqual('index', doc.index)
     self.assertEqual('type2', doc.doc_type)
예제 #29
0
    def test_filtered_search(self):
        client = self._get_client()
        index = client.get_index('test')
        index.create(options=True)
        doc_type = index.get_doc_type('helloworld')
        doc_type.add_document(pylastica.Document(1, {'name': 'hello world'}))
        doc_type.add_document(pylastica.Document(2, {'name': 'Joe Linn'}))
        doc_type.add_document(pylastica.Document(3, {'name': 'Linn'}))
        index.refresh()

        query = pylastica.query.Terms()
        query.set_terms('name', ['joe', 'hello'])
        result_set = doc_type.search(query)
        self.assertEqual(2, len(result_set))

        query.add_term('linn')
        result_set = doc_type.search(query)
        self.assertEqual(3, len(result_set))

        index.delete()
예제 #30
0
    def test_query(self):
        client = self._get_client()
        index = client.get_index('test')
        index.create(options=True)
        doc_type = index.get_doc_type('helloworld')

        doc_type.add_document(pylastica.Document(1, {'name': 'Joe Linn'}))
        doc_type.add_document(pylastica.Document(2, {'name': 'Derek Gould'}))
        doc_type.add_document(pylastica.Document(3, {'name': 'Marc Hoag'}))
        doc_type.add_document(pylastica.Document(4, {'name': 'Ryan Lum'}))

        index.refresh()
        facet = pylastica.facet.Terms('test')
        facet.set_field('name')
        query = pylastica.query.Query()
        query.add_facet(facet)
        response = doc_type.search(query)
        facets = response.get_facets()
        self.assertEqual(8, len(facets['test']['terms']))
        index.delete()