Lucene.net - 如何查询包含数字部分的路径?
我创建了一个索引,用于索引网站不同部分中的事件项目。 这些项目在网站上的结构如下:
/Start/Section1/Events/2011/12/25/X-mas
/Start/Section2/Events/2012/01/01/New-years-day
这些路径存储在索引中的 path
字段中。
在起始页上,我需要对所有不同部分的事件进行概述。 当我位于某个部分时,我只需要放置在该部分下的事件。
我添加了这样的布尔查询:
QueryParser queryParser = new QueryParser("path", analyzer);
Query query = queryParser.Parse(startPath);
completeQuery.Add(query, BooleanClause.Occur.MUST);
“path”是通过自定义索引脚本添加的字段;
要检索起始页的项目,我将使用以下方式搜索索引:
string startPath = "/Start";
这通常会为我提供路径以“/Start”开头的所有项目
要检索第 1 节的项目,我将使用以下方式搜索索引:
string startPath = "/Start/Section1/Events";
这通常会为我提供路径以“/Start”开头的所有项目路径以“/Start/Section1/Events”开头
我已经为新闻项目实现了这个解决方案,并且效果很好。对于活动项目则不然。 当我搜索索引时,它没有返回任何结果。问题是最后三个文件夹名称是数字。 当我将文件夹(fe 2011,12,25)重命名为文本(2000,12,25)时,它确实返回了命中。
如何让索引返回结果并保持文件夹名称为数字?
I've created an index which indexes the event items in different sections of a website.
This items are on the website in a structure like this:
/Start/Section1/Events/2011/12/25/X-mas
/Start/Section2/Events/2012/01/01/New-years-day
These paths are stored in the field path
in the index.
On the start page I need an overview of the events from all the different sections.
When I'm in a section I only need the events placed under that section.
I add a booleanquery like this:
QueryParser queryParser = new QueryParser("path", analyzer);
Query query = queryParser.Parse(startPath);
completeQuery.Add(query, BooleanClause.Occur.MUST);
"path" is a field that is added through a custom index script;
To retreive the items for the start page I would search my index using:
string startPath = "/Start";
This normally gives me all item where the path starts with "/Start"
To retreive the items for section1 I would search my index using:
string startPath = "/Start/Section1/Events";
This normally gives me all item where the path starts with "/Start/Section1/Events"
I've implemented this solution for news items and that works fine. For event items it does not.
When I search my index it returns no hits. The problem is that the last three folder names are numeric.
When I rename the folders (f.e. 2011,12,25) to text (two-thousand,twelve,twenty-five) it DOES return hits.
How can I get my index to return results keeping my folder names numeric?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
CharTokenizer
作为您的路径,并让IsTokenChar(char c)
对于/
返回 false。这样您就可以确保路径的每个部分都是一个单独的
令牌
。Use a
CharTokenizer
for your path, and haveIsTokenChar(char c)
return false for the/
.This way you'll be sure each part of your path is an individual
Token
.