|
|
-
Lucene Query About Sorting
Yogesh patel 2012-06-26, 03:05
Hi,
I have one query of lucene about sort.
I have 10000 documents in my index which having fields A,B,C,D. i want first 100 results in my query but they must be sort by field A. Suppose I have query "B:abc".
so used below code with search :
qp is object of query parser.
Query query=qp.parse("B:abc");
Sort sort= new Sort(new SortField("A",SortField.STRING_VAL,true));
hits = searcher.search(query, null,100,sort);
but when i search above way.it gives me result in sorting but sorting applies to only matching first 100 results.It search first 100 results and then sort. I want first 100 sorted descending of Field A with matching query.
Is it possible in Lucene?
Thanks
*Regards,
Yogesh Patel*
-
Re: Lucene Query About Sorting
Apostolis Xekoukoulotakis... 2012-06-26, 12:32
I am just new here.
When you make a query, you create an ordering of the documents based on this query. If you have a second ordering, you have to decide what to do with those 2 orderings. You have to decide how to join those two.
The default search orders your results by the query and picks the top n, then it sorts them by your sort. You can see the code at TopDocColector.
2012/6/26 Yogesh patel <[EMAIL PROTECTED]>
> Hi, > > I have one query of lucene about sort. > > I have 10000 documents in my index which having fields A,B,C,D. i want > first 100 results in my query but they must be sort by field A. > Suppose I have query "B:abc". > > so used below code with search : > > qp is object of query parser. > > Query query=qp.parse("B:abc"); > > Sort sort= new Sort(new SortField("A",SortField.STRING_VAL,true)); > > hits = searcher.search(query, null,100,sort); > > but when i search above way.it gives me result in sorting but sorting > applies to only matching first 100 results.It search first 100 results and > then sort. I want first 100 sorted descending of Field A with matching > query. > > Is it possible in Lucene? > > Thanks > > *Regards, > > Yogesh Patel* >
-- Sincerely yours,
Apostolis Xekoukoulotakis
-
Re: Lucene Query About Sorting
Ian Lea 2012-06-26, 17:12
Do you mean you want all hits that match B:abc, sorted by field A? As opposed to the top 100 hits sorted by field A? Just pass a higher value in the search(query, ... 100, ...) call. It will be slower and potentially use more memory but with only 10K docs you probably won't notice. -- Ian.
On Tue, Jun 26, 2012 at 4:05 AM, Yogesh patel <[EMAIL PROTECTED]> wrote: > Hi, > > I have one query of lucene about sort. > > I have 10000 documents in my index which having fields A,B,C,D. i want > first 100 results in my query but they must be sort by field A. > Suppose I have query "B:abc". > > so used below code with search : > > qp is object of query parser. > > Query query=qp.parse("B:abc"); > > Sort sort= new Sort(new SortField("A",SortField.STRING_VAL,true)); > > hits = searcher.search(query, null,100,sort); > > but when i search above way.it gives me result in sorting but sorting > applies to only matching first 100 results.It search first 100 results and > then sort. I want first 100 sorted descending of Field A with matching > query. > > Is it possible in Lucene? > > Thanks > > *Regards, > > Yogesh Patel*
---------------------------------------------------------------------
-
Re: Lucene Query About Sorting
Yogesh patel 2012-06-27, 05:44
Thanks for reply Ian ,
But i just gave suppose document number..i have 2-3 GB index and every day , it goes higher. so i cant use searcher.maxdoc(). So i need this solution. Can you please help me out? On Tue, Jun 26, 2012 at 10:42 PM, Ian Lea <[EMAIL PROTECTED]> wrote:
> Do you mean you want all hits that match B:abc, sorted by field A? As > opposed to the top 100 hits sorted by field A? Just pass a higher > value in the search(query, ... 100, ...) call. It will be slower and > potentially use more memory but with only 10K docs you probably won't > notice. > > > -- > Ian. > > > > On Tue, Jun 26, 2012 at 4:05 AM, Yogesh patel > <[EMAIL PROTECTED]> wrote: > > Hi, > > > > I have one query of lucene about sort. > > > > I have 10000 documents in my index which having fields A,B,C,D. i want > > first 100 results in my query but they must be sort by field A. > > Suppose I have query "B:abc". > > > > so used below code with search : > > > > qp is object of query parser. > > > > Query query=qp.parse("B:abc"); > > > > Sort sort= new Sort(new SortField("A",SortField.STRING_VAL,true)); > > > > hits = searcher.search(query, null,100,sort); > > > > but when i search above way.it gives me result in sorting but sorting > > applies to only matching first 100 results.It search first 100 results > and > > then sort. I want first 100 sorted descending of Field A with matching > > query. > > > > Is it possible in Lucene? > > > > Thanks > > > > *Regards, > > > > Yogesh Patel* > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- *
Regards,
Yogesh Patel*
-
Re: Lucene Query About Sorting
Li Li 2012-06-27, 07:54
what do you want to do? 1. sort all matched docs by field A. 2. sort all matched docs by relevant score, selecting top 100 docs and then sort by field A On Wed, Jun 27, 2012 at 1:44 PM, Yogesh patel <[EMAIL PROTECTED]> wrote: > Thanks for reply Ian , > > But i just gave suppose document number..i have 2-3 GB index and every day > , it goes higher. so i cant use searcher.maxdoc(). So i need this solution. > Can you please help me out? > > > On Tue, Jun 26, 2012 at 10:42 PM, Ian Lea <[EMAIL PROTECTED]> wrote: > >> Do you mean you want all hits that match B:abc, sorted by field A? As >> opposed to the top 100 hits sorted by field A? Just pass a higher >> value in the search(query, ... 100, ...) call. It will be slower and >> potentially use more memory but with only 10K docs you probably won't >> notice. >> >> >> -- >> Ian. >> >> >> >> On Tue, Jun 26, 2012 at 4:05 AM, Yogesh patel >> <[EMAIL PROTECTED]> wrote: >> > Hi, >> > >> > I have one query of lucene about sort. >> > >> > I have 10000 documents in my index which having fields A,B,C,D. i want >> > first 100 results in my query but they must be sort by field A. >> > Suppose I have query "B:abc". >> > >> > so used below code with search : >> > >> > qp is object of query parser. >> > >> > Query query=qp.parse("B:abc"); >> > >> > Sort sort= new Sort(new SortField("A",SortField.STRING_VAL,true)); >> > >> > hits = searcher.search(query, null,100,sort); >> > >> > but when i search above way.it gives me result in sorting but sorting >> > applies to only matching first 100 results.It search first 100 results >> and >> > then sort. I want first 100 sorted descending of Field A with matching >> > query. >> > >> > Is it possible in Lucene? >> > >> > Thanks >> > >> > *Regards, >> > >> > Yogesh Patel* >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [EMAIL PROTECTED] >> For additional commands, e-mail: [EMAIL PROTECTED] >> >> > > > -- > * > > Regards, > > Yogesh Patel*
---------------------------------------------------------------------
-
Re: Lucene Query About Sorting
Ian Lea 2012-06-27, 09:11
I think he wants 1, sort all matched docs by field A.
If lucene sorting doesn't work for you you can always sort the hits yourself using whatever technique you want. Sorting large numbers of docs is always going to be expensive. -- Ian. On Wed, Jun 27, 2012 at 8:54 AM, Li Li <[EMAIL PROTECTED]> wrote: > what do you want to do? > 1. sort all matched docs by field A. > 2. sort all matched docs by relevant score, selecting top 100 docs and > then sort by field A > > > On Wed, Jun 27, 2012 at 1:44 PM, Yogesh patel > <[EMAIL PROTECTED]> wrote: >> Thanks for reply Ian , >> >> But i just gave suppose document number..i have 2-3 GB index and every day >> , it goes higher. so i cant use searcher.maxdoc(). So i need this solution. >> Can you please help me out? >> >> >> On Tue, Jun 26, 2012 at 10:42 PM, Ian Lea <[EMAIL PROTECTED]> wrote: >> >>> Do you mean you want all hits that match B:abc, sorted by field A? As >>> opposed to the top 100 hits sorted by field A? Just pass a higher >>> value in the search(query, ... 100, ...) call. It will be slower and >>> potentially use more memory but with only 10K docs you probably won't >>> notice. >>> >>> >>> -- >>> Ian. >>> >>> >>> >>> On Tue, Jun 26, 2012 at 4:05 AM, Yogesh patel >>> <[EMAIL PROTECTED]> wrote: >>> > Hi, >>> > >>> > I have one query of lucene about sort. >>> > >>> > I have 10000 documents in my index which having fields A,B,C,D. i want >>> > first 100 results in my query but they must be sort by field A. >>> > Suppose I have query "B:abc". >>> > >>> > so used below code with search : >>> > >>> > qp is object of query parser. >>> > >>> > Query query=qp.parse("B:abc"); >>> > >>> > Sort sort= new Sort(new SortField("A",SortField.STRING_VAL,true)); >>> > >>> > hits = searcher.search(query, null,100,sort); >>> > >>> > but when i search above way.it gives me result in sorting but sorting >>> > applies to only matching first 100 results.It search first 100 results >>> and >>> > then sort. I want first 100 sorted descending of Field A with matching >>> > query. >>> > >>> > Is it possible in Lucene? >>> > >>> > Thanks >>> > >>> > *Regards, >>> > >>> > Yogesh Patel* >>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: [EMAIL PROTECTED] >>> For additional commands, e-mail: [EMAIL PROTECTED] >>> >>> >> >> >> -- >> * >> >> Regards, >> >> Yogesh Patel* > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] >
---------------------------------------------------------------------
-
Re: Lucene Query About Sorting
Apostolis Xekoukoulotakis... 2012-06-27, 09:51
Cant he synchronously iterate over both fields postingLists and use one priorityQueue that picks the docs that contain the query and have the best order according to the second field.
It requires more work but this should be feasible.
2012/6/27 Ian Lea <[EMAIL PROTECTED]>
> I think he wants 1, sort all matched docs by field A. > > If lucene sorting doesn't work for you you can always sort the hits > yourself using whatever technique you want. Sorting large numbers of > docs is always going to be expensive. > > > -- > Ian. > > > On Wed, Jun 27, 2012 at 8:54 AM, Li Li <[EMAIL PROTECTED]> wrote: > > what do you want to do? > > 1. sort all matched docs by field A. > > 2. sort all matched docs by relevant score, selecting top 100 docs and > > then sort by field A > > > > > > On Wed, Jun 27, 2012 at 1:44 PM, Yogesh patel > > <[EMAIL PROTECTED]> wrote: > >> Thanks for reply Ian , > >> > >> But i just gave suppose document number..i have 2-3 GB index and every > day > >> , it goes higher. so i cant use searcher.maxdoc(). So i need this > solution. > >> Can you please help me out? > >> > >> > >> On Tue, Jun 26, 2012 at 10:42 PM, Ian Lea <[EMAIL PROTECTED]> wrote: > >> > >>> Do you mean you want all hits that match B:abc, sorted by field A? As > >>> opposed to the top 100 hits sorted by field A? Just pass a higher > >>> value in the search(query, ... 100, ...) call. It will be slower and > >>> potentially use more memory but with only 10K docs you probably won't > >>> notice. > >>> > >>> > >>> -- > >>> Ian. > >>> > >>> > >>> > >>> On Tue, Jun 26, 2012 at 4:05 AM, Yogesh patel > >>> <[EMAIL PROTECTED]> wrote: > >>> > Hi, > >>> > > >>> > I have one query of lucene about sort. > >>> > > >>> > I have 10000 documents in my index which having fields A,B,C,D. i > want > >>> > first 100 results in my query but they must be sort by field A. > >>> > Suppose I have query "B:abc". > >>> > > >>> > so used below code with search : > >>> > > >>> > qp is object of query parser. > >>> > > >>> > Query query=qp.parse("B:abc"); > >>> > > >>> > Sort sort= new Sort(new SortField("A",SortField.STRING_VAL,true)); > >>> > > >>> > hits = searcher.search(query, null,100,sort); > >>> > > >>> > but when i search above way.it gives me result in sorting but > sorting > >>> > applies to only matching first 100 results.It search first 100 > results > >>> and > >>> > then sort. I want first 100 sorted descending of Field A with > matching > >>> > query. > >>> > > >>> > Is it possible in Lucene? > >>> > > >>> > Thanks > >>> > > >>> > *Regards, > >>> > > >>> > Yogesh Patel* > >>> > >>> --------------------------------------------------------------------- > >>> To unsubscribe, e-mail: [EMAIL PROTECTED] > >>> For additional commands, e-mail: [EMAIL PROTECTED] > >>> > >>> > >> > >> > >> -- > >> * > >> > >> Regards, > >> > >> Yogesh Patel* > > > > --------------------------------------------------------------------- > > 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] > > -- Sincerely yours,
Apostolis Xekoukoulotakis
-
Re: Lucene Query About Sorting
Karthik Muthuswami 2012-06-28, 23:01
On Jun 26, 2012, at 5:32 AM, Apostolis Xekoukoulotakis wrote:
> I am just new here. > > When you make a query, you create an ordering of the documents based on > this query. > If you have a second ordering, you have to decide what to do with those 2 > orderings. You have to decide how to join those two. > > The default search orders your results by the query and picks the top n, > then it sorts them by your sort. > You can see the code at TopDocColector. > > 2012/6/26 Yogesh patel <[EMAIL PROTECTED]> > >> Hi, >> >> I have one query of lucene about sort. >> >> I have 10000 documents in my index which having fields A,B,C,D. i want >> first 100 results in my query but they must be sort by field A. >> Suppose I have query "B:abc". >> >> so used below code with search : >> >> qp is object of query parser. >> >> Query query=qp.parse("B:abc"); >> >> Sort sort= new Sort(new SortField("A",SortField.STRING_VAL,true)); >> >> hits = searcher.search(query, null,100,sort); >> >> but when i search above way.it gives me result in sorting but sorting >> applies to only matching first 100 results.It search first 100 results and >> then sort. I want first 100 sorted descending of Field A with matching >> query. >> >> Is it possible in Lucene? >> >> Thanks >> >> *Regards, >> >> Yogesh Patel* >> > > > > -- > > > Sincerely yours, > > Apostolis Xekoukoulotakis
Regards, Karthik ---------------------------------------------------------------------
|
|