我是否误解了Solr中的AND查询?

时间:2014-10-15 02:19:13

标签: php solr

我在solr文档中有两个字段,“title”和“subject”(两者都默认可用)

然后我在数据库中放置两行,然后搜索它们。

但AND查询title:"facebook" and subject:"java"会返回两行。

它应该只返回第二行,对吗?

<?php
   $solr = new SolrClient (array ('hostname' => '127.0.0.1'));

   /////// INSERT ////////
   if (0)
   {
      $data = array (
         array (
            'id'       => 100,
            'title'    => 'Google',
            'subject'  => 'Java Interface'
         ),
         array (
            'id'       => 101,
            'title'    => 'FaceBook',
            'subject'  => 'Not Java'
         )
      );

      foreach ($data as $input)
      {
         $doc = new SolrInputDocument();
         foreach ($input as $key => $value)
         {
            $doc->addField ($key, $value);
         }

         $solr->addDocument ($doc, false, 1000);
      }

      sleep (3);
   }

   /////// QUERY ////////
   $query = new SolrQuery();

   $query->setQuery('title:"facebook" and subject:"java"');
   $query->addField('id')->addField('title')->addField('subject');

   $resp  = $solr->query($query)->getResponse ();
   print_r ($resp->response->docs);
?>

1 个答案:

答案 0 :(得分:0)

没关系,AND关键字必须为大写。