[Xapian-discuss] Problems with positions and replace_document
Fernando Nemec
fernando.nemec at folha.com.br
Fri Nov 10 20:34:07 GMT 2006
Hi Rafael,
thanks for you help. That's strange because I did almost the same
thing using c++ but I got different results. I sent to the list a link
with the code I did. I appreciate if you take a look. As your python
code works it's likely I mess up something in my own code.
Thanks,
Nemec
Friday, November 10, 2006, 5:07:13 PM, you wrote:
> Fernando, look this fast test:
> sdm at sdm-desktop:~/db$ python
> Python 2.4.4c1 (#2, Oct 11 2006, 21:51:02)
> [GCC 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import xapian
>>>> db = xapian.WritableDatabase('.', xapian.DB_CREATE_OR_OPEN)
>>>> doc = xapian.Document
>>>> doc = xapian.Document()
>>>> doc.add_posting('foo', 1)
>>>> doc.add_posting('bar', 2)
>>>> db.add_document(doc)
> 1
>>>>
> EXIT PYTHON
> sdm at sdm-desktop:~/db$ python
> Python 2.4.4c1 (#2, Oct 11 2006, 21:51:02)
> [GCC 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import xapian
>>>> a = xapian.open('.')
>>>> db = xapian.open('.')
>>>> db.get_doccount()
> 1
>>>> db.get_document(1)
>>>> doc = db.get_document(1)
>>>> doc.add_value(0,"fnord")
>>>> db = xapian.WritableDatabase('.', xapian.DB_CREATE_OR_OPEN)
>>>> db.replace_document(1, doc)
>>>>
> EXIT PYTHON AGAIN
> sdm at sdm-desktop:~/db$ python
> Python 2.4.4c1 (#2, Oct 11 2006, 21:51:02)
> [GCC 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import xapian
>>>> db = xapian.open('.')
>>>> doc = db.get_document(1)
>>>> for i in doc.termlist():
> ... print i
> ...
> ['bar', 1, 0, <xapian.PositionIter instance at 0xb7b67b8c>]
> ['foo', 1, 0, <xapian.PositionIter instance at 0xb7b67c2c>]
>>>> enq = xapian.Enquire(db)
>>>> qp = xapian.QueryParser()
>>>> enq.set_query(qp.parse_query('"foo bar"'))
>>>> m = enq.get_mset(0,1)
>>>> for i in m:
> ... print i
> ...
> [1, 0.30830135965451672, 0, 100, <xapian.Document; proxy of <Swig Object of
> type 'Xapian::Document *' at 0x81a7118> >]
> As you can see, the Xapian overwrote the document keeping the postlist
> terms, and the search for "foo bar" (Phrase search) returns the right
> document.
> I'm using Ubuntu 6.10, python2.4 xapian-0.9.6 (just to test, 0.9.9 is the
> better release xD -remote backend historic-)
--
[]s
Fernando Nemec
fernando.nemec at folha.com.br
http://www.folha.com.br/
More information about the Xapian-discuss
mailing list