Using a TopFieldCollector works fine for me in a little test program.
My program sorts on a simple String field rather than your
CustomComparatorSource, whatever that is.
SortField sortField[] = {
new SortField("cat", SortField.STRING),
SortField.FIELD_SCORE
};
Sort sort = new Sort(sortField);
Query q = whatever;
TopFieldCollector tfc = TopFieldCollector.create(sort,
1000,
true,
true,
true,
true);
searcher.search(q, tfc);
TopDocs td = tfc.topDocs();
I suggest you break your code down into a simple standalone program
and post that if it still doesn't work.
--
Ian.
On Thu, Nov 29, 2012 at 4:20 AM, Andy Yu <[email protected]> wrote:
> I revise the code to
>
> SortField sortField[] = {new SortField("id", new
> CustomComparatorSource(bitSet)),SortField.FIELD_SCORE};
>
> Sort sort = new Sort(sortField);
>
> TopFieldCollector topFieldCollector =
> TopFieldCollector.create(sort, 1000, true, true, true, true);
> indexSearcher.search(query, topFieldCollector);
> TopDocs topDocs = topFieldCollector.topDocs();
>
> but I got the same result with the previous code, need I custom the
> class TopFieldCollector?
>
> thank you lan
>
>
> 2012/11/27 Ian Lea <[email protected]>
>
>> What are you getting for the scores? If it's NaN I think you'll need
>> to use a TopFieldCollector. See for example
>> http://www.gossamer-threads.com/lists/lucene/java-user/86309
>>
>>
>> --
>> Ian.
>>
>>
>> On Tue, Nov 27, 2012 at 3:51 AM, Andy Yu <[email protected]> wrote:
>> > Hi All,
>> >
>> >
>> > Now I want to sort by a field and the relevance
>> > For example
>> >
>> > SortField sortField[] = {new SortField("id", new
>> > CustomComparatorSource(bitSet)),SortField.FIELD_SCORE};
>> > Sort sort = new Sort(sortField);
>> > TopDocs topDocs = indexSearcher.search(query, 10,sort);
>> >
>> > if (0 < topDocs.totalHits) {
>> > for (ScoreDoc scoreDoc : topDocs.scoreDocs) {
>> >
>> > System.out.println(indexSearcher.doc(scoreDoc.doc).get("id"));
>> > System.out.println("score is " + scoreDoc.score);
>> >
>> > System.out.println(indexSearcher.doc(scoreDoc.doc).get("name"));
>> > }
>> > }
>> >
>> > I found that the search result sort just by [new SortField("id", new
>> > CustomComparatorSource(bitSet))]
>> > [SortField.FIELD_SCORE] does not work at all
>> >
>> >
>> > PS: my lucene version is 3.6
>> >
>> > does anybodu know the reason or how to solve it ?
>> >
>> >
>> > Thanks ,
>> > Andy
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>>
>>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]