Solr query particular value of a field last

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Solr query particular value of a field last

Anuj Bhargava
I have a field *country*. I need to do a search in which I need to show the
search result of a country or some countries, last in the search result for
eg. country code *BD*. What query should I use to get the above result.

fq=country:???&q=*%3A*
Reply | Threaded
Open this post in threaded view
|

Re: Solr query particular value of a field last

Saurabh Sharma
I would suggest to sort on the basis of condition. First find all the
records and then sort on the basis of condition where you will be putting
spcific countries below other.

fq=country :c1 OR c2 OR c3&sort=if(termfreq (country,c2),1,0) desc


Here we are putting c2 below c1 and c3.

You can also try term search and boost specific terms.

Thanks and regards
Saurabh

On Sun 14 Apr, 2019, 1:49 PM Anuj Bhargava, <[hidden email]> wrote:

> I have a field *country*. I need to do a search in which I need to show the
> search result of a country or some countries, last in the search result for
> eg. country code *BD*. What query should I use to get the above result.
>
> fq=country:???&q=*%3A*
>
Reply | Threaded
Open this post in threaded view
|

Re: Solr query particular value of a field last

Saurabh Sharma
fq=country :c1 OR c2 OR c3&sort=if(termfreq (country,c2),0,1) desc


Correcting query.

On Sun 14 Apr, 2019, 3:36 PM Saurabh Sharma, <[hidden email]>
wrote:

> I would suggest to sort on the basis of condition. First find all the
> records and then sort on the basis of condition where you will be putting
> spcific countries below other.
>
> fq=country :c1 OR c2 OR c3&sort=if(termfreq (country,c2),1,0) desc
>
>
> Here we are putting c2 below c1 and c3.
>
> You can also try term search and boost specific terms.
>
> Thanks and regards
> Saurabh
>
> On Sun 14 Apr, 2019, 1:49 PM Anuj Bhargava, <[hidden email]> wrote:
>
>> I have a field *country*. I need to do a search in which I need to show
>> the
>> search result of a country or some countries, last in the search result
>> for
>> eg. country code *BD*. What query should I use to get the above result.
>>
>> fq=country:???&q=*%3A*
>>
>
Reply | Threaded
Open this post in threaded view
|

Re: Solr query particular value of a field last

Prince Manohar
Basically, you need to boost some documents low.

For this, you can either use solr’s Boost Query ( bq ) or Boost Function (bf)
parameter.

For example in your case:-

If you want the documents with countries A and B to show last in the
result, you can use:-

bq=( country:A OR country:B )^-1

Note that a negative boosting has been done here.

I would say this approach is better than sorting because other documents
maintain their actual order and only those documents are boosted up or
down, which satisfy the condition.




On Sun, Apr 14, 2019 at 4:03 PM Saurabh Sharma <[hidden email]>
wrote:

> fq=country :c1 OR c2 OR c3&sort=if(termfreq (country,c2),0,1) desc
>
>
> Correcting query.
>
> On Sun 14 Apr, 2019, 3:36 PM Saurabh Sharma, <[hidden email]>
> wrote:
>
> > I would suggest to sort on the basis of condition. First find all the
> > records and then sort on the basis of condition where you will be putting
> > spcific countries below other.
> >
> > fq=country :c1 OR c2 OR c3&sort=if(termfreq (country,c2),1,0) desc
> >
> >
> > Here we are putting c2 below c1 and c3.
> >
> > You can also try term search and boost specific terms.
> >
> > Thanks and regards
> > Saurabh
> >
> > On Sun 14 Apr, 2019, 1:49 PM Anuj Bhargava, <[hidden email]> wrote:
> >
> >> I have a field *country*. I need to do a search in which I need to show
> >> the
> >> search result of a country or some countries, last in the search result
> >> for
> >> eg. country code *BD*. What query should I use to get the above result.
> >>
> >> fq=country:???&q=*%3A*
> >>
> >
>


--
*Regards,
<https://rawgit.com/princemanohar/cv/master/resume7797045315-princemanohar0909.pdf>*
*Prince Manohar
<https://rawgit.com/princemanohar/cv/master/resume7797045315-princemanohar0909.pdf>*
*B.Tech (InformationTechnology)
<https://rawgit.com/princemanohar/cv/master/Prince_Manohar_Resume.pdf>*
*Bengaluru
<https://rawgit.com/princemanohar/cv/master/resume7797045315-princemanohar0909.pdf>*
*+91 7797045315
<https://rawgit.com/princemanohar/cv/master/resume7797045315-princemanohar0909.pdf>*
Reply | Threaded
Open this post in threaded view
|

Re: Solr query particular value of a field last

Anuj Bhargava
Thanks Saurabh And Prince, Works perfectly.

On Sun, 14 Apr 2019 at 17:21, Prince Manohar <[hidden email]>
wrote:

> Basically, you need to boost some documents low.
>
> For this, you can either use solr’s Boost Query ( bq ) or Boost Function
> (bf)
> parameter.
>
> For example in your case:-
>
> If you want the documents with countries A and B to show last in the
> result, you can use:-
>
> bq=( country:A OR country:B )^-1
>
> Note that a negative boosting has been done here.
>
> I would say this approach is better than sorting because other documents
> maintain their actual order and only those documents are boosted up or
> down, which satisfy the condition.
>
>
>
>
> On Sun, Apr 14, 2019 at 4:03 PM Saurabh Sharma <[hidden email]
> >
> wrote:
>
> > fq=country :c1 OR c2 OR c3&sort=if(termfreq (country,c2),0,1) desc
> >
> >
> > Correcting query.
> >
> > On Sun 14 Apr, 2019, 3:36 PM Saurabh Sharma, <[hidden email]
> >
> > wrote:
> >
> > > I would suggest to sort on the basis of condition. First find all the
> > > records and then sort on the basis of condition where you will be
> putting
> > > spcific countries below other.
> > >
> > > fq=country :c1 OR c2 OR c3&sort=if(termfreq (country,c2),1,0) desc
> > >
> > >
> > > Here we are putting c2 below c1 and c3.
> > >
> > > You can also try term search and boost specific terms.
> > >
> > > Thanks and regards
> > > Saurabh
> > >
> > > On Sun 14 Apr, 2019, 1:49 PM Anuj Bhargava, <[hidden email]>
> wrote:
> > >
> > >> I have a field *country*. I need to do a search in which I need to
> show
> > >> the
> > >> search result of a country or some countries, last in the search
> result
> > >> for
> > >> eg. country code *BD*. What query should I use to get the above
> result.
> > >>
> > >> fq=country:???&q=*%3A*
> > >>
> > >
> >
>
>
> --
> *Regards,
> <
> https://rawgit.com/princemanohar/cv/master/resume7797045315-princemanohar0909.pdf
> >*
> *Prince Manohar
> <
> https://rawgit.com/princemanohar/cv/master/resume7797045315-princemanohar0909.pdf
> >*
> *B.Tech (InformationTechnology)
> <https://rawgit.com/princemanohar/cv/master/Prince_Manohar_Resume.pdf>*
> *Bengaluru
> <
> https://rawgit.com/princemanohar/cv/master/resume7797045315-princemanohar0909.pdf
> >*
> *+91 7797045315
> <
> https://rawgit.com/princemanohar/cv/master/resume7797045315-princemanohar0909.pdf
> >*
>