-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4b24bd0
commit ba5d463
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
api/src/main/java/org/openmrs/api/db/hibernate/search/ConceptNameSimilarity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* The contents of this file are subject to the OpenMRS Public License | ||
* Version 1.0 (the "License"); you may not use this file except in | ||
* compliance with the License. You may obtain a copy of the License at | ||
* http://license.openmrs.org | ||
* | ||
* Software distributed under the License is distributed on an "AS IS" | ||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing rights and limitations | ||
* under the License. | ||
* | ||
* Copyright (C) OpenMRS, LLC. All Rights Reserved. | ||
*/ | ||
package org.openmrs.api.db.hibernate.search; | ||
|
||
import org.apache.lucene.index.FieldInvertState; | ||
import org.apache.lucene.search.DefaultSimilarity; | ||
|
||
public class ConceptNameSimilarity extends DefaultSimilarity { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
@Override | ||
public float computeNorm(String field, FieldInvertState state) { | ||
final int numTerms; | ||
if (discountOverlaps) | ||
numTerms = state.getLength() - state.getNumOverlap(); | ||
else | ||
numTerms = state.getLength(); | ||
|
||
//Score longer documents much lower | ||
return state.getBoost() * ((float) (1.0 / numTerms / numTerms / numTerms / numTerms)); | ||
} | ||
} |