FAQ
Hello,

i'm trying to introduce an additional weighting using payloads.

Therefore i implemented my own Similarity class (see below) and implemented
scorePayload().

My problem is, that scorePayload() is not called during search.
On the other Hand i overwrote the tf() method and that one gets called during
searching.
I am also using PayloadTermQuery, so that should make the scorePayload()
method get called.

Anyone has an Idea what i'm doing wrong?

---------
IndexSearcher searcher = getIndexSearcher(dir);
searcher.setSimilarity(new MySimilarity());
Term t = new Term(TikaConstants.FIELD_CONTENT, SEARCHTERM);
Query q = new PayloadTermQuery(t, new AveragePayloadFunction());
TopDocs docs = searcher.search(q, 15);
---------
public class MySimilarity extends DefaultSimilarity {

@Override
public float tf(float freq) {
System.out.println("TF");
return super.tf(freq);
}

@Override
public float scorePayload(int docID, String fieldName, int start,
int end, byte[] payload, int offset,
int length) {
System.out.println("Called!");
if (payload != null) {
float boost = PayloadContainer.getBoost(payload);
System.out.println("Boosting: " + boost);
return boost;
} else {
return 1.0f;
}
}
}
---------

regards
Christoph Hermann

--
Christoph Hermann
Institut für Informatik
Tel: +49 761-203-8171 Fax: +49 761-203-8162
e-mail: hermann@informatik.uni-freiburg.de

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org

Search Discussions

  • Uwe Schindler at Oct 16, 2010 at 3:24 pm
    scorePayload should be called *if* there is a payload on the term you are
    searching for. If there is a payload on other terms you would not see it. So
    PayloadTermQuery only reports payloads on exactly the passed - in term (not
    on any other field or other term in the same field).

    Additionally, the payload byte array is a generally a very large one (it
    shares many payloads), so your function to calculate the boost from the
    payload must respect the offset and length parameter!

    -----
    Uwe Schindler
    H.-H.-Meier-Allee 63, D-28213 Bremen
    http://www.thetaphi.de
    eMail: uwe@thetaphi.de
    -----Original Message-----
    From: Christoph Hermann
    Sent: Saturday, October 16, 2010 4:55 PM
    To: java-user@lucene.apache.org
    Subject: scorePayload does not get called

    Hello,

    i'm trying to introduce an additional weighting using payloads.

    Therefore i implemented my own Similarity class (see below) and
    implemented
    scorePayload().

    My problem is, that scorePayload() is not called during search.
    On the other Hand i overwrote the tf() method and that one gets called during
    searching.
    I am also using PayloadTermQuery, so that should make the scorePayload()
    method get called.

    Anyone has an Idea what i'm doing wrong?

    ---------
    IndexSearcher searcher = getIndexSearcher(dir); searcher.setSimilarity(new
    MySimilarity()); Term t = new Term(TikaConstants.FIELD_CONTENT,
    SEARCHTERM); Query q = new PayloadTermQuery(t, new
    AveragePayloadFunction()); TopDocs docs = searcher.search(q, 15);

    ---------
    public class MySimilarity extends DefaultSimilarity {

    @Override
    public float tf(float freq) {
    System.out.println("TF");
    return super.tf(freq);
    }

    @Override
    public float scorePayload(int docID, String fieldName, int start,
    int end, byte[] payload, int
    offset,
    int length) {
    System.out.println("Called!");
    if (payload != null) {
    float boost = PayloadContainer.getBoost(payload);
    System.out.println("Boosting: " + boost);
    return boost;
    } else {
    return 1.0f;
    }
    }
    }
    ---------

    regards
    Christoph Hermann

    --
    Christoph Hermann
    Institut für Informatik
    Tel: +49 761-203-8171 Fax: +49 761-203-8162
    e-mail: hermann@informatik.uni-freiburg.de

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org


    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupjava-user @
categorieslucene
postedOct 16, '10 at 2:55p
activeOct 16, '10 at 3:24p
posts2
users2
websitelucene.apache.org

People

Translate

site design / logo © 2022 Grokbase