lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Taylor <paul_t...@fastmail.fm>
Subject Re: Score exact matches higher than matches that match analysed text but not original text
Date Fri, 27 Jan 2012 16:25:47 GMT
On 10/01/2012 12:26, Paul Taylor wrote:
> On 10/01/2012 10:18, Ian Lea wrote:
>> If a term has an accent, add both accented and unaccented versions at
>> index and search time.
>>
>> So in your example your default field would contain
>>
>> República Republica
>>
>> and a search for "República" would expand to "República Republica" and
>> match both and score higher than a search for "Republica" which would
>> just match the unaccented version.
>
Ive done the simple case using a CustomScoreQuery

i.e in this case I say if the matching document has an exact match to 
the original artist name then boosting score slightly, Now need to 
extend it compare matching chars, ust be an algorithm for this somewhere.

    protected Query parseQuery(String userQuery) throws ParseException
     {
         Query q1 = dismaxSearcher.parseQuery(userQuery, analyzer);
         Query q2 = new MatchesOriginalValueBoosterQuery(q1, userQuery);
         return q2;
     }


     static class MatchesOriginalValueBoosterQuery extends 
CustomScoreQuery {

         private String userQuery;
         public MatchesOriginalValueBoosterQuery(Query query, String 
userQuery)
         {
             super(query);
             this.userQuery=userQuery;
         }

         public CustomScoreProvider getCustomScoreProvider(IndexReader 
r) throws IOException {
             return new ExactMatcherBooster(r);
         }

         private class ExactMatcherBooster extends CustomScoreProvider {

             public ExactMatcherBooster(IndexReader r) throws IOException {
                 super(r);

             }

             public float customScore(int docNo, float subQueryScore, 
float valSrcSource) {

                 try {
                     org.apache.lucene.document.Document doc = 
this.reader.document(docNo);
                     
if(userQuery.equals(doc.getValues(ArtistIndexField.ARTIST.getName())[0])) {
                         return subQueryScore * (1.1f);
                     }
                     else {
                         return subQueryScore;
                     }
                 }
                 catch(Exception ex) {
                     return subQueryScore;
                 }
             }
         }
     }
}


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


Mime
View raw message