lucene-solr-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Keegan <peterlkee...@gmail.com>
Subject Re: how to include result ordinal in response
Date Sat, 04 Jan 2014 22:43:35 GMT
Thank you both. The DocTransformer solution was very simple:

import java.io.IOException;

import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.transform.DocTransformer;
import org.apache.solr.response.transform.TransformerFactory;

public class PositionAugmenterFactory extends TransformerFactory{

    @Override
    public DocTransformer create(String field, SolrParams params,
            SolrQueryRequest req) {
        return new PositionAugmenter( field );
    }

    class PositionAugmenter extends DocTransformer {
        final String name;
        int position;

        public PositionAugmenter( String display )
        {
            this.name = display;
            this.position = 1;
        }
        @Override
        public String getName() {
            return name;
        }

        @Override
        public void transform(SolrDocument doc, int docid) throws
IOException {
            doc.setField( name, position++);
        }

    }
}

@Jack: fl=[docid] is similar to using the uniqueKey, but still hard to
compare visually (for me).

The fields are not returned in the same order as specified in the 'fl'
parameter. Can the order be overridden?

Thanks,
Peter




On Fri, Jan 3, 2014 at 6:58 PM, Jack Krupansky <jack@basetechnology.com>wrote:

> Or just use the internal document ID: fl=*,[docid]
>
> Granted, the docID may change if a segment merge occurs and earlier
> documents have been deleted, but it may be sufficient for your purposes.
>
> -- Jack Krupansky
>
> -----Original Message----- From: Upayavira
> Sent: Friday, January 03, 2014 5:58 PM
> To: solr-user@lucene.apache.org
> Subject: Re: how to include result ordinal in response
>
>
> On Fri, Jan 3, 2014, at 10:00 PM, Peter Keegan wrote:
>
>> Is there a simple way to output the result number (ordinal) with each
>> returned document using the 'fl' parameter? This would be useful when
>> visually comparing the results from 2 queries.
>>
>
> I'm not aware of a simple way.
>
> If you're competent in Java, this could be a neat new DocTransformer
> component. You'd say:
>
> fl=*,[position]
>
> and you'd get a new field in your search results.
>
> Cruder ways would be to use XSLT to add it to an XML output, or a
> velocity template, but the DocTransformer approach would create
> something that could be of ongoing use.
>
> Upayavira
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message