Project

General

Profile

Revision 608dd377

ID608dd377292d37b87da26ae0ab55ae6967ed21b5
Parent fd93c8b3
Child c93aed86

Added by Andreas Kohlbecker over 8 years ago

fixing #3117 (fulltext search: score values missing in results) and supplying maxScore

View differences:

cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/search/LuceneSearch.java
143 143
    public Searcher getSearcher() {
144 144
        if(searcher == null){
145 145
            searcher = new IndexSearcher(getIndexReader());
146
            ((IndexSearcher)searcher).setDefaultFieldSortScoring(true, true);
146 147
        }
147 148
        return searcher;
148 149
    }
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/search/SearchResult.java
29 29

  
30 30
    private float score = 0;
31 31

  
32
    private float maxScore = 0;
33

  
32 34
    private Document doc;
33 35

  
34 36
    private T entity;
......
79 81
    }
80 82

  
81 83

  
84
    public float getMaxScore() {
85
        return maxScore;
86
    }
87

  
88

  
89
    public void setMaxScore(float maxScore) {
90
        this.maxScore = maxScore;
91
    }
92

  
93

  
82 94

  
83 95

  
84 96

  
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/search/SearchResultBuilder.java
88 88
            String[] idStrings = doc.getValues(idField);
89 89
            SearchResult<T> searchResult = new SearchResult<T>(doc);
90 90

  
91
            if(!Double.isNaN(scoreDoc.score) && !Double.isInfinite(scoreDoc.score)){
91
            if(isNumber(scoreDoc.score)){
92 92
                searchResult.setScore(scoreDoc.score);
93 93
            }
94
            if(isNumber(topDocsResultSet.getMaxScore())){
95
                searchResult.setMaxScore(topDocsResultSet.getMaxScore());
96
            }
94 97

  
95 98
            //TODO use findByUuid(List<UUID> uuids, List<Criterion> criteria, List<String> propertyPaths)
96 99
            //      instead or even better a similar findById(List<Integer> ids) however this is not yet implemented
......
110 113
        return searchResults;
111 114
    }
112 115

  
116
    /**
117
     * @param scoreDoc
118
     * @return
119
     */
120
    private boolean isNumber(Float number) {
121
        return !Double.isNaN(number) && !Double.isInfinite(number);
122
    }
123

  
113 124
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)