Changeset 629
- Timestamp:
- Jul 15, 2010, 10:35:53 AM (14 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/services/InventoryItemSearchService.groovy
r616 r629 146 146 def getTextSearch(params, locale) { 147 147 def result = [:] 148 result.searchText = params.searchText.trim() ?: "" 148 result.searchText = params.searchText.trim() ?: "" // User supplied text. 149 result.queryString = "" // Modified string that will be passed to searchable query. 149 150 150 151 def getMessage = { Map m -> … … 183 184 searchableParams.properties = properitesList 184 185 185 // Require isActive and isObsolete. 186 def queryString = '( '+result.searchText+' )'+ ' AND isActive:"true" AND isObsolete:"false"' 186 // Check searchText for key words and modifiers. 187 def hasIsActive = result.searchText.contains('isActive') 188 def hasIsObsolete = result.searchText.contains('isObsolete') 189 def hasBracket = result.searchText.contains('(') || result.searchText.contains(')') 190 def containsModifier = { s -> 191 s.contains('"') || 192 s.contains('~') || 193 s.contains('*') || 194 s.contains('(') || 195 s.contains(')') || 196 s.contains('+') || 197 s.contains('-') || 198 s.contains('^') || 199 s.contains('OR') || 200 s.contains('AND') || 201 s.contains('NOT') || 202 s.contains('TO') || 203 s.contains('isObsolete') || 204 s.contains('isActive') 205 } 206 207 // Expand search with wildcards. 208 def addWildcards = { text -> 209 text = text.tokenize().collect { token -> 210 if(!containsModifier(token)) 211 '*'+token+'*' 212 else 213 token 214 }.join(' ') 215 return text 216 } 217 218 // Default isActive and isObsolete. 219 def addDefaultFlags = { text -> 220 if(!hasBracket) 221 text = '( '+text+' )' 222 if(!hasIsActive) 223 text = text + ' AND isActive:"true" ' 224 if(!hasIsObsolete) 225 text = text + ' AND isObsolete:"false" ' 226 return text 227 } 228 229 result.queryString = addWildcards(result.searchText) 230 result.queryString = addDefaultFlags(result.queryString) 187 231 188 232 // Perform the searchable query. 189 233 try { 190 result.inventoryItemList = InventoryItem.search( queryString, searchableParams)234 result.inventoryItemList = InventoryItem.search(result.queryString, searchableParams) 191 235 192 236 // Would be nice if this worked. … … 234 278 // Get the result message. 235 279 if(result.inventoryItemList.totalCount > 0) 236 result.message = getMessage(code:"inventoryItem.search.text.found", args: [result. searchText])280 result.message = getMessage(code:"inventoryItem.search.text.found", args: [result.queryString]) 237 281 else 238 result.message = getMessage(code:"inventoryItem.search.text.none.found", args: [result. searchText])282 result.message = getMessage(code:"inventoryItem.search.text.none.found", args: [result.queryString]) 239 283 240 284 // Success. -
trunk/grails-app/views/inventoryItemDetailed/search.gsp
r615 r629 38 38 39 39 <span> <!--Prevent IE inheriting margin--> 40 < input type="text" style="width:450px;" maxlength="75" id="searchText" name="searchText" value="${filterParams.searchText}"/>40 <g:textField style="width:450px;" maxlength="75" id="searchText" name="searchText" value="${filterParams.searchText}" /> 41 41 <g:helpBalloon code="inventoryItem.search.searchText" /> 42 42
Note: See TracChangeset
for help on using the changeset viewer.