1 /************************************************************************************************* 2 * Pure Java interface of Hyper Estraier 3 * Copyright (C) 2004-2007 Mikio Hirabayashi 4 * All rights reserved. 5 * This file is part of Hyper Estraier. 6 * Redistribution and use in source and binary forms, with or without modification, are 7 * permitted provided that the following conditions are met: 8 * 9 * * Redistributions of source code must retain the above copyright notice, this list of 10 * conditions and the following disclaimer. 11 * * Redistributions in binary form must reproduce the above copyright notice, this list of 12 * conditions and the following disclaimer in the documentation and/or other materials 13 * provided with the distribution. 14 * * Neither the name of Mikio Hirabayashi nor the names of its contributors may be used to 15 * endorse or promote products derived from this software without specific prior written 16 * permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS 19 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 21 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 26 * OF THE POSSIBILITY OF SUCH DAMAGE. 27 *************************************************************************************************/ 28 29 30 package estraier.pure; 31 32 import java.util.*; 33 import java.io.*; 34 import java.net.*; 35 36 37 38 /** 39 * Abstraction of search condition. 40 */ 41 public class Condition { 42 //---------------------------------------------------------------- 43 // public constants 44 //---------------------------------------------------------------- 45 /** option: check every N-gram key */ 46 public static final int SURE = 1 << 0; 47 /** option: check N-gram keys skipping by one */ 48 public static final int USUAL = 1 << 1; 49 /** option: check N-gram keys skipping by two */ 50 public static final int FAST = 1 << 2; 51 /** option: check N-gram keys skipping by three */ 52 public static final int AGITO = 1 << 3; 53 /** option: without TF-IDF tuning */ 54 public static final int NOIDF = 1 << 4; 55 /** option: with the simplified phrase */ 56 public static final int SIMPLE = 1 << 10; 57 /** option: with the rough phrase */ 58 public static final int ROUGH = 1 << 11; 59 /** option: with the union phrase */ 60 public static final int UNION = 1 << 15; 61 /** option: with the intersection phrase */ 62 public static final int ISECT = 1 << 16; 63 //---------------------------------------------------------------- 64 // private fields 65 //---------------------------------------------------------------- 66 private String phrase; 67 private List attrs; 68 private String order; 69 private int max; 70 private int skip; 71 private int options; 72 private int auxiliary; 73 private String distinct; 74 private int mask; 75 //---------------------------------------------------------------- 76 // constructors 77 //---------------------------------------------------------------- 78 /** 79 * Create a search condition object. 80 */ Condition()81 public Condition(){ 82 phrase = null; 83 attrs = new ArrayList(31); 84 order = null; 85 max = -1; 86 skip = 0; 87 options = 0; 88 auxiliary = 32; 89 distinct = null; 90 mask = 0; 91 } 92 //---------------------------------------------------------------- 93 // public methods 94 //---------------------------------------------------------------- 95 /** 96 * Set the search phrase. 97 * @param phrase a search phrase. 98 */ set_phrase(String phrase)99 public void set_phrase(String phrase){ 100 this.phrase = phrase; 101 } 102 /** 103 * Add an expression for an attribute. 104 * @param expr an expression for an attribute. 105 */ add_attr(String expr)106 public void add_attr(String expr){ 107 attrs.add(expr); 108 } 109 /** 110 * Set the order. 111 * @param expr an expression for the order. By default, the order is by score descending. 112 */ set_order(String expr)113 public void set_order(String expr){ 114 order = expr; 115 } 116 /** 117 * Set the maximum number of retrieval. 118 * @param max the maximum number of retrieval. By default, the number of retrieval is not 119 * limited. 120 */ set_max(int max)121 public void set_max(int max){ 122 if(max >= 0) this.max = max; 123 } 124 /** 125 * Set the number of skipped documents. 126 * @param skip the number of documents to be skipped in the search result. 127 */ set_skip(int skip)128 public void set_skip(int skip){ 129 if(skip >= 0) this.skip = skip; 130 } 131 /** 132 * Set options of retrieval. 133 * @param options options: `Condition.SURE' specifies that it checks every N-gram key, 134 * `Condition.USUAL', which is the default, specifies that it checks N-gram keys with skipping 135 * one key, `Condition.FAST' skips two keys, `Condition.AGITO' skips three keys, 136 * `Condition.NOIDF' specifies not to perform TF-IDF tuning, `Condition.SIMPLE' specifies to 137 * use simplified phrase, `Condition.ROUGH' specifies to use rough phrase, `Condition.UNION' 138 * specifies to use union phrase, `Condition.ISECT' specifies to use intersection phrase. Each 139 * option can be specified at the same time by bitwise or. If keys are skipped, though search 140 * speed is improved, the relevance ratio grows less. 141 */ set_options(int options)142 public void set_options(int options){ 143 this.options |= options; 144 } 145 /** 146 * Set permission to adopt result of the auxiliary index. 147 * @param min the minimum hits to adopt result of the auxiliary index. If it is not more 148 * than 0, the auxiliary index is not used. By default, it is 32. 149 */ set_auxiliary(int min)150 public void set_auxiliary(int min){ 151 this.auxiliary = min; 152 } 153 /** 154 * Set the attribute distinction filter. 155 * @param name the name of an attribute to be distinct. 156 */ set_distinct(String name)157 public void set_distinct(String name){ 158 distinct = name; 159 } 160 /** 161 * Set the mask of targets of meta search. 162 * @param mask a masking number. 1 means the first target, 2 means the second target, 4 means 163 * the third target and, power values of 2 and their summation compose the mask. 164 */ set_mask(int mask)165 public void set_mask(int mask){ 166 this.mask = mask & 0x7fffffff; 167 } 168 //---------------------------------------------------------------- 169 // package methods 170 //---------------------------------------------------------------- 171 /** 172 * Get the search phrase. 173 * @return the search phrase. 174 */ phrase()175 String phrase(){ 176 if(phrase == null) return ""; 177 return phrase; 178 } 179 /** 180 * Get expressions for attributes. 181 * @return expressions for attributes. 182 */ attrs()183 List attrs(){ 184 return attrs; 185 } 186 /** 187 * Get the order expression. 188 * @return the order expression. 189 */ order()190 String order(){ 191 if(order == null) return ""; 192 return order; 193 } 194 /** 195 * Get the maximum number of retrieval. 196 * @return the maximum number of retrieval. 197 */ max()198 int max(){ 199 return max; 200 } 201 /** 202 * Get the number of skipped documents. 203 * @return the number of documents to be skipped in the search result. 204 */ skip()205 int skip(){ 206 return skip; 207 } 208 /** 209 * Get options of retrieval. 210 * @return options by bitwise or. 211 */ options()212 int options(){ 213 return options; 214 } 215 /** 216 * Get permission to adopt result of the auxiliary index. 217 * @return permission to adopt result of the auxiliary index. 218 */ auxiliary()219 int auxiliary(){ 220 return auxiliary; 221 } 222 /** 223 * Get the attribute distinction filter. 224 * @return the name of the distinct attribute. 225 */ distinct()226 String distinct(){ 227 if(distinct == null) return ""; 228 return distinct; 229 } 230 /** 231 * Get the mask of targets of meta search. 232 * @return the mask of targets of meta search. 233 */ mask()234 int mask(){ 235 return mask; 236 } 237 } 238 239 240 241 /* END OF FILE */ 242