1 /*************************************************************************** 2 * (C) Copyright 2014 - Faiumoni e. V. * 3 *************************************************************************** 4 *************************************************************************** 5 * * 6 * This program is free software; you can redistribute it and/or modify * 7 * it under the terms of the GNU General Public License as published by * 8 * the Free Software Foundation; either version 2 of the License, or * 9 * (at your option) any later version. * 10 * * 11 ***************************************************************************/ 12 package games.stendhal.server.core.rp.searchindex; 13 14 import java.util.Locale; 15 16 17 /** 18 * a search index entry 19 * 20 * @author hendrik 21 */ 22 public class SearchIndexEntry { 23 24 private final String searchTerm; 25 private final char entityType; 26 private final String entityName; 27 private final int searchScore; 28 private final int dbId; 29 30 /** 31 * a search index entry 32 * 33 * @param searchTerm the search term, usually a phrase or a single word 34 * @param entityType type of entity (A achievement, I item, C creatures, N NPC, Z zone) 35 * @param entityName name of entity 36 * @param searchScore score of this match 37 * (30: match on the complete name, 38 * 20: match on parts of the name, 39 * 10: match on parts of the descriptions) 40 */ SearchIndexEntry(String searchTerm, char entityType, String entityName, int searchScore)41 public SearchIndexEntry(String searchTerm, char entityType, String entityName, int searchScore) { 42 this.searchTerm = searchTerm.toLowerCase(Locale.ENGLISH); 43 this.entityType = entityType; 44 this.entityName = entityName; 45 this.searchScore = searchScore; 46 this.dbId = -1; 47 } 48 49 /** 50 * a search index entry 51 * 52 * @param searchTerm the search term, usually a phrase or a single word 53 * @param entityType type of entity (A achievement, I item, C creatures, N NPC, Z zone) 54 * @param entityName name of entity 55 * @param searchScore score of this match 56 * (30: match on the complete name, 57 * 20: match on parts of the name, 58 * 10: match on parts of the descriptions) 59 * @param dbId database table id 60 */ SearchIndexEntry(String searchTerm, char entityType, String entityName, int searchScore, int dbId)61 public SearchIndexEntry(String searchTerm, char entityType, String entityName, int searchScore, int dbId) { 62 this.searchTerm = searchTerm.toLowerCase(Locale.ENGLISH); 63 this.entityType = entityType; 64 this.entityName = entityName; 65 this.searchScore = searchScore; 66 this.dbId = dbId; 67 } 68 69 /** 70 * gets the search term 71 * 72 * @return search term 73 */ getSearchTerm()74 public String getSearchTerm() { 75 return searchTerm; 76 } 77 78 /** 79 * gets the entity type 80 * 81 * @return entity type 82 */ getEntityType()83 public char getEntityType() { 84 return entityType; 85 } 86 87 /** 88 * gets the entity name 89 * 90 * @return name of entity 91 */ getEntityName()92 public String getEntityName() { 93 return entityName; 94 } 95 96 /** 97 * gets the search score 98 * 99 * @return search score 100 */ getSearchScore()101 public int getSearchScore() { 102 return searchScore; 103 } 104 105 /** 106 * gets the database id 107 * 108 * @return database id or -1 109 */ getDbId()110 public int getDbId() { 111 return dbId; 112 } 113 114 @Override hashCode()115 public int hashCode() { 116 final int prime = 31; 117 int result = 1; 118 result = prime * result + entityName.hashCode(); 119 result = prime * result + entityType; 120 result = prime * result + searchScore; 121 result = prime * result + searchTerm.hashCode(); 122 return result; 123 } 124 125 @Override equals(Object obj)126 public boolean equals(Object obj) { 127 if (!(obj instanceof SearchIndexEntry)) { 128 return false; 129 } 130 SearchIndexEntry other = (SearchIndexEntry) obj; 131 132 if (!entityName.equals(other.entityName)) { 133 return false; 134 } 135 if (entityType != other.entityType) { 136 return false; 137 } 138 if (searchScore != other.searchScore) { 139 return false; 140 } 141 if (!searchTerm.equals(other.searchTerm)) { 142 return false; 143 } 144 145 return true; 146 } 147 } 148