我有基于URL,BODYTEXT,TITLE等的索引。我想基于URL搜索我的代码正在工作,但只给出了精确的URL匹配记录。例如 : 记录1: 网址:HTTP://example.com/example/index.php 内容:例子在lucene和bla bla中很好 主持人:example.com 标题:欢迎来到示例
记录2: 网址:http://example.com/ 内容:示例是最佳解决方案之一 主持人; example.com 标题:欢迎来到示例
它仅提供记录2,因为我的网址为http://example.com/所以如何通过网址http://example.com/获取记录1和记录2,因为http://example.com/example/index.php也是 http://example.com/的一部分。
我的搜索代码 - >
Term term = new Term("URL", siteUrl.toLowerCase());
Query query1 = new TermQuery(term);
BooleanQuery booleanQuery.add(query1,BooleanClause.Occur.MUST);
TopDocs hits = is.search(booleanQuery, 50000);
索引编码
private Document createLuceneDocument(HTMLDocument htmlDocument)
{
Document document = new Document();
document.add(new Field("URL", htmlDocument.getUrl().toLowerCase(), Field.Store.YES,Field.Index.ANALYZED,Field.TermVector.WITH_POSITIONS_OFFSETS));
return document;
}
答案 0 :(得分:0)
TermQuery仅进行完全匹配。这是最简单的搜索方式。还有另一种称为PrefixQuery的查询,它将匹配以您指定的值开头的字段。这就是你要找的东西吗?如果您想匹配URL的任何部分,那么您需要拆分URL并在单独的字段中索引组件,否则使用可以在索引(和搜索)过程中有效地执行此操作的分析器。