Ticket #256 (closed defect: fixed)

Opened 7 months ago

Last modified 6 months ago

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

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

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

in reply to: ↑ description   Changed 7 months ago by versmisse

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.

  Changed 7 months ago by olly

  • status changed from new to assigned
  • milestone set to 1.0.7

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.

  Changed 7 months ago by versmisse

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

Best regards, David Versmisse.

  Changed 7 months ago by olly

  • component changed from Xapian-bindings to Library API

  Changed 7 months ago by richard

  • status changed from assigned to closed
  • resolution set to fixed

Fixed in changeset [10456]

  Changed 6 months ago by olly

Change has been backported for 1.0.7.

Note: See TracTickets for help on using tickets.