Opened 16 years ago

Closed 16 years ago

Last modified 8 years ago

#256 closed defect (fixed)

Bug when i switch from a sorting mode to an other in python

Reported by: Versmisse David Owned by: Olly Betts
Priority: normal Milestone: 1.0.7
Component: Library API Version: 1.0.6
Severity: normal Keywords: Enquire python
Cc: Blocked By:
Blocking: Operating System: All

Description

Hello,

I'm a French developer and i really want to use xapian for a project. We already have a "catalog" object but it is not efficient enough.

I have already written a good part of the code (in python), but i have a problem with Enquire. When i use two different sorters and the first one no longer exists (simulated by a "del" in the snippet), i have an error.

I simulate my problem with the following snippet that crashes with a beautiful segmentation fault

#!/usr/bin/python
# -*- coding: UTF-8 -*-

from xapian import (WritableDatabase, DB_CREATE_OR_OPEN, Document,
                    Query, Enquire, MultiValueSorter,
                    sortable_serialise)

db = WritableDatabase('my_db', DB_CREATE_OR_OPEN)

doc1 = Document()
doc1.add_posting('foo', 0)
doc1.add_value(0, sortable_serialise(1))
doc1.add_value(1, 'doc1')

doc2 = Document()
doc2.add_posting('foo', 0)
doc2.add_value(0, sortable_serialise(2))
doc2.add_value(1, 'doc2')

db.add_document(doc1)
db.add_document(doc2)

enquire = Enquire(db)
enquire.set_query(Query(''))


sorter = MultiValueSorter()
sorter.add(0)
enquire.set_sort_by_key_then_relevance(sorter)
for doc in enquire.get_mset(0,10):
    print doc.get_document().get_value(1)

del sorter

enquire.set_sort_by_value_then_relevance(0)
for doc in enquire.get_mset(0,10):
    print doc.get_document().get_value(1)

When i delete the "del sorter" line, there is not problem. Is it a bug or is it only my fault? Do we must do a new Enquire instance for each sort?

Thanks you in advance for your answer. And thanks you very much for your project.

Best regards, David Versmisse.

Change History (6)

in reply to:  description comment:1 by Versmisse David, 16 years ago

Replying to versmisse:

I looked at the code (omenquire.cc in particular), i think that the functions set_sort_by_* can operate only once with a single instance of Enquire. For example: internal->sorter = NULL; added to Enquire::set_sort_by_value_then_relevance resolves my problem, but it is not very clean, there are surely some other variables to set.

Thanks you in advance for your answer,

Best regards, David Versmisse.

comment:2 by Olly Betts, 16 years ago

Milestone: 1.0.7
Status: newassigned

Actually, I believe you've nailed this one. Thanks!

I don't think there are any other variables to set. In a less strongly typed language, sort_key and sorter would be a single member variable, but in C++ that isn't possible so sort_key is ignored unless sorter is NULL.

I'll commit fixes for 1.1.0 and 1.0.7 when I get a chance, but meanwhile, adding internal->sorter = NULL to set_sort_by*value*() by hand should resolve this for you.

comment:3 by Versmisse David, 16 years ago

Thank you very much for your reply. I will follow your advice.

Best regards, David Versmisse.

comment:4 by Olly Betts, 16 years ago

Component: Xapian-bindingsLibrary API

comment:5 by Richard Boulton, 16 years ago

Resolution: fixed
Status: assignedclosed

Fixed in changeset [10456]

comment:6 by Olly Betts, 16 years ago

Change has been backported for 1.0.7.

Note: See TracTickets for help on using tickets.