FAQ
Hi,
I want to execute a query searching a few terms

QueryParser queryParser = new MultiFieldQueryParser(new String[] {"tags", "title"}, ProcessConstants.analyzer);
Query query = queryParser.parse("rocio ortega");

and I want to obtain the results sorted by the number of founded terms, but not considering other factors like the number of times found each term. ¿How can I do this?

SortField.FIELD_SCORE doesn´t work for this because I think it consider other factors like the number of times found each term.

Thanks

Search Discussions

  • Chris Hostetter at Aug 9, 2006 at 11:42 pm
    what you want is not a customized sort as much as a customized Score ..
    scores can be customized by modifying your Similarity, class -- LIA has
    some good info on this, but the best way to figure out what you want may
    be to start by creating your own Similarity class and then look at the
    search.explain output for your searches to understand how your changes
    affect things.


    : Date: Wed, 9 Aug 2006 13:46:30 +0200
    : From: Enrique Lamas <enrique.lamas@corp.ya.com>
    : Reply-To: java-user@lucene.apache.org
    : To: java-user@lucene.apache.org
    : Subject: custom sort
    :
    : Hi,
    : I want to execute a query searching a few terms
    :
    : QueryParser queryParser = new MultiFieldQueryParser(new String[] {"tags", "title"}, ProcessConstants.analyzer);
    : Query query = queryParser.parse("rocio ortega");
    :
    : and I want to obtain the results sorted by the number of founded terms, but not considering other factors like the number of times found each term. ¿How can I do this?
    :
    : SortField.FIELD_SCORE doesn´t work for this because I think it consider other factors like the number of times found each term.
    :
    : Thanks
    :



    -Hoss


    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org
  • Enrique Lamas at Aug 10, 2006 at 9:04 am
    Hi Chris,
    I investigated that way too, but I don't know how to do it.

    I have a query that searches two words. This query finds both words at two
    documents, with the difference that one of the words appears twice at the
    first document whereas at the second documents the two words appear only
    once. This makes the first document to have more score than second, ¿is this
    right? I don't know if more factors affect to this.

    Looking at the explanation, I see that the unique difference is what is
    returnes as fieldNorm.

    What I don't know is how can I make that fieldNorm returns the same value
    for both documents, and at the same time this values is bigger than if the
    query only found one of the words, smaller than finding three of three...

    Recapitulating,
    I think that I only need a score function that returns the number of
    searched words the query found at the document.

    I subclass DefaultSimilarity and set it to IndexSearcher, but I don't know
    what reimplementation of the methods is what I need.

    Thanks
    ----- Original Message -----
    From: "Chris Hostetter" <hossman_lucene@fucit.org>
    To: <java-user@lucene.apache.org>
    Sent: Thursday, August 10, 2006 1:41 AM
    Subject: Re: custom sort



    what you want is not a customized sort as much as a customized Score ..
    scores can be customized by modifying your Similarity, class -- LIA has
    some good info on this, but the best way to figure out what you want may
    be to start by creating your own Similarity class and then look at the
    search.explain output for your searches to understand how your changes
    affect things.


    : Date: Wed, 9 Aug 2006 13:46:30 +0200
    : From: Enrique Lamas <enrique.lamas@corp.ya.com>
    : Reply-To: java-user@lucene.apache.org
    : To: java-user@lucene.apache.org
    : Subject: custom sort
    :
    : Hi,
    : I want to execute a query searching a few terms
    :
    : QueryParser queryParser = new MultiFieldQueryParser(new String[] {"tags",
    "title"}, ProcessConstants.analyzer);
    : Query query = queryParser.parse("rocio ortega");
    :
    : and I want to obtain the results sorted by the number of founded terms,
    but not considering other factors like the number of times found each term.
    ¿How can I do this?
    :
    : SortField.FIELD_SCORE doesn´t work for this because I think it consider
    other factors like the number of times found each term.
    :
    : Thanks
    :



    -Hoss


    ---------------------------------------------------------------------
    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
  • Chris Hostetter at Aug 11, 2006 at 8:07 am
    : What I don't know is how can I make that fieldNorm returns the same value
    : for both documents, and at the same time this values is bigger than if the
    : query only found one of the words, smaller than finding three of three...
    ...
    : I subclass DefaultSimilarity and set it to IndexSearcher, but I don't know
    : what reimplementation of the methods is what I need.

    take a look at the lengthNorm function of Similarity. As i said before
    LIA ("Lucene In Action" just in case that isn't clear) has some great
    info on this, and if you search the archives for Similarity you'll find
    previous discussions about writing custom subclass ... the one special
    thing to note about lengthNorm is that it's used when the index is built
    -- so setting it at search time isn't enough.


    :
    : Thanks
    : ----- Original Message -----
    : From: "Chris Hostetter" <hossman_lucene@fucit.org>
    : To: <java-user@lucene.apache.org>
    : Sent: Thursday, August 10, 2006 1:41 AM
    : Subject: Re: custom sort
    :
    :
    :
    : what you want is not a customized sort as much as a customized Score ..
    : scores can be customized by modifying your Similarity, class -- LIA has
    : some good info on this, but the best way to figure out what you want may
    : be to start by creating your own Similarity class and then look at the
    : search.explain output for your searches to understand how your changes
    : affect things.
    :
    :
    : : Date: Wed, 9 Aug 2006 13:46:30 +0200
    : : From: Enrique Lamas <enrique.lamas@corp.ya.com>
    : : Reply-To: java-user@lucene.apache.org
    : : To: java-user@lucene.apache.org
    : : Subject: custom sort
    : :
    : : Hi,
    : : I want to execute a query searching a few terms
    : :
    : : QueryParser queryParser = new MultiFieldQueryParser(new String[] {"tags",
    : "title"}, ProcessConstants.analyzer);
    : : Query query = queryParser.parse("rocio ortega");
    : :
    : : and I want to obtain the results sorted by the number of founded terms,
    : but not considering other factors like the number of times found each term.
    : ¿How can I do this?
    : :
    : : SortField.FIELD_SCORE doesn´t work for this because I think it consider
    : other factors like the number of times found each term.
    : :
    : : Thanks
    : :
    :
    :
    :
    : -Hoss
    :
    :
    : ---------------------------------------------------------------------
    : 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
    :



    -Hoss


    ---------------------------------------------------------------------
    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
postedAug 9, '06 at 11:45a
activeAug 11, '06 at 8:07a
posts4
users2
websitelucene.apache.org

2 users in discussion

Enrique Lamas: 2 posts Chris Hostetter: 2 posts

People

Translate

site design / logo © 2022 Grokbase