Advertisement
k-joseph

Untitled

Jun 30th, 2014
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1. /**
  2. * The contents of this file are subject to the OpenMRS Public License
  3. * Version 1.0 (the "License"); you may not use this file except in
  4. * compliance with the License. You may obtain a copy of the License at
  5. * http://license.openmrs.org
  6. *
  7. * Software distributed under the License is distributed on an "AS IS"
  8. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
  9. * License for the specific language governing rights and limitations
  10. * under the License.
  11. *
  12. * Copyright (C) OpenMRS, LLC. All Rights Reserved.
  13. */
  14. package org.openmrs.module.chartsearch.solr;
  15.  
  16. import java.util.ArrayList;
  17. import java.util.List;
  18.  
  19. import org.apache.commons.lang.StringEscapeUtils;
  20. import org.junit.Test;
  21.  
  22. /**
  23. * Handles all behavior of interpreting the search phrase entered into the search box which we
  24. * return to solr as query, we are currently using Boolean search syntax.
  25. */
  26. public class ChartSearchSyntax {
  27.  
  28. /**
  29. * Search phrase entered in the search box, e.g. "Blood Pressure"
  30. */
  31. private String searchPhrase;
  32.  
  33. /**
  34. * A collection of words from the search phrase entered in the search box, e.g. "Blood" and
  35. * "Pressure"
  36. */
  37. private List<String> wordsFromSearchPhrase = new ArrayList<String>();
  38.  
  39. public String getSearchPhrase() {
  40. return searchPhrase;
  41. }
  42.  
  43. private List<String> getWordsFromSearchPhrase() {
  44. return wordsFromSearchPhrase;
  45. }
  46.  
  47. /**
  48. * To define Chart Search Syntax behaviour, we must at all times have searchPhrase
  49. *
  50. * @param searchPhrase
  51. */
  52. public ChartSearchSyntax(String searchPhrase) {
  53. this.searchPhrase = searchPhrase;
  54. }
  55.  
  56. /**
  57. * Takes search phrase and breaks it down into words: for-example. "Blood Pressure" into
  58. * ["Blood", "Pressure"]
  59. *
  60. * @param searchPhrase
  61. * @return {@link #getWordsFromSearchPhrase()}
  62. */
  63. public List<String> breakDownASearchPhraseIntoWords(String searchPhrase) {
  64. String[] words = searchPhrase.split("\\s+");
  65. for (int i = 0; i < words.length; i++) {
  66. words[i] = words[i].replaceAll("[!?,]", "");
  67. this.wordsFromSearchPhrase.add(words[i]);
  68. }
  69. return getWordsFromSearchPhrase();
  70. }
  71.  
  72. /**
  73. * Picks a phrase got from the UI and checks for presence of double quotes ("Blood Pressure")
  74. *
  75. * @param searchPhrase
  76. * @return
  77. */
  78. public boolean shouldTakePhraseAsItIs() {
  79.  
  80. String searchPhrase = getSearchPhrase();
  81. //TODO add code for achieving this hear
  82. return false;
  83. }
  84.  
  85. /**
  86. * Returns A collection of floats when given a whole number, e.g. 36 returns; 36.2, etc
  87. *
  88. * @param wholeValue
  89. * @return
  90. */
  91. public List<Double> searchFloatsWhenGivenWholeNumber(long wholeValue) {
  92. List<Double> estimatedValues = new ArrayList<Double>();
  93. //TODO add code here
  94.  
  95. return estimatedValues;
  96. }
  97.  
  98. /**
  99. * Checks the datatype of the searchPhrase entered in the UI and returns it
  100. *
  101. * @param searchPhrase
  102. * @return
  103. */
  104. public Object checkSearchPhraseDatatypeAndReturnIt(Object searchPhrase) {
  105. //TODO add code here
  106.  
  107. return searchPhrase;
  108. }
  109.  
  110. /**
  111. * Handles obs:blood, so that we search for blood in obs and the the like
  112. *
  113. * @param searchPhrase
  114. */
  115. public void searchAgainstSpecificiedFields(String searchPhrase) {
  116. //TODO add code here
  117. }
  118.  
  119. /**
  120. * Handles support for wildcard (**) in searches, e.g. foo becomes (foo or foo*)
  121. *
  122. * @param searchPhrase
  123. */
  124. public void modifyPhraseToSearchForMany() {
  125. //TODO add code here
  126. String searchPhrase = getSearchPhrase();
  127. }
  128.  
  129. /**
  130. * Supports searching parts of words? For example searching "hem" would return "hemoglobin" and
  131. * "hematocrit"
  132. *
  133. * @param searchPhrase
  134. */
  135. public void supportAutoCompleteOfPhrases() {
  136. //TODO add code here
  137. String searchPhrase = getSearchPhrase();
  138. }
  139.  
  140. @Test
  141. public void test() {
  142. //remove double quotes from the sentence
  143. String input = "\"this is a simple sentence\"";
  144. String result = input.replaceFirst("(?s)^\"(.*)\"$", " $1 ");
  145.  
  146. System.out.println(result);
  147.  
  148. String str = "kaweesi joseph is improving in programming";
  149. String results = StringEscapeUtils.escapeJava(str);
  150. System.out.println(results);
  151. }
  152.  
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement