返回具有值“v”的“x”字段的SOLR结果

时间:2016-09-28 10:50:13

标签: solr

我正在使用SOLR 4.9版本。以下是我的索引文档。



    {
       "id": "1",
       "index_id": "index",
       "tm_title":"Avenger"
       "category":"1"
       "type":"movie"
       "article_type":"Hollywood"
    },
    {
       "id": "2",
       "index_id": "index",
       "tm_title":"Avenger 2: Age of ultron"
       "category":"1",
       "type":"movie"
       "article_type":"Hollywood"
    },
    {
       "id": "3",
       "index_id": "index",
       "tm_title":"Spiderman"
       "category":"2"
       "type":"movie"
       "article_type":"Hollywood"
    },
    {
       "id": "4",
       "index_id": "index",
       "tm_title":"Emy Jackson"
       "type":"celebrity"
       "article_type":"Hollywood"
    },
    {
       "id": "5",
       "index_id": "index",
       "tm_title":"Jim Watson"
       "type":"celebrity"
       "article_type":"Hollywood"
    }


现在要求就像这样的电影和名人结果的组合。

  1. 查询1:如果搜索“好莱坞” “类别”:“2”并且还包括名人。然后结果将是 3,4,5 的ids。
  2. 查询1:如果搜索“好莱坞” “类别”:“1”,还包括名人。然后结果将是 1,2,4,5 的ids。
  3. 我搜索了很多,但没有找到解决方案。 我正在尝试以下查询。

    FOR Query 1:

    localhost:8983/solr/collection1/select?q=Hollywood&fq=if(exist(category),category:2,'');

    FOR Query 2:

    localhost:8983/solr/collection1/select?q=Hollywood&fq=if(exist(category),category:1,'');

1 个答案:

答案 0 :(得分:0)

使用AND运算符

 localhost:8983/solr/collection1/select?q=article_type:Hollywood AND category:2 AND type:celebrity

第二次查询

localhost:8983/solr/collection1/select?q=article_type:Hollywood AND category:1 AND type:celebrity