patrickn
patrickn

Reputation: 2561

Sphinx not always returning string attributes

In some instances, Sphinx is returning results without JOIN'd fields I've declared as sql_attr_string's. Take the following source/index configuration for example:

source myapp_recipe
{
    type                = pgsql
    sql_host            = 
    sql_user            = me
    sql_pass            = secret
    sql_db              = myapp_db
    sql_port            = 

    sql_query           = \
        SELECT myapp_recipe.id as id, \
            myapp_recipe.name as name, \
            myapp_recipe.cookbook_id as cookbook_id, \
            myapp_cookbook.name as cookbook_name, \
            'recipe' as content_type \
        FROM myapp_recipe \
        INNER JOIN myapp_cookbook \
        ON myapp_recipe.cookbook_id = myapp_cookbook.id

    #content_type for django
    sql_attr_string       = content_type

    # stored string fields in the document
    sql_attr_string     = cookbook_name

    # stored and indexed string fields
    sql_field_string     = name

    # ForeignKey's
    sql_attr_uint       = cookbook_id
}

index myapp_recipe
{
    source          = myapp_recipe
    path            = /var/data/myapp_recipe
    docinfo         = extern
    morphology      = none
    stopwords       =
    min_word_len    = 2
    charset_type    = utf-8
    min_prefix_len  = 0
    min_infix_len   = 3
    enable_star     = 0
}

For some searches, result documents are coming back without attributes aside from content_type and name. For a different search, that returns the same document, Sphinx may very well return the same result document WITH all the expected attributes.

Example: A query for "pizza" will return an incomplete result document (documentA) without JOIN'd string attributes.

A query for "pizza pocket" will return the same document (documentA) WITH all of the expected JOIN'd attributes.

Can anyone explain this baffling behavior?

Upvotes: 0

Views: 582

Answers (1)

aditirex
aditirex

Reputation: 692

Check if you don't have duplicate id's Your sql_query must return a result with unique ids , otherwise Sphinx can have for same id several documents (for Sphinx the id is seen as a simple number , doesn't apply any uniquity rule ) . When you index, there should be raised an warning that you have duplicates.

Upvotes: 1

Related Questions