| SearchType.java |
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 as published by
5 * the Free Software Foundation. This program is distributed in the hope
6 * that it will be useful, but WITHOUT ANY WARRANTY; without even the
7 * 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 * Copyright: 2005
18 * The copyright to this program is held by it's authors.
19 *
20 * ID: $Id: SearchType.java 2050 2010-12-09 15:31:45Z dmsmith $
21 */
22 package org.crosswire.jsword.index.search;
23
24 import org.crosswire.jsword.index.query.QueryDecorator;
25 import org.crosswire.jsword.index.query.QueryDecoratorFactory;
26
27 /**
28 * An Enumeration of the possible types of Searches.
29 *
30 * @see gnu.lgpl.License for license details.<br>
31 * The copyright to this program is held by it's authors.
32 * @author DM Smith [dmsmith555 at yahoo dot com]
33 */
34 public enum SearchType {
35 /**
36 * Find the words in the specified order.
37 */
38 PHRASE ("Phrase") {
39 @Override
40 public String decorate(String queryWords) {
41 return SEARCH_SYNTAX.decoratePhrase(queryWords);
42 }
43 },
44
45 /**
46 * Find all the words regardless of position.
47 */
48 ALL_WORDS ("All") {
49 @Override
50 public String decorate(String queryWords) {
51 return SEARCH_SYNTAX.decorateAllWords(queryWords);
52 }
53 },
54
55 /**
56 * Find any of these words
57 */
58 ANY_WORDS ("Any") {
59 @Override
60 public String decorate(String queryWords) {
61 return SEARCH_SYNTAX.decorateAnyWords(queryWords);
62 }
63 },
64
65 /**
66 * Find verses not containing these words. Note this may require being added
67 * after words being sought.
68 */
69 NOT_WORDS ("Not") {
70 @Override
71 public String decorate(String queryWords) {
72 return SEARCH_SYNTAX.decorateNotWords(queryWords);
73 }
74 },
75
76 /**
77 * Find verses with words that start with the these beginnings.
78 */
79 START_WORDS ("Start") {
80 @Override
81 public String decorate(String queryWords) {
82 return SEARCH_SYNTAX.decorateStartWords(queryWords);
83 }
84 },
85
86 /**
87 * Find verses with words spelled something like
88 */
89 SPELL_WORDS ("Spell") {
90 @Override
91 public String decorate(String queryWords) {
92 return SEARCH_SYNTAX.decorateSpellWords(queryWords);
93 }
94 },
95
96 /**
97 * Find verses in this range
98 */
99 RANGE ("Range") {
100 @Override
101 public String decorate(String queryWords) {
102 return SEARCH_SYNTAX.decorateRange(queryWords);
103 }
104 };
105
106 /**
107 * @param name
108 * The name of the BookCategory
109 */
110 private SearchType(String name) {
111 this.name = name;
112 }
113
114 /**
115 * Decorate a string with the given type of decoration.
116 */
117 public abstract String decorate(String queryWords);
118
119 /**
120 * Lookup method to convert from a String
121 */
122 public static SearchType fromString(String name) {
123 for (SearchType v : values()) {
124 if (v.name.equalsIgnoreCase(name)) {
125 return v;
126 }
127 }
128
129 throw new ClassCastException("Not a valid search type");
130 }
131
132 /* (non-Javadoc)
133 * @see java.lang.Enum#toString()
134 */
135 @Override
136 public String toString() {
137 return name;
138 }
139
140 /**
141 * The name of the BookCategory
142 */
143 private String name;
144
145 protected static final QueryDecorator SEARCH_SYNTAX = QueryDecoratorFactory.getSearchSyntax();
146 }
147