1 23 24 package org.apache.slide.index; 25 26 import org.apache.slide.search.basic.IBasicExpressionFactory; 27 import org.apache.slide.search.basic.IBasicQuery; 28 import org.apache.slide.search.basic.IBasicExpression; 29 import org.apache.slide.search.PropertyProvider; 30 import org.apache.slide.search.BadQueryException; 31 import org.apache.slide.content.NodeProperty; 32 import org.jdom.Element; 33 34 import org.apache.lucene.analysis.Analyzer; 35 36 import java.util.Collection ; 37 38 42 public class TextContainsExpressionFactory implements IBasicExpressionFactory { 43 44 45 private IBasicQuery query; 46 protected PropertyProvider propertyProvider; 47 48 private String rootPath; 49 private Analyzer analyzer; 50 51 57 public TextContainsExpressionFactory (String rootPath, Analyzer analyzer) 58 { 59 this.rootPath = rootPath; 60 this.analyzer = analyzer; 61 } 62 63 75 public IBasicExpression createMergeExpression (String mergeOperator, 76 String namespace, 77 Collection expressionsToMerge) 78 throws BadQueryException 79 { 80 return null; 81 } 82 83 93 public IBasicExpression createExpression (Element element) 94 throws BadQueryException 95 { 96 TextContainsExpression result = null; 97 98 if (element == null) 99 { 100 throw new BadQueryException ("expected a where criteria"); 101 } 102 else 103 { 104 String namespace = element.getNamespace().getURI(); 105 if (namespace.equals (NodeProperty.NamespaceCache.DEFAULT_URI)) 106 result = createDAVExpression (element); 107 108 } 112 result.setFactory(this); 113 return result; 114 } 115 116 117 126 private TextContainsExpression createDAVExpression (Element e) 127 { 128 String name = e.getName(); 129 TextContainsExpression result = null; 130 131 if (name.equals ("contains")) 132 { 133 String searchedText = e.getTextTrim(); 134 result = new TextContainsExpression (searchedText, rootPath, analyzer); 135 } 136 137 return result; 138 } 139 140 149 public void init(IBasicQuery query, PropertyProvider propertyProvider) 150 throws BadQueryException 151 { 152 this.query = (IBasicQuery) query; 153 this.propertyProvider = propertyProvider; 154 } 155 156 162 public PropertyProvider getPropertyProvider() 163 { 164 return propertyProvider; 165 } 166 167 173 public IBasicQuery getQuery() 174 { 175 return query; 176 } 177 } 178 | Popular Tags |