Reputation: 155
I've done a vanilla install of Solr and Solarium for PHP
Solarium 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". obviously there is some schema somewhere that specifies that id is a single-value field. how can I create my own single-value fields? All fields I create are multi-value 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. the solarium documentation has a section on multi-value fields but not single-value 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
id : 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.
Upvotes: 0
Views: 452
Reputation: 155
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.
however it says at the top of this file:
So now the real question is, how do you edit the SOLR schema?
Upvotes: 0