def testServicePrefixSearch(self):
     observer = CallTrace('lucene')
     def prefixSearch(**kwargs):
         raise StopIteration(LuceneResponse(total=2, hits=['aap','noot']))
         yield
     observer.methods['prefixSearch'] = prefixSearch
     service = LuceneRemoteService(CallTrace('reactor'))
     service.addObserver(observer)
     body = dumps({
             'message': 'prefixSearch',
             'kwargs':{
                 'prefix':'aap',
                 'fieldname': 'field',
                 'limit': 10,
             }
         })
     result = ''.join(compose(service.handleRequest(path='/__lucene_remote__', Method="POST", Body=body)))
     header, body = result.split('\r\n'*2)
     self.assertTrue('Content-Type: application/json' in header, header)
     response = LuceneResponse.fromJson(body)
     self.assertEquals(2, response.total)
     self.assertEquals(['aap', 'noot'], response.hits)
     self.assertEquals(['prefixSearch'], observer.calledMethodNames())
     m = observer.calledMethods[0]
     self.assertEquals('aap', m.kwargs['prefix'])
     self.assertEquals(10, m.kwargs['limit'])
     self.assertEquals('field', m.kwargs['fieldname'])
 def testServiceExecuteQuery(self):
     observer = CallTrace('lucene')
     def executeQuery(**kwargs):
         raise StopIteration(LuceneResponse(total=2, hits=['aap','noot']))
         yield
     observer.methods['executeQuery'] = executeQuery
     service = LuceneRemoteService(CallTrace('reactor'))
     service.addObserver(observer)
     body = dumps({
             'message': 'executeQuery',
             'kwargs':{
                 'cqlAbstractSyntaxTree': {'__CQL_QUERY__': 'query AND field=value'},
                 'start':0,
                 'stop': 10,
                 'facets': [{'fieldname': 'field', 'maxTerms':5}],
                 'filterQueries': [{'__CQL_QUERY__': 'query=fiets'}],
                 'joinQueries': {'core1': {'__CQL_QUERY__': 'query=test'}}
             }
         })
     result = ''.join(compose(service.handleRequest(path='/__lucene_remote__', Method="POST", Body=body)))
     header, body = result.split('\r\n'*2)
     self.assertTrue('Content-Type: application/json' in header, header+body)
     response = LuceneResponse.fromJson(body)
     self.assertEquals(2, response.total)
     self.assertEquals(['aap', 'noot'], response.hits)
     self.assertEquals(['executeQuery'], observer.calledMethodNames())
     m = observer.calledMethods[0]
     self.assertEquals(parseString('query AND field=value'), m.kwargs['cqlAbstractSyntaxTree'])
     self.assertEquals(0, m.kwargs['start'])
     self.assertEquals(10, m.kwargs['stop'])
     self.assertEquals([{'fieldname': 'field', 'maxTerms':5}], m.kwargs['facets'])
     self.assertEquals([parseString('query=fiets')], m.kwargs['filterQueries'])
     self.assertEquals({'core1': parseString('query=test')}, m.kwargs['joinQueries'])
Ejemplo n.º 3
0
    def testServicePrefixSearch(self):
        observer = CallTrace('lucene')

        def prefixSearch(**kwargs):
            raise StopIteration(LuceneResponse(total=2, hits=['aap', 'noot']))
            yield

        observer.methods['prefixSearch'] = prefixSearch
        service = LuceneRemoteService(CallTrace('reactor'))
        service.addObserver(observer)
        body = dumps({
            'message': 'prefixSearch',
            'kwargs': {
                'prefix': 'aap',
                'fieldname': 'field',
                'limit': 10,
            }
        })
        result = ''.join(
            compose(
                service.handleRequest(path='/__lucene_remote__',
                                      Method="POST",
                                      Body=body)))
        header, body = result.split('\r\n' * 2)
        self.assertTrue('Content-Type: application/json' in header, header)
        response = LuceneResponse.fromJson(body)
        self.assertEquals(2, response.total)
        self.assertEquals(['aap', 'noot'], response.hits)
        self.assertEquals(['prefixSearch'], observer.calledMethodNames())
        m = observer.calledMethods[0]
        self.assertEquals('aap', m.kwargs['prefix'])
        self.assertEquals(10, m.kwargs['limit'])
        self.assertEquals('field', m.kwargs['fieldname'])
Ejemplo n.º 4
0
    def testServiceExecuteQuery(self):
        observer = CallTrace('lucene')

        def executeQuery(**kwargs):
            raise StopIteration(LuceneResponse(total=2, hits=['aap', 'noot']))
            yield

        observer.methods['executeQuery'] = executeQuery
        service = LuceneRemoteService(CallTrace('reactor'))
        service.addObserver(observer)
        body = dumps({
            'message': 'executeQuery',
            'kwargs': {
                'cqlAbstractSyntaxTree': {
                    '__CQL_QUERY__': 'query AND field=value'
                },
                'start': 0,
                'stop': 10,
                'facets': [{
                    'fieldname': 'field',
                    'maxTerms': 5
                }],
                'filterQueries': [{
                    '__CQL_QUERY__': 'query=fiets'
                }],
                'joinQueries': {
                    'core1': {
                        '__CQL_QUERY__': 'query=test'
                    }
                }
            }
        })
        result = ''.join(
            compose(
                service.handleRequest(path='/__lucene_remote__',
                                      Method="POST",
                                      Body=body)))
        header, body = result.split('\r\n' * 2)
        self.assertTrue('Content-Type: application/json' in header,
                        header + body)
        response = LuceneResponse.fromJson(body)
        self.assertEquals(2, response.total)
        self.assertEquals(['aap', 'noot'], response.hits)
        self.assertEquals(['executeQuery'], observer.calledMethodNames())
        m = observer.calledMethods[0]
        self.assertEquals(parseString('query AND field=value'),
                          m.kwargs['cqlAbstractSyntaxTree'])
        self.assertEquals(0, m.kwargs['start'])
        self.assertEquals(10, m.kwargs['stop'])
        self.assertEquals([{
            'fieldname': 'field',
            'maxTerms': 5
        }], m.kwargs['facets'])
        self.assertEquals([parseString('query=fiets')],
                          m.kwargs['filterQueries'])
        self.assertEquals({'core1': parseString('query=test')},
                          m.kwargs['joinQueries'])
Ejemplo n.º 5
0
def main(reactor, port, databasePath):
    drilldownFields = [
        DrilldownField('untokenized.field2'),
        DrilldownField('untokenized.fieldHier', hierarchical=True)
    ]

    fieldRegistry = FieldRegistry(drilldownFields)
    luceneSettings = LuceneSettings(fieldRegistry=fieldRegistry,
                                    commitCount=30,
                                    commitTimeout=1,
                                    analyzer=MerescoDutchStemmingAnalyzer())
    lucene = Lucene(path=join(databasePath, 'lucene'),
                    reactor=reactor,
                    name='main',
                    settings=luceneSettings)

    lucene2Settings = LuceneSettings(fieldRegistry=fieldRegistry,
                                     commitTimeout=0.1)
    lucene2 = Lucene(path=join(databasePath, 'lucene2'),
                     reactor=reactor,
                     name='main2',
                     settings=lucene2Settings)

    termNumerator = TermNumerator(path=join(databasePath, 'termNumerator'))

    emptyLuceneSettings = LuceneSettings(commitTimeout=1)
    multiLuceneHelix = (
        MultiLucene(defaultCore='main'),
        (Lucene(path=join(databasePath, 'lucene-empty'),
                reactor=reactor,
                name='empty-core',
                settings=emptyLuceneSettings), ),
        (lucene, ),
        (lucene2, ),
    )
    storageComponent = StorageComponent(
        directory=join(databasePath, 'storage'))

    return \
    (Observable(),
        (ObservableHttpServer(reactor=reactor, port=port),
            (BasicHttpHandler(),
                (ApacheLogger(outputStream=stdout),
                    (PathFilter("/info", excluding=[
                            '/info/version',
                            '/info/name',
                            '/update',
                            '/sru',
                            '/remote',
                            '/via-remote-sru',
                        ]),
                        (DynamicHtml(
                                [dynamicPath],
                                reactor=reactor,
                                indexPage='/info',
                                additionalGlobals={
                                    'VERSION': version,
                                }
                            ),
                        )
                    ),
                    (PathFilter("/info/version"),
                        (StringServer(version, ContentTypePlainText), )
                    ),
                    (PathFilter("/info/name"),
                        (StringServer('Meresco Lucene', ContentTypePlainText),)
                    ),
                    (PathFilter("/static"),
                        (PathRename(lambda path: path[len('/static'):]),
                            (FileServer(staticPath),)
                        )
                    ),
                    (PathFilter("/update_main", excluding=['/update_main2']),
                        uploadHelix(lucene, termNumerator, storageComponent, drilldownFields, fieldRegistry=luceneSettings.fieldRegistry),
                    ),
                    (PathFilter("/update_main2"),
                        uploadHelix(lucene2, termNumerator, storageComponent, drilldownFields, fieldRegistry=lucene2Settings.fieldRegistry),
                    ),
                    (PathFilter('/sru'),
                        (SruParser(defaultRecordSchema='record'),
                            (SruHandler(),
                                (MultiCqlToLuceneQuery(
                                    defaultCore='main',
                                    coreToCqlLuceneQueries={
                                        "main": CqlToLuceneQuery([], luceneSettings=luceneSettings),
                                        "main2": CqlToLuceneQuery([], luceneSettings=lucene2Settings),
                                        "empty-core": CqlToLuceneQuery([], luceneSettings=emptyLuceneSettings),
                                    }),
                                    multiLuceneHelix,
                                ),
                                (SRUTermDrilldown(defaultFormat='xml'),),
                                (SruDuplicateCount(),),
                                (storageComponent,),
                            )
                        )
                    ),
                    (PathFilter('/via-remote-sru'),
                        (SruParser(defaultRecordSchema='record'),
                            (SruHandler(),
                                (LuceneRemote(host='localhost', port=port, path='/remote'),),
                                (SRUTermDrilldown(defaultFormat='xml'),),
                                (SruDuplicateCount(),),
                                (storageComponent,),
                            )
                        )
                    ),
                    (PathFilter('/remote'),
                        (LuceneRemoteService(reactor=reactor),
                            (MultiCqlToLuceneQuery(
                                    defaultCore='main',
                                    coreToCqlLuceneQueries={
                                        "main": CqlToLuceneQuery([], luceneSettings=luceneSettings),
                                        "main2": CqlToLuceneQuery([], luceneSettings=lucene2Settings),
                                        "empty-core": CqlToLuceneQuery([], luceneSettings=emptyLuceneSettings),
                                    }),
                                multiLuceneHelix,
                            )
                        )
                    ),
                    (PathFilter('/autocomplete'),
                        (Autocomplete('localhost', port, '/autocomplete', '__all__', '?', 5, '?', '?'),
                            (lucene,),
                        )
                    )
                )
            )
        )
    )