簡體   English   中英

如何在 Solr/Solarium 中創建單值字段?

[英]How do I create a single-value field in Solr/Solarium?

我已經為 PHP 完成了 Solr 和 Solarium 的香草安裝

日光浴室 5.x PHP 7.1 Solr 8.5.1

我可以創建和查詢文檔。 但是我創建的所有字段都返回為 arrays - “id”除外。 顯然,某處有一些模式指定 id 是一個單值字段。 如何創建自己的單值字段? 我創建的所有字段都是多值 arrays。

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

看來我應該能夠定義字段類型並指定它們是否是多值的,但我創建的所有字段都是多值 arrays 並且我似乎無法改變它。 日光浴室文檔有一個關於多值字段但沒有單值字段的部分。

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
名稱:數組
價格:數組

是的,我知道如何從數組中取出這些值,但我知道默認情況下必須有某種方法來獲取單值字段。

提前致謝。

我發現我可以通過在核心的 conf 目錄中手動編輯托管模式 (schema.xml) 來定義字段的 multiValued="false" 和許多其他詳細屬性。

但是它在這個文件的頂部說:

所以現在真正的問題是,如何編輯 SOLR 模式?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM