Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/368.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java LUCENE中使用slop短语查询时面临的问题_Java_Lucene_Full Text Search_Phrase - Fatal编程技术网

Java LUCENE中使用slop短语查询时面临的问题

Java LUCENE中使用slop短语查询时面临的问题,java,lucene,full-text-search,phrase,Java,Lucene,Full Text Search,Phrase,我在短语查询方面遇到了一些问题,因此请编写一段小代码,以确切了解短语查询如何实际处理slop内容: 我有一个字符串“abc理工学院”,我索引了这个字符串的不同组合(更像一个木瓦),就像这样 Document doc = new Document(); ArrayList<String> sh = new ArrayList<String>(); sh.add("abc institute engineering technology"); sh.ad

我在短语查询方面遇到了一些问题,因此请编写一段小代码,以确切了解短语查询如何实际处理slop内容:

我有一个字符串“abc理工学院”,我索引了这个字符串的不同组合(更像一个木瓦),就像这样

Document doc = new Document();
ArrayList<String> sh = new ArrayList<String>(); 
     sh.add("abc institute engineering technology");
     sh.add("abc institute engineering");
     sh.add("abc institute");
     sh.add("abc");
     sh.add("institute engineering technology");
     sh.add("institute engineering");
     sh.add("institute");
     sh.add("engineering technology");
     sh.add("engineering");
     sh.add("technology");
  for(String s : sh){
        doc.add(new Field("insti_shingles", s.toLowerCase(), Field.Store.YES,  Field.Index.ANALYZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
  }
  writer.addDocument(doc);
现在当我搜索术语“abc技术学院”

现在,根据slop短语查询的文档,我应该得到一些结果,但得到的结果集是空的。但是,当我搜索与索引标记完全相同的术语时,就会得到结果

我认为当我们使用短语查询时,术语“abc学院技术”应该与标记“abc学院工程技术”匹配


我做错什么了吗?Help

您不需要特殊的标记器就可以将短语查询与slop一起使用-正如您所注意到的,它确实会导致这些查询失败


只需使用
StandardAnalyzer
进行标记化,无需进行定制的木瓦操作

我想出来了,在这里我在一个术语中搜索“abc研究所技术”,但我要做的是我需要将它们分解成不同的术语,然后像“abc”、“研究所”和“技术”这样搜索
engineering technology
abc
institute
abc institute engineering technology
technology
abc institute
abc institute engineering
institute engineering technology
engineering
institute engineering
IndexSearcher searcher = new IndexSearcher(dir);
BooleanQuery booleanQuery = new BooleanQuery();
PhraseQuery query = new PhraseQuery();
query.add(new Term("insti_shingles", "abc institute technology"));
query.setSlop(4);
booleanQuery.add(query, BooleanClause.Occur.SHOULD);
TopDocs hits = searcher.search(booleanQuery, 30);