Search code examples
pythonsphinxdjango-sphinx

Sphinx Search Engine & Python API


I am trying to use Sphinx Search Engine with their Python API. The installation went fine. But when I use their Python API I do not get the complete result set. I only get the ID's? But when I use their ./search binary in ./bin I get the entire indexed content.

When using cpp ./search binary -

./search test

1. document=1, weight=1, group_id=1, date_added=Sat Sep 11 07:42:38 2010, title=2
    id=1
    group_id=1
    group_id2=5
    date_added=2010-09-11 07:42:38
    title=test one
    content=this is my test document number one. also checking search within phrases.

But when I use the Python API, I get -

>>> import sphinxapi
>>> client = sphinxapi.SphinxClient()
>>> client.SetServer('127.0.0.1', 9312)
>>> client.Query('test')
{'status': 0, 'matches': [{'id': 1, 'weight': 1, 'attrs': {'date_added': 1284171158, 'group_id': 1, 'title': 2}}, {'id': 2, 'weight': 1, 'attrs': {'date_added': 1284171158, 'group_id': 1, 'title': 3}}, {'id': 4, 'weight': 1, 'attrs': {'date_added': 1284171158, 'group_id': 2, 'title': 1}}], 'fields': ['content'], 'time': '0.022', 'total_found': 3, 'warning': '', 'attrs': [['group_id', 1], ['date_added', 2], ['title', 3]], 'words': [{'docs': 6, 'hits': 6, 'word': 'test'}], 'error': '', 'total': 3}

How do I get the string fields like 'title' or 'content' as part of the result set?


Solution

  • You could use sql_field_string - add to your config

    source YOUR_SOURCE
    {
    sql_field_string = title
    sql_field_string = content
    

    it would index data of these fields and also store these fields as string attributes so you could get them in your result set without additional SQL query.

    However as all attributes string attributes always loads into memory that is why you could run out of your box memory quickly.