Java Android在搜索中获取搜索词

Java Android在搜索中获取搜索词,java,android,string,search,text,Java,Android,String,Search,Text,我有任何问题,比如什么是java。出于这个问题,我想过滤掉搜索词,在谷歌上进行自动搜索,在这种情况下,搜索词是:java。 另一个例子: 问题: What is the opposite of long? 搜索词为: opposite of long 如果您知道问题的布局,可以使用字符串子字符串方法 String question = "What is the opposite of long?"; String searchTerm = question.substring(9, ques

我有任何问题,比如
什么是java
。出于这个问题,我想过滤掉搜索词,在谷歌上进行自动搜索,在这种情况下,搜索词是:
java
。 另一个例子: 问题:

What is the opposite of long?
搜索词为:

opposite of long

如果您知道问题的布局,可以使用字符串子字符串方法

String question = "What is the opposite of long?";
String searchTerm = question.substring(9, question.length() - 1);
编辑: 这仅适用于此类问题,因此,如果要应用自定义语义过滤器,请执行以下操作:

String question = "What is the opposite of long?";
String[] invalidSearchValues = {"Where", "What", "Why", "?", "!"};
String[] questionWords = question.split(" ");
String searchTerm = "";

for (String word : questionWords) {
    if (!Arrays.asList(invalidSearchValues).contains(word)) {
        searchTerm+= " " + word;
    }
}

我指的是任何问题的搜索词,特别是这个问题。它适用于每个以“What is”开头,以“?”结尾的问题。你想为这个问题实现一个语义过滤器,这很难。作为一种替代方法,您可以将字符串按空格分割,并从中过滤出每个疑问词和符号。这不是我的问题在数据库中(这是您应该使用的),您可以使用SQL
之类的
操作符。