001: /*
002:
003: This software is OSI Certified Open Source Software.
004: OSI Certified is a certification mark of the Open Source Initiative.
005:
006: The license (Mozilla version 1.0) can be read at the MMBase site.
007: See http://www.MMBase.org/license
008:
009: */
010: package org.mmbase.storage.search;
011:
012: import java.util.*;
013:
014: /**
015: * A constraint specifically for advanced types of text searches.
016: * <p>
017: * In addition to searchterms, a <em>search type</em> and a
018: * <em>match type</em> can be specified:
019: * <p>
020: * The search type specifies how the search is performed:
021: * Must be one of:
022: * <ul>
023: * <li>{@link #SEARCH_TYPE_WORD_ORIENTED SEARCH_TYPE_WORD_ORIENTED}
024: * - searches for the most occurrences of the words in the search terms.
025: * Order and proximity of words is not significant.
026: * <li>{@link #SEARCH_TYPE_PHRASE_ORIENTED SEARCH_TYPE_PHRASE_ORIENTED}
027: * - searches for occurrence of the sequence of words in the search terms.
028: * <li>{@link #SEARCH_TYPE_PROXIMITY_ORIENTED SEARCH_TYPE_PROXIMITY_ORIENTED}
029: * - searches for the most occurrences of the words within a given
030: * word distance.
031: * Order of words is not important.
032: * </ul>
033: * <p>
034: * The match type specifies how individual words in the
035: * search terms are matched with words in the searched text.
036: * <ul>
037: * <li>{@link #MATCH_TYPE_LITERAL MATCH_TYPE_LITERAL}
038: * - exact match only
039: * <li>{@link #MATCH_TYPE_FUZZY MATCH_TYPE_FUZZY}
040: * - fuzzy match: matches words within the specified number of
041: * typo's as well (specified by parameter <code>PARAM_FUZZINESS</code>)
042: * <li>{@link #MATCH_TYPE_SYNONYM MATCH_TYPE_SYNONYM}
043: * - matches synonyms as well
044: * </ul>
045: * <p>
046: * The searchterms may containt the following wildchard characters as well:
047: * <ul>
048: * <li>% for any string
049: * <li>_ for a single character
050: * </ul>
051: * <p>
052: * Depending on searchtype and searchmode, the following parameters
053: * can be set:
054: * <ul>
055: * <li>{@link #PARAM_FUZZINESS PARAM_FUZZINESS}
056: * - <code>Float</code>, specifies maximum allowed number of
057: * typo's per word, expressed as fraction of word length.
058: * (E.g. 0,2 means: maximum 2 typo's for 10 letter words.).<br />
059: * This parameter is only relevant when used with match type
060: * <code>MATCH_TYPE_FUZZY</code>.
061: * It can only be set for this match type, and is cleared when
062: * the match type is set to another value.
063: * <li>{@link #PARAM_PROXIMITY_LIMIT PARAM_PROXIMITY_LIMIT}
064: * - <code>Integer</code>, specifies maximum distance between
065: * searched words.<br />
066: * This parameter is only relevant when used with search type
067: * <code>SEARCH_TYPE_PROXIMITY_ORIENTED</code>.
068: * It can only be set for this search type, and is cleared when
069: * the search type is set to another value.
070: * </ul>
071: *
072: * @author Rob van Maris
073: * @version $Id: StringSearchConstraint.java,v 1.5 2007/02/24 21:57:50 nklasens Exp $
074: * @since MMBase-1.7
075: */
076: public interface StringSearchConstraint extends FieldConstraint {
077:
078: /** Search type for <em>word oriented</em> search. */
079: public final static int SEARCH_TYPE_WORD_ORIENTED = 1;
080:
081: /** Search type for <em>phrase oriented</em> search. */
082: public final static int SEARCH_TYPE_PHRASE_ORIENTED = 2;
083:
084: /** Search type for <em>proximity oriented</em> search. */
085: public final static int SEARCH_TYPE_PROXIMITY_ORIENTED = 3;
086:
087: /**
088: * Search type descriptions corresponding to the search type values:
089: * {@link #SEARCH_TYPE_WORD_ORIENTED}, {@link #SEARCH_TYPE_PHRASE_ORIENTED}, and
090: * {@link #SEARCH_TYPE_PROXIMITY_ORIENTED}
091: */
092: String[] SEARCH_TYPE_DESCRIPTIONS = new String[] { null, // not specified
093: "word oriented", "phrase oriented", "proximity oriented" };
094:
095: /** Match type for <em>literal</em> matching. */
096: public final static int MATCH_TYPE_LITERAL = 1;
097:
098: /** Match type for <em>fuzzy</em> matching. */
099: public final static int MATCH_TYPE_FUZZY = 2;
100:
101: /** Match type for <em>synonym</em> matching. */
102: public final static int MATCH_TYPE_SYNONYM = 3;
103:
104: /**
105: * Match type descriptions corresponding to the match type values:
106: * {@link #MATCH_TYPE_LITERAL}, {@link #MATCH_TYPE_FUZZY}, and
107: * {@link #MATCH_TYPE_SYNONYM}
108: */
109: public final static String[] MATCH_TYPE_DESCRIPTIONS = new String[] {
110: null, // not specified
111: "literal", "fuzzy", "synonym" };
112:
113: /** Name for parameter specifying <em>fuzziness</em> for fuzzy matching. */
114: public final static String PARAM_FUZZINESS = "fuzziness";
115:
116: /**
117: * Name for parameter specifying <em>proximity limit</em> for
118: * proximity oriented search.
119: */
120: public final static String PARAM_PROXIMITY_LIMIT = "proximityLimit";
121:
122: /**
123: * Gets the search type, this specifies how the search is performed.
124: */
125: int getSearchType();
126:
127: /**
128: * Gets value of additional parameters.
129: *
130: * @return The parameters, as an unmodifiable Map.
131: */
132: Map<String, Object> getParameters();
133:
134: /**
135: * Gets the match type.
136: */
137: int getMatchType();
138:
139: /**
140: * Gets the list of searchterms.
141: *
142: * @return The searchterms, as an unmodifiable List.
143: */
144: List<String> getSearchTerms();
145:
146: /**
147: * Returns a string representation of this StringSearchConstraint.
148: * The string representation has the form
149: * "StringSearchConstraint(inverse:<:inverse>, field:<field>,
150: * casesensitive:<casesensitive>, searchtype:<searchtype>,
151: * matchtype:<matchtype>, parameters:<parameters>,
152: * searchterms:<searchterms>)"
153: * where
154: * <ul>
155: * <li><em><inverse></em>is the value returned by
156: * {@link #isInverse isInverse()}
157: * <li><em><field></em> is the field alias returned by
158: * <code>getField().getAlias()</code>
159: * <li><em><casesensitive></em> is the value returned by
160: * {@link FieldConstraint#isCaseSensitive isCaseSensitive()}
161: * <li><em><searchtype></em> is the value returned by
162: * {@link StringSearchConstraint#getSearchType getSearchType()}
163: * <li><em><matchtype></em> is the value returned by
164: * {@link StringSearchConstraint#getMatchType getMatchType()}
165: * <li><em><parameters></em> is the map returned by
166: * {@link StringSearchConstraint#getParameters getParameters()}
167: * <li><em><searchterms></em> is the list returned by
168: * {@link StringSearchConstraint#getSearchTerms getParameters()}
169: *
170: * @return A string representation of this FieldValueConstraint.
171: */
172: public String toString();
173:
174: }
|