Re: Boosting documents

2004-07-27 Thread Akmal Sarhan
Hallo,

I have followed your suggestion but I am not sure how it should be done
to achieve the following:
I want when I do the following search to have the score calculated so
that those with nr of kids higher get a better score and the less kids,
the less score , notice that I still want to get all documents

thanks for any input

import java.io.IOException;

import org.apache.lucene.analysis.SimpleAnalyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.Term;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.DefaultSimilarity;
import org.apache.lucene.search.Hits;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Searcher;
import org.apache.lucene.store.RAMDirectory;

public class TestMatching
{

protected float f;

public static void main(String[] args) throws IOException,
ParseException
{

RAMDirectory store = new RAMDirectory();
IndexWriter writer = new IndexWriter(store, new
SimpleAnalyzer(), true);

Field f1 = Field.Text("field", "word");
Field kids1 = Field.Keyword("kids", "2");
Field kids2 = Field.Keyword("kids", "3");
Field kids3 = Field.Keyword("kids", "4");

Document d1 = new Document();
Document d2 = new Document();
Document d3 = new Document();

d1.add(f1);
d2.add(f1);
d3.add(f1);
d1.add(kids1);
d2.add(kids2);
d3.add(kids3);

d1.add(f1);
writer.addDocument(d1);
writer.addDocument(d2);
writer.addDocument(d3);

writer.optimize();
writer.close();

Searcher s = new IndexSearcher(store);

s.setSimilarity(new DefaultSimilarity() {

public float idf(Term term, Searcher searcher) throws
IOException
{
String string = term.text();
String string2 = term.field();
float f = 0.0f;
if (term.field().equals("kids"))
{
// and now ??
} else
{
f = idf(searcher.docFreq(term), searcher.maxDoc());
}

return f;
}
});
Query query = QueryParser.parse("field:word kids:5", "field",
new StandardAnalyzer());
Hits hits = s.search(query);

for (int i = 0; i < hits.length(); ++i)
{
Document doc = hits.doc(i);
System.out.println(i + " " + hits.score(i));

}

}
}

Am Mo, den 26.07.2004 schrieb Doug Cutting um 20:14:
> Rob Clews wrote:
> > I want to do the same, set a boost for a field containing a date that
> > lowers as the date is further from now, is there any way I could do
> > this?
> 
> You could implement Similarity.idf(Term, Searcher) to, when 
> Term.field().equals("date"), return a value that is greater for more 
> recent dates.
> 
> Doug
> 
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> !EXCUBATOR:41054a2d101985076154790!
> 


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Boosting documents

2004-07-26 Thread Doug Cutting
Rob Clews wrote:
I want to do the same, set a boost for a field containing a date that
lowers as the date is further from now, is there any way I could do
this?
You could implement Similarity.idf(Term, Searcher) to, when 
Term.field().equals("date"), return a value that is greater for more 
recent dates.

Doug
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Boosting documents

2004-07-26 Thread Rob Clews
I want to do the same, set a boost for a field containing a date that
lowers as the date is further from now, is there any way I could do
this?

Also when I set a document boost at index time, with doc.setBoost(2);
then retrieve it via doc.getBoost() I always seem to get 1.0, even
though I can tell from a search that the boost works correctly. I
realise the docs say that the returned value may not be the same as the
indexed value, but should I always get 1? Essentially I'm trying to
allow an administrator to set the boost on the document through my
webapp.

Thanks

On Mon, 2004-07-26 at 17:17 +0200, Akmal Sarhan wrote:
> I want to boost those with the oldest age to have a better score for
> example but in conjunction with other criteria (therefore the new Sort
> will not help I guess)

-- 
Rob Clews
Klear Systems Ltd
t: +44 (0)121 707 8558 e: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]