【问题标题】:filtering the boolean query results in lucene在 lucene 中过滤布尔查询结果
【发布时间】:2017-05-18 09:30:33
【问题描述】:

我的 solr json 响应如下,

{
     "stateOrProvinceId":"TN",
     "entityType":"hotelInfo",
     "chainCode":"SM",
     "marketerName":"InnLink",
     "propertyId":"4380",
     "marketerId":"INNLINK",
     "propertyStatus":"Active",
     "chainName":"Innlink",
     "propertyName":"Value Place Memphis NE",
     "countryCode":"US"},
{
     "entityType":"hotelInfo",
     "chainCode":"GT",
     "marketerName":"Golden Tulip",
     "propertyId":"69170",
     "marketerId":"GOLDENT",
     "propertyStatus":"Active",
     "chainName":"Golden Tulip Hotels",
     "propertyName":"Tulip Inn Sunny Hill",
     "countryCode":"RO"},
{
     "stateOrProvinceId":"TN",
     "entityType":"hotelInfo",
     "chainCode":"BW",
     "marketerName":"Best Western",
     "propertyId":"85336",
     "marketerId":"BESTWEST",
     "propertyStatus":"Active",
     "chainName":"Best Western Intl",
     "propertyName":"BEST WESTERN Brentwood",
     "countryCode":"US"},
{
     "entityType":"amenitiesInfo",
     "propertyId":"69170",
     "amenitiesInfoAttrId":"AC"},

我们正在使用以下布尔查询搜索特定的属性 ID,

BooleanQuery booleanQuery = new BooleanQuery(); 
booleanQuery.add(new TermQuery(new Term("propertyId", pid)), BooleanClause.Occur.SHOULD);

给出以下响应,

{
     "entityType":"hotelInfo",
     "chainCode":"GT",
     "marketerName":"Golden Tulip",
     "propertyId":"69170",
     "marketerId":"GOLDENT",
     "propertyStatus":"Active",
     "chainName":"Golden Tulip Hotels",
     "propertyName":"Tulip Inn Sunny Hill",
     "countryCode":"RO"},

{
     "entityType":"amenitiesInfo",
     "propertyId":"69170",
     "amenitiesInfoAttrId":"AC"},

现在我需要一个查询来获取只有hotelInfo 而不包含设施信息。

提前感谢您的帮助。 拉格万

【问题讨论】:

    标签: solr lucene booleanquery


    【解决方案1】:

    我不知道我是否做对了,据我了解,您希望根据两个条件构建查询:pidentityType,如果您想这样做,您应该在 entityType 上向您的 BooleanQuery 添加另一个 TermQuery,您应该尝试以下操作:

    BooleanQuery booleanQuery = new BooleanQuery(); 
    booleanQuery.add(new TermQuery(new Term("propertyId", pid)), BooleanClause.Occur.SHOULD);
    booleanQuery.add(new TermQuery(new Term("entityType", "hotelInfo")), BooleanClause.Occur.SHOULD);
    

    【讨论】:

    • 感谢 NAIT,第二部分无法从整个响应中检索所有 hotelInfo 字符串,我需要对上一个查询的结果进行此搜索
    • 我不明白@Raghavan,你能说清楚点吗?
    猜你喜欢
    • 1970-01-01
    • 2010-10-31
    • 1970-01-01
    • 2019-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-14
    相关资源
    最近更新 更多