【问题标题】:How do I create a single-value field in Solr/Solarium?如何在 Solr/Solarium 中创建单值字段?
【发布时间】:2020-04-22 23:11:20
【问题描述】:

我已经为 PHP 完成了 Solr 和 Solarium 的香草安装

日光浴室 5.x PHP 7.1 Solr 8.5.1

我可以创建和查询文档。但我创建的所有字段都以数组形式返回——“id”除外。显然,某处有一些模式指定 id 是一个单值字段。如何创建自己的单值字段?我创建的所有字段都是多值数组。

多值字段功能很有用,但只有少数情况下我需要它。

似乎我应该能够定义字段类型并指定它们是否为多值,但我创建的所有字段都是多值数组,我似乎无法更改它。日光浴室文档有一个关于多值字段但没有单值字段的部分。

https://solarium.readthedocs.io/en/stable/documents/#multivalue-fields

我在日光浴室中没有看到任何用于定义文档及其字段类型的文档。我的安装可能有问题。

这是我的代码示例:

$client = new Solarium\Client($config);

// get an update query instance
$update = $client->createUpdate();

// create a new document for the data
$doc1 = $update->createDocument();
// add data to the document
$doc1->id       = 123; // single value by default
$doc1->name     = 'document name'; // always results in an array
$doc1->price    = 5; // always results in an array


// add the documents and a commit command to the update query
$update->addDocuments(array($doc1));
$update->addCommit();

// this executes the query and returns the result
$result = $client->update($update);

// then query the documents
$query = $client->createSelect();
$query->setQuery('*:*');
$resultSet = $client->select($query);

echo 'NumFound: '.$resultSet->getNumFound().'<br>';
foreach ($resultSet as $document) {
    foreach ($document as $field => $value) {
        // I can test to see if $value is an array but my point is that I don't want
        // to do so for every single field.  how can I define fields that are single-value by default?
        echo '<div'> . $field . ' : ' . $value . '</div>';
    }
}

这个输出:

找到的数量:1
编号:123
名称:数组
价格:数组

是的,我知道如何从数组中取出这些值,但我知道必须有某种方法可以默认获取单值字段。

提前致谢。

【问题讨论】:

    标签: php solr solarium


    【解决方案1】:

    我发现我可以通过在核心的 conf 目录中手动编辑托管模式 (schema.xml) 来定义字段的 multiValued="false" 和许多其他详细属性。

    但是它在这个文件的顶部说:

    所以现在真正的问题是,如何编辑 SOLR 架构?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-14
      • 1970-01-01
      相关资源
      最近更新 更多