雪月蓝影 2018-11-26 08:20 采纳率: 0%
浏览 446

在使用lucene时,怎么设置搜索方式让输入短语(如管理信息系统),输出结果中必须带有管理,信息和系统

在使用lucene时,怎么设置搜索方式让输入短语(如管理信息系统),输出结果中必须带有管理,信息和系统?

 public ScoreDoc[] SearchIndex(String searchplace, String searchkey) throws Exception {
        Directory directory = FSDirectory.open(new File("F:\\temp\\index"));
        IndexReader indexReader = DirectoryReader.open(directory);
        IndexSearcher indexSearcher = new IndexSearcher(indexReader);
        IKAnalyzer analyzer = new IKAnalyzer();
        QueryParser parser = new QueryParser(searchplace, analyzer);
        Query query = parser.parse(searchkey);
        TopDocs topDocs = indexSearcher.search(query, 100);
        ScoreDoc[] scoreDocs = topDocs.scoreDocs;
        System.out.println("共有 " + topDocs.totalHits + " 条匹配的结果");
        System.out.println("共有 " + scoreDocs.length + " 条匹配的结果");
        System.out.println("-----------------------------------------------------------------");
        for (ScoreDoc scoreDoc : scoreDocs) {
            int doc = scoreDoc.doc;
            Document document = indexSearcher.doc(doc);
            // 文件名称
            String fileName = document.get("fileName");
            System.out.println(fileName);
            // 文件内容
            String fileContent = document.get("fileContent");
            System.out.println(fileContent);
            // 文件大小
            String fileSize = document.get("fileSize");
            System.out.println(fileSize);
            // 文件路径
            String filePath = document.get("filePath");
            System.out.println(filePath);
            System.out.println("-----------------------------------------------------------------");
        }
        indexReader.close();
        return scoreDocs;
    }

我这么写的代码,假如搜索词是管理信息系统,输出结果会是带有管理、信息或者系统的文件,怎么把或者改成都要出现?

  • 写回答

1条回答 默认 最新

  • 落雅秋齐 2019-03-26 20:59
    关注

    IKAnalyzer 添加自定义词,
    添加自定义查询表达式,
    例如:用Term fileName:[信息 系统]

    Query query = parser.parse(searchkey);

    评论

报告相同问题?

悬赏问题

  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch