组织 Lunene 目录
我有一组记录。每条记录可以有多个技能和一个状态。
因此,您可能有技能 a、b 和 c 的记录以及维多利亚州的记录。
我需要能够在目录中搜索包含维多利亚技能 a 或维多利亚技能 a 和 c 的任何记录。
我无法创建一个有效的目录来以我想要的方式进行搜索。
首先,我创建了一个目录,其中包含 skills: abc state:vic
然后我尝试了 skills: a,b,c state:vic
但搜索这些并没有给我正确的结果。事实上,当我有疑问时;
skills:a,b AND state:vic,
skills: a OR b AND state:vic,
skills: a OR skills:b AND state:vic
以上所有内容都返回一组 skills: a AND state:vic
记录。
有什么想法吗?
编辑
自从发布此内容以来,我已经让它发挥作用,但不确定这是否是正确的方法。
我将所有技能组合到一个领域中,并用空间将它们分开。技能采用 GUID 格式。
然后在我的搜索方法中我这样做;
queryString = "skills:(skill1 OR skill2 OR skill3) AND state:Vic";
Query query = parser.Parse(queryString);
这工作得很好,而且非常快,但是创建一个 queryString 真的是解决这个问题的方法还是有更好的方法?
I have a set of records. Each record can have multiple skills and a single state.
So you might have a record of skills a, b and c and a state of Victoria.
I need to be able to search the directory for any records that have say skill a in Victoria or skill a and c in Victoria.
I'm having trouble creating an effective directory that will allow me to search in the manner I want.
At first i created a directory with skills: a b c state:vic
then i tried skills: a,b,c state:vic
But searching these is not giving me the correct results. In fact when i have a query;
skills:a,b AND state:vic,
skills: a OR b AND state:vic,
skills: a OR skills:b AND state:vic
the above all return a set of records for skills: a AND state:vic
.
Any thought?
EDIT
Since posting this I have gotten it to work but am unsure if this is the right approach.
I have combined all the skills into a single field and space seperated them. The skills are in GUID format.
Then in my search method I do this;
queryString = "skills:(skill1 OR skill2 OR skill3) AND state:Vic";
Query query = parser.Parse(queryString);
This works fine and it's very quick but is creating a queryString really the way to go with this or is there a better way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 BooleanQuery : http://geekswithblogs.net /rgupta/archive/2009/01/07/lucene-multifield-searches.aspx
You can use a BooleanQuery : http://geekswithblogs.net/rgupta/archive/2009/01/07/lucene-multifield-searches.aspx
您可以直接构建
BooleanQuery
,而不是通过QueryParser
。这要求您在向用户呈现搜索界面时区分技能和状态输入字段。在搜索技能时允许自由文本条目仍然需要调用
QueryParser.Parse
。You could build your
BooleanQuery
directly, instead of going via aQueryParser
. This requires that you differentate skills- and state input fields when presenting your search interface to your users.Allowing freetext entries when searching for skills still require a call to
QueryParser.Parse
.