Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * The contents of this file are subject to the OpenMRS Public License
- * Version 1.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://license.openmrs.org
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- * License for the specific language governing rights and limitations
- * under the License.
- *
- * Copyright (C) OpenMRS, LLC. All Rights Reserved.
- */
- package org.openmrs.module.chartsearch.solr;
- import java.util.ArrayList;
- import java.util.List;
- import org.apache.commons.lang.StringEscapeUtils;
- import org.junit.Test;
- /**
- * Handles all behavior of interpreting the search phrase entered into the search box which we
- * return to solr as query, we are currently using Boolean search syntax.
- */
- public class ChartSearchSyntax {
- /**
- * Search phrase entered in the search box, e.g. "Blood Pressure"
- */
- private String searchPhrase;
- /**
- * A collection of words from the search phrase entered in the search box, e.g. "Blood" and
- * "Pressure"
- */
- private List<String> wordsFromSearchPhrase = new ArrayList<String>();
- public String getSearchPhrase() {
- return searchPhrase;
- }
- private List<String> getWordsFromSearchPhrase() {
- return wordsFromSearchPhrase;
- }
- /**
- * To define Chart Search Syntax behaviour, we must at all times have searchPhrase
- *
- * @param searchPhrase
- */
- public ChartSearchSyntax(String searchPhrase) {
- this.searchPhrase = searchPhrase;
- }
- /**
- * Takes search phrase and breaks it down into words: for-example. "Blood Pressure" into
- * ["Blood", "Pressure"]
- *
- * @param searchPhrase
- * @return {@link #getWordsFromSearchPhrase()}
- */
- public List<String> breakDownASearchPhraseIntoWords(String searchPhrase) {
- String[] words = searchPhrase.split("\\s+");
- for (int i = 0; i < words.length; i++) {
- words[i] = words[i].replaceAll("[!?,]", "");
- this.wordsFromSearchPhrase.add(words[i]);
- }
- return getWordsFromSearchPhrase();
- }
- /**
- * Picks a phrase got from the UI and checks for presence of double quotes ("Blood Pressure")
- *
- * @param searchPhrase
- * @return
- */
- public boolean shouldTakePhraseAsItIs() {
- String searchPhrase = getSearchPhrase();
- //TODO add code for achieving this hear
- return false;
- }
- /**
- * Returns A collection of floats when given a whole number, e.g. 36 returns; 36.2, etc
- *
- * @param wholeValue
- * @return
- */
- public List<Double> searchFloatsWhenGivenWholeNumber(long wholeValue) {
- List<Double> estimatedValues = new ArrayList<Double>();
- //TODO add code here
- return estimatedValues;
- }
- /**
- * Checks the datatype of the searchPhrase entered in the UI and returns it
- *
- * @param searchPhrase
- * @return
- */
- public Object checkSearchPhraseDatatypeAndReturnIt(Object searchPhrase) {
- //TODO add code here
- return searchPhrase;
- }
- /**
- * Handles obs:blood, so that we search for blood in obs and the the like
- *
- * @param searchPhrase
- */
- public void searchAgainstSpecificiedFields(String searchPhrase) {
- //TODO add code here
- }
- /**
- * Handles support for wildcard (**) in searches, e.g. foo becomes (foo or foo*)
- *
- * @param searchPhrase
- */
- public void modifyPhraseToSearchForMany() {
- //TODO add code here
- String searchPhrase = getSearchPhrase();
- }
- /**
- * Supports searching parts of words? For example searching "hem" would return "hemoglobin" and
- * "hematocrit"
- *
- * @param searchPhrase
- */
- public void supportAutoCompleteOfPhrases() {
- //TODO add code here
- String searchPhrase = getSearchPhrase();
- }
- @Test
- public void test() {
- //remove double quotes from the sentence
- String input = "\"this is a simple sentence\"";
- String result = input.replaceFirst("(?s)^\"(.*)\"$", " $1 ");
- System.out.println(result);
- String str = "kaweesi joseph is improving in programming";
- String results = StringEscapeUtils.escapeJava(str);
- System.out.println(results);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement