-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from oreillymedia/SPIDR-1451
SPIDR-1451 keep highest weight, de-dupe on text AND context
- Loading branch information
Showing
3 changed files
with
108 additions
and
7 deletions.
There are no files selected for viewing
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
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
82 changes: 82 additions & 0 deletions
82
src/main/java/com/ifactory/press/db/solr/spelling/suggest/Suggestion.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,82 @@ | ||
package com.ifactory.press.db.solr.spelling.suggest; | ||
|
||
import org.apache.lucene.util.BytesRef; | ||
|
||
import java.util.Set; | ||
|
||
public class Suggestion { | ||
|
||
private String text; | ||
private String payload; | ||
private Set<BytesRef> contexts; | ||
private long weight; | ||
|
||
public Suggestion(BytesRef text, Set<BytesRef> contexts, long weight, BytesRef payload) { | ||
this.text = text != null ? text.utf8ToString() : null; | ||
this.contexts = contexts; | ||
this.weight = weight; | ||
this.payload = payload != null ? payload.utf8ToString() : null; | ||
} | ||
|
||
public String getText() { | ||
return text; | ||
} | ||
|
||
public void setText(String text) { | ||
this.text = text; | ||
} | ||
|
||
public String getPayload() { | ||
return payload; | ||
} | ||
|
||
public void setPayload(String payload) { | ||
this.payload = payload; | ||
} | ||
|
||
public Set<BytesRef> getContexts() { | ||
return contexts; | ||
} | ||
|
||
public void setContexts(Set<BytesRef> contexts) { | ||
this.contexts = contexts; | ||
} | ||
|
||
public long getWeight() { | ||
return weight; | ||
} | ||
|
||
public void setWeight(long weight) { | ||
this.weight = weight; | ||
} | ||
|
||
/** | ||
* Overridden equals() method that only uses text and contexts variables for equality check. | ||
* @param other the other Object to be checked for equality to this Suggestion | ||
* @return true if 'other' is an instance of Suggestion and has the same text and | ||
* contexts as this Suggestion object. | ||
*/ | ||
@Override | ||
public boolean equals(Object other) { | ||
if(this == other) { | ||
return true; | ||
} | ||
|
||
if(!(other instanceof Suggestion)) { | ||
return false; | ||
} | ||
|
||
Suggestion otherSuggestion = (Suggestion)other; | ||
|
||
// Intentionally only using text and context to signify that two suggestions are equal. | ||
return this.text.equals(otherSuggestion.text) && this.contexts.equals(otherSuggestion.contexts); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = 17; | ||
result = 31 * result + text.hashCode(); | ||
result = 31 * result + contexts.hashCode(); | ||
return result; | ||
} | ||
} |