有没有办法搜索在某个字段的前10个单词中包含单词的所有文档?
由于
答案 0 :(得分:1)
如果您希望它始终是您要定位的特定字段的前十个单词,也许您可以在schema.xml
中添加一个字段,该字段只包含该字段的前十个单词。
答案 1 :(得分:1)
编写一个带有参数的分析仪非常容易,该参数具有最大令牌数,可以过滤剩余的令牌,使其可重复使用。
您可以轻松修改schema.xml以将原始字段内容复制到此字段并使用此字段进行搜索。
答案 2 :(得分:-1)
这样的事情应该这样做:
public boolean doesWordExist(String word, String path) {
String line = null;
int count = 0;
String token = null;
BufferedReader br = null;
File folder = new File(path);
File[] listOfFiles = folder.listFiles(/*use filename filter here*/);
for (int i = 0; i < listOfFiles.length; i++) {
count=0;
if (listOfFiles[i].isFile()) {
try {
br = new BufferedReader(new InputStreamReader(
new FileInputStream(listOfFiles[i].getName())));
while ((line = br.readLine()) != null && count < 10) {
StringTokenizer tknz = new StringTokenizer(line, "");
while (tknz.hasMoreTokens() && count < 10 /* variable */) {
token = tknz.nextToken();
if (token.equalsIgnoreCase(word)) {
return true;
}
count++;
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
br.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}// if
}//for
return false;
}
String line = null;
int count = 0;
String token = null;
BufferedReader br = null;
File folder = new File(path);
File[] listOfFiles = folder.listFiles(/*use filename filter here*/);
for (int i = 0; i < listOfFiles.length; i++) {
count=0;
if (listOfFiles[i].isFile()) {
try {
br = new BufferedReader(new InputStreamReader(
new FileInputStream(listOfFiles[i].getName())));
while ((line = br.readLine()) != null && count < 10) {
StringTokenizer tknz = new StringTokenizer(line, "");
while (tknz.hasMoreTokens() && count < 10 /* variable */) {
token = tknz.nextToken();
if (token.equalsIgnoreCase(word)) {
return true;
}
count++;
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
br.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}// if
}//for
return false;
}