Here you can find the source of getSQLTokens(String query)
Parameter | Description |
---|---|
query | The search query string. |
public static ArrayList<String> getSQLTokens(String query)
//package com.java2s; /*//from w ww. j a va2 s. c om MetaDB: A Distributed Metadata Collection Tool Copyright 2011, Lafayette College, Eric Luhrs, Haruki Yamaguchi, Long Ho. This file is part of MetaDB. MetaDB is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. MetaDB is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with MetaDB. If not, see <http://www.gnu.org/licenses/>. */ import java.util.ArrayList; public class Main { /** * Returns a list of Strings representing the terms in the search string. * The words must be separated by whitespace and quotes signify an exact match. * @param query The search query string. * @return an ArrayList of Strings, containing the original query separated to individual search terms */ public static ArrayList<String> getSQLTokens(String query) { //Parse query into quoted/non-quoted words String[] tokens = query.split("#(?:\"([^\"]+)\")|([^ ]+)#"); String noteTokens = ""; for (String token : tokens) noteTokens += "\"" + token + "\" "; //MetaDbHelper.note("Search tokens: "+noteTokens); ArrayList<String> sqlTokens = new ArrayList<String>(); int numTokens = tokens.length; for (int i = 0; i < numTokens; i++) { String quotesRemovedString = tokens[i].replaceAll("\"", ""); sqlTokens.add("%" + quotesRemovedString.trim().toLowerCase() + "%"); } return sqlTokens; } }