[英]How do I create a single-value field in Solr/Solarium?
I've done a vanilla install of Solr and Solarium for PHP我已经为 PHP 完成了 Solr 和 Solarium 的香草安装
Solarium 5.x PHP 7.1 Solr 8.5.1日光浴室 5.x PHP 7.1 Solr 8.5.1
I can create and query documents.我可以创建和查询文档。 But all fields I create are returned as arrays - except for "id".
但是我创建的所有字段都返回为 arrays - “id”除外。 obviously there is some schema somewhere that specifies that id is a single-value field.
显然,某处有一些模式指定 id 是一个单值字段。 how can I create my own single-value fields?
如何创建自己的单值字段? All fields I create are multi-value arrays.
我创建的所有字段都是多值 arrays。
The multi-value field feature is useful but there are only a few cases where I will need it.多值字段功能很有用,但只有少数情况下我需要它。
It seems I should be able to define the field types and specify whether they are multi-value or not but instead all fields I create are multi-value arrays and I can't appear to change that.看来我应该能够定义字段类型并指定它们是否是多值的,但我创建的所有字段都是多值 arrays 并且我似乎无法改变它。 the solarium documentation has a section on multi-value fields but not single-value fields.
日光浴室文档有一个关于多值字段但没有单值字段的部分。
https://solarium.readthedocs.io/en/stable/documents/#multivalue-fields https://solarium.readthedocs.io/en/stable/documents/#multivalue-fields
I don't see any documentation in solarium for defining the documents and their field types.我在日光浴室中没有看到任何用于定义文档及其字段类型的文档。 possibly something is wrong with my installation.
我的安装可能有问题。
here is my code example:这是我的代码示例:
$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>';
}
}
this outputs:这输出:
NumFound: 1发现数:1
id: 123编号:123
name: Array名称:数组
price: Array价格:数组
yes I know how to get those values out of the array but I know there must be some way to get single-value fields by default.是的,我知道如何从数组中取出这些值,但我知道默认情况下必须有某种方法来获取单值字段。
Thanks in advance.提前致谢。
I have discovered that I can define multiValued="false", and many other detailed properties of a field, by manually editing managed-schema (schema.xml) in the conf directory for the core.我发现我可以通过在核心的 conf 目录中手动编辑托管模式 (schema.xml) 来定义字段的 multiValued="false" 和许多其他详细属性。
however it says at the top of this file:但是它在这个文件的顶部说:
So now the real question is, how do you edit the SOLR schema?所以现在真正的问题是,如何编辑 SOLR 模式?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.