Hi Nic,
What I meant was something like below
DIGY
public
System.Collections.Generic.List<Lucene.Net.Documents.Document>
Sort(Lucene.Net.Search.Hits Hits)
{
System.Collections.Generic.List<Lucene.Net.Documents.Document>
retList = new List<Lucene.Net.Documents.Document>();
System.Collections.Generic.List<float> scores = new
List<float>();
for (int i = 0; i < Hits.Length(); i++)
{
scores.Add(Hits.Score(i));
retList.Add(Hits.Doc(i));
}
//BUBBLE SORT Q(n)=n*n
//This is the one of the worst sorting algorithms you can ever
find. Replace it with an inteligent one.
bool anotherPassNeeded = true;
while (anotherPassNeeded)
{
anotherPassNeeded = false;
for (int i = 0; i < retList.Count-1; i++)
{
if(
CalcScore(retList[i].GetField("field2").StringValue() , scores[i] ) <
CalcScore(retList[i+1].GetField("field2").StringValue() , scores[i+1]) )
{
anotherPassNeeded = true;
float fTemp = scores[i];
scores[i] = scores[i + 1];
scores[i + 1] = fTemp;
Lucene.Net.Documents.Document doc = retList[i];
retList[i] = retList[i + 1];
retList[i + 1] = doc;
}
}
}
return retList;
}
//Your custom Score Function
float CalcScore(string FieldValue, float OriginalScore)
{
char lastChar = FieldValue[FieldValue.Length - 1];
return OriginalScore * lastChar;
}
-----Original Message-----
From: Nic Wise [mailto:[EMAIL PROTECTED]
Sent: Wednesday, January 16, 2008 1:43 PM
To: [email protected]
Subject: RE: Bubbling up "newer" records
Thanks! Do you have a URL or some sample code for how to write a custom
sort function? I am wanting it to influence the results (as a boost
does), not really sort by this one field.
Eg, if I start out with a relevance of 0.1 and 0.9, if the 0.1 one was
put in today, it may end up being 0.7, and if the 0.9 one was 3 months
old, it may be down-graded to 0.72 - so it's not just a pure sort....
I tried a quick google (and will continue once I have this new laptop
built up), but couldn't find much. Is there a snippit somewhere?
Thanks heaps!
-----Original Message-----
From: DIGY [mailto:[EMAIL PROTECTED]
Sent: 15 January 2008 20:18
To: [email protected]
Subject: RE: Bubbling up "newer" records
Hi Nic,
CustomScoreQuery or FieldScoreQuery is introduced with Lucene 2.2.
If you don't want to wait for Lucene.Net 2.2, writing a custom sort
function
and sorting the returned results -for ex.,using the "timestamp" field
and
the Score() method of Hits class- may be a quick solution.
DIGY
-----Original Message-----
From: Nic Wise [mailto:[EMAIL PROTECTED]
Sent: Tuesday, January 15, 2008 7:46 PM
To: [email protected]
Subject: Bubbling up "newer" records
Hi there
Long time user (and reader), first time poster J
Just wondering if anyone knows of a way to bubble up (ie, increase the
score on) items which are newer - either via putting a date field in the
document, or some kind of timestamp / tick count.
I have found some references to doing it in the Java version, but I
can't find many of the the classes (FieldScoreQuery, CustomScoreQuery)
in the .NET version - I assume they are new in the Java version. I
looked into replacing the Query, Weight, Scorer set, modelling it off
the Lucene.Net.Search.Spans stuff.... But nothing so far.
Am I even looking in the right place? Is it even possible?
I'm after something with a long, flat tail (so I guess I'm going to have
to write something custom regardless) - eg stuff which is 1 day old gets
a boost of 10, 1 week old is 5, 1 month is 2, over three months is 0 etc
(with a floating scale on those - think "the long tail" diagram
(http://en.wikipedia.org/wiki/The_Long_Tail), but have it hit 0 when it
flattens out.)
Anyone done this?
Thanks heaps.
Nic Wise
Lead .NET Developer, TopGear.com redevelopment.
BBC Worldwide.
This e-mail (and any attachments) is confidential and may contain
personal
views which are not the views of the BBC unless specifically stated. If
you
have received it in error, please delete it from your system. Do not
use,
copy or disclose the information in any way nor act in reliance on it
and
notify the sender immediately.
Please note that the BBC monitors e-mails sent or received. Further
communication will signify your consent to this
This e-mail has been sent by one of the following wholly-owned
subsidiaries
of the BBC:
BBC Worldwide, Registration Number: 1420028 England, Registered Address:
Woodlands, 80 Wood Lane, London W12 0TT
BBC World, Registration Number: 04514407 England, Registered Address:
Woodlands, 80 Wood Lane, London W12 0TT
BBC World Distribution Limited, Registration Number: 04514408,
Registered
Address: Woodlands, 80 Wood Lane, London W12 0TT
This e-mail (and any attachments) is confidential and may contain personal
views which are not the views of the BBC unless specifically stated. If you
have received it in error, please delete it from your system. Do not use,
copy or disclose the information in any way nor act in reliance on it and
notify the sender immediately.
Please note that the BBC monitors e-mails sent or received. Further
communication will signify your consent to this
This e-mail has been sent by one of the following wholly-owned subsidiaries
of the BBC:
BBC Worldwide, Registration Number: 1420028 England, Registered Address:
Woodlands, 80 Wood Lane, London W12 0TT
BBC World, Registration Number: 04514407 England, Registered Address:
Woodlands, 80 Wood Lane, London W12 0TT
BBC World Distribution Limited, Registration Number: 04514408, Registered
Address: Woodlands, 80 Wood Lane, London W12 0TT