On Sat, 9 Sep 2006, Yura Smolsky wrote:
object of TopFieldDocs returned from
IndexSearcher.search(Weight weight, Filter filter, int nDocs, Sort
sort) is wrong. Here is piece of code:
from PyLucene import *
dir = FSDirectory.getDirectory("../../index/index", False)
searcher = IndexSearcher(dir)
query = QueryParser("summary", StandardAnalyzer()).parse("good")
weight = query.weight(searcher)
print 'weight:', weight
tfd = searcher.search(weight, None, 10, Sort())
print 'TopFieldDocs:', tfd
print 'TopFieldDocs.fields:', tfd.fields
It tells me this:
weight: weight(summary:good)
TopFieldDocs: [EMAIL PROTECTED]
TopFieldDocs.fields:
Traceback (most recent call last):
File "TopFieldDoc.py", line 14, in ?
print 'TopFieldDocs.fields:', tfd.fields
AttributeError: 'PyLucene.TopDocs' object has no attribute 'fields'
The Searchable.search(Weight, Filter, int, Sort) wrapper was wrapping the
return value with a FieldDocs instead of a TopFieldDocs. This is fixed in the
attached patch and in svn.
Thank you for finding this !
Andi..
Index: lucene.cpp
===================================================================
--- lucene.cpp (revision 292)
+++ lucene.cpp (working copy)
@@ -10296,7 +10296,8 @@
static PyObject *j_searchable_search(j_searchable *self, PyObject *args)
{
- org::apache::lucene::search::TopDocs *docs;
+ org::apache::lucene::search::TopDocs *td;
+ org::apache::lucene::search::TopFieldDocs *tfd;
org::apache::lucene::search::Weight *weight;
org::apache::lucene::search::Filter *filter;
org::apache::lucene::search::Sort *sort;
@@ -10310,8 +10311,8 @@
&org::apache::lucene::search::Filter::class$,
check_Filter, &weight, &filter, make_Filter, &n))
{
- OBJ_CALL(docs = self->object->search(weight, filter, n));
- return wrap_TopDocs(docs);
+ OBJ_CALL(td = self->object->search(weight, filter, n));
+ return wrap_TopDocs(td);
}
if (!parseArgs(args, "JPP",
&org::apache::lucene::search::Weight::class$,
@@ -10333,8 +10334,8 @@
&org::apache::lucene::search::Sort::class$,
&weight, &filter, make_Filter, &n, &sort))
{
- OBJ_CALL(docs = self->object->search(weight, filter, n, sort));
- return wrap_TopDocs(docs);
+ OBJ_CALL(tfd = self->object->search(weight, filter, n, sort));
+ return wrap_TopFieldDocs(tfd);
}
break;
}
_______________________________________________
pylucene-dev mailing list
[email protected]
http://lists.osafoundation.org/mailman/listinfo/pylucene-dev