首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Solr/Solarium中创建单值字段?

如何在Solr/Solarium中创建单值字段?
EN

Stack Overflow用户
提问于 2020-04-23 07:11:21
回答 1查看 213关注 0票数 0

我已经为PHP安装了Solr和Solarium

Solaria5.x PHP 7.1Solr 8.5.1

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

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

看起来我应该能够定义字段类型并指定它们是否是多值的,但是我创建的所有字段都是多值数组,我似乎不能改变这一点。solarium文档中有一个关于多值字段的部分,但没有关于单值字段的部分。

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

我在solarium中没有看到任何定义文档及其字段类型的文档。可能是我的安装有问题。

下面是我的代码示例:

代码语言:javascript
复制
$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>';
    }
}

这将输出以下内容:

NumFound: 1

id : 123

名称:数组

价格:数组

是的,我知道如何从数组中获取这些值,但我知道在默认情况下,一定有某种方法可以获取单值字段。

提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2020-04-23 07:34:32

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

然而,它在此文件的顶部写道:

因此,现在真正的问题是,如何编辑SOLR模式?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61376642

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档