| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| SearchType |
|
| 1.3636363636363635;1.364 | ||||
| SearchType$1 |
|
| 1.3636363636363635;1.364 | ||||
| SearchType$2 |
|
| 1.3636363636363635;1.364 | ||||
| SearchType$3 |
|
| 1.3636363636363635;1.364 | ||||
| SearchType$4 |
|
| 1.3636363636363635;1.364 | ||||
| SearchType$5 |
|
| 1.3636363636363635;1.364 | ||||
| SearchType$6 |
|
| 1.3636363636363635;1.364 | ||||
| SearchType$7 |
|
| 1.3636363636363635;1.364 |
| 1 | /** | |
| 2 | * Distribution License: | |
| 3 | * JSword is free software; you can redistribute it and/or modify it under | |
| 4 | * the terms of the GNU Lesser General Public License, version 2.1 or later | |
| 5 | * as published by the Free Software Foundation. This program is distributed | |
| 6 | * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even | |
| 7 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
| 8 | * See the GNU Lesser General Public License for more details. | |
| 9 | * | |
| 10 | * The License is available on the internet at: | |
| 11 | * http://www.gnu.org/copyleft/lgpl.html | |
| 12 | * or by writing to: | |
| 13 | * Free Software Foundation, Inc. | |
| 14 | * 59 Temple Place - Suite 330 | |
| 15 | * Boston, MA 02111-1307, USA | |
| 16 | * | |
| 17 | * © CrossWire Bible Society, 2005 - 2016 | |
| 18 | * | |
| 19 | */ | |
| 20 | package org.crosswire.jsword.index.search; | |
| 21 | ||
| 22 | import org.crosswire.jsword.index.query.QueryDecorator; | |
| 23 | import org.crosswire.jsword.index.query.QueryDecoratorFactory; | |
| 24 | ||
| 25 | /** | |
| 26 | * An Enumeration of the possible types of Searches. | |
| 27 | * | |
| 28 | * @see gnu.lgpl.License The GNU Lesser General Public License for details. | |
| 29 | * @author DM Smith | |
| 30 | */ | |
| 31 | 0 | public enum SearchType { |
| 32 | /** | |
| 33 | * Find the words in the specified order. | |
| 34 | */ | |
| 35 | 0 | PHRASE ("Phrase") { |
| 36 | @Override | |
| 37 | public String decorate(String queryWords) { | |
| 38 | 0 | return SEARCH_SYNTAX.decoratePhrase(queryWords); |
| 39 | } | |
| 40 | }, | |
| 41 | ||
| 42 | /** | |
| 43 | * Find all the words regardless of position. | |
| 44 | */ | |
| 45 | 0 | ALL_WORDS ("All") { |
| 46 | @Override | |
| 47 | public String decorate(String queryWords) { | |
| 48 | 0 | return SEARCH_SYNTAX.decorateAllWords(queryWords); |
| 49 | } | |
| 50 | }, | |
| 51 | ||
| 52 | /** | |
| 53 | * Find any of these words | |
| 54 | */ | |
| 55 | 0 | ANY_WORDS ("Any") { |
| 56 | @Override | |
| 57 | public String decorate(String queryWords) { | |
| 58 | 0 | return SEARCH_SYNTAX.decorateAnyWords(queryWords); |
| 59 | } | |
| 60 | }, | |
| 61 | ||
| 62 | /** | |
| 63 | * Find verses not containing these words. Note this may require being added | |
| 64 | * after words being sought. | |
| 65 | */ | |
| 66 | 0 | NOT_WORDS ("Not") { |
| 67 | @Override | |
| 68 | public String decorate(String queryWords) { | |
| 69 | 0 | return SEARCH_SYNTAX.decorateNotWords(queryWords); |
| 70 | } | |
| 71 | }, | |
| 72 | ||
| 73 | /** | |
| 74 | * Find verses with words that start with the these beginnings. | |
| 75 | */ | |
| 76 | 0 | START_WORDS ("Start") { |
| 77 | @Override | |
| 78 | public String decorate(String queryWords) { | |
| 79 | 0 | return SEARCH_SYNTAX.decorateStartWords(queryWords); |
| 80 | } | |
| 81 | }, | |
| 82 | ||
| 83 | /** | |
| 84 | * Find verses with words spelled something like | |
| 85 | */ | |
| 86 | 0 | SPELL_WORDS ("Spell") { |
| 87 | @Override | |
| 88 | public String decorate(String queryWords) { | |
| 89 | 0 | return SEARCH_SYNTAX.decorateSpellWords(queryWords); |
| 90 | } | |
| 91 | }, | |
| 92 | ||
| 93 | /** | |
| 94 | * Find verses in this range | |
| 95 | */ | |
| 96 | 0 | RANGE ("Range") { |
| 97 | @Override | |
| 98 | public String decorate(String queryWords) { | |
| 99 | 0 | return SEARCH_SYNTAX.decorateRange(queryWords); |
| 100 | } | |
| 101 | }; | |
| 102 | ||
| 103 | /** | |
| 104 | * @param name | |
| 105 | * The name of the BookCategory | |
| 106 | */ | |
| 107 | 0 | SearchType(String name) { |
| 108 | 0 | this.name = name; |
| 109 | 0 | } |
| 110 | ||
| 111 | /** | |
| 112 | * Decorate a string with the given type of decoration. | |
| 113 | * @param queryWords | |
| 114 | * @return the decorated query | |
| 115 | */ | |
| 116 | public abstract String decorate(String queryWords); | |
| 117 | ||
| 118 | /** | |
| 119 | * Lookup method to convert from a String | |
| 120 | * | |
| 121 | * @param name | |
| 122 | * @return the matching search type | |
| 123 | */ | |
| 124 | public static SearchType fromString(String name) { | |
| 125 | 0 | for (SearchType v : values()) { |
| 126 | 0 | if (v.name.equalsIgnoreCase(name)) { |
| 127 | 0 | return v; |
| 128 | } | |
| 129 | } | |
| 130 | ||
| 131 | 0 | throw new ClassCastException("Not a valid search type"); |
| 132 | } | |
| 133 | ||
| 134 | /* (non-Javadoc) | |
| 135 | * @see java.lang.Enum#toString() | |
| 136 | */ | |
| 137 | @Override | |
| 138 | public String toString() { | |
| 139 | 0 | return name; |
| 140 | } | |
| 141 | ||
| 142 | /** | |
| 143 | * The name of the BookCategory | |
| 144 | */ | |
| 145 | private String name; | |
| 146 | ||
| 147 | 0 | protected static final QueryDecorator SEARCH_SYNTAX = QueryDecoratorFactory.getSearchSyntax(); |
| 148 | } |