完善爽哥给亿信智能知识库的接口

完善爽哥给亿信智能知识库的接口 solr源码(https://github.com/jack00000/esensoft/tree/master/solr)

  • 1.需要干的事:把数据从数据库取出来 放到文件 通过代码把数据集按照需要的结构插入solr
  • 2.与how2j教程的 区别 文件中每个字段以逗号相隔 而亿信华晨智能知识库数据库字段的数据有逗号
    如果写到文件 读的时候会出现问题。

遇到的坑

1.Integer.valueOf(fields[1]) 总报下面的错误 靠

  • NumberFormatException: For input string: “”
  • 结果:文件里面有四行 一行数据 3行空格 我靠!!!!!!!!!!!!!!!!!!!!!!!!

2.定义一个集合插入数据时

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
List<String> questionsString=new ArrayList<>();
for (int i = 0; i < 10; i++) {
questionsString.add(new String("亿信华晨怎么样?" + i));
}
//我写成 结果没数据 。。。。。。。。。
for(String q:questions){
questionsString.add(new String("亿信华晨怎么样?" + i));
}
```

## 3.object转int
- solr deleteById 需要string类型id 。。。。。。
```java
//把id存入ids 并在solr上删除
int[] ids=new int[10];
for(int i=0;i<documents.size();i++){
System.out.println(documents.get(i).getFieldValue("id"));
ids[i]=Integer.valueOf(documents.get(i).getFieldValue("id").toString());
System.out.println(ids[i]);

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package com.fangjun.esensoft_solr.solrInterface;

import java.util.List;
import java.util.Map;

/**
* 索引管理器
*
* @author esen
*
*/
public interface DocsManager {
/**
* 添加一个索引
*
* @param questions 不同的答案可以有多种问法
* @param aid 答案的id
* @throws Exception
*/
public void addDocs(List<String> questions, int aid) throws Exception;

/**
* 更新这个问题的索引
*
* @param questions 不同的答案可以有多种问法
* @param aid 答案的id
* @throws Exception
*/
public void updateDocs(List<String> questions, int aid) throws Exception;

/**
* 根据答案id去删除索引,删除问题时要调用此方法删除这个答案和它的所有问题
*
* @param aid
* @throws Exception
*/
public void deleteDocsByAid(int aid) throws Exception;

/**
* 根据关键词,查找此关键词对应的问题和答案返回给前端
*
* @param word 短语
* @return
* @throws Exception
*/
public Map<String, Integer> getSuggestQuestions(String word) throws Exception;

}