【问题标题】:How to create solr document with String type using solarium query如何使用日光浴室查询创建字符串类型的 solr 文档
【发布时间】:2019-07-10 05:29:07
【问题描述】:

我通过 php 中的日光浴室插件创建 solr 文档。

但是除了id字段外,所有文档都存储text_general数据类型。 text_general 是 solr 系统的默认数据类型。

我的疑问是为什么id 字段默认只存储字符串类型。

如果有可能使用日光浴室插件添加string 类型的文档。

我的代码部分在这里,

        public function updateQuery() {
            $update = $this->client2->createUpdate();

            // create a new document for the data
            $doc1 = $update->createDocument();
            // $doc1->id = 123;
            $doc1->name = 'value123';
            $doc1->price = 364;

            // and a second one
            $doc2 = $update->createDocument();
            // $doc2->id = 124;
            $doc2->name = 'value124';
            $doc2->price = 340;

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

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

            echo '<b>Update query executed</b><br/>';
            echo 'Query status: ' . $result->getStatus(). '<br/>';
            echo 'Query time: ' . $result->getQueryTime();
        }

以上代码的结果文档在这里,

{
  "responseHeader":{
    "status":0,
    "QTime":2,
    "params":{
      "q":"*:*",
      "_":"1562736411330"}},
  "response":{"numFound":2,"start":0,"docs":[
      {
        "name":["value123"],
        "price":[364],
        "id":"873dfec0-4f9b-4d16-9579-a4d5be8fee85",
        "_version_":1638647891775979520},
      {
        "name":["value124"],
        "price":[340],
        "id":"7228e92d-5ee6-4a09-bf12-78e24bdfa52a",
        "_version_":1638647892102086656}]
  }}

【问题讨论】:

    标签: php solr solarium


    【解决方案1】:

    这取决于您的 Solr 安装的字段类型 defined in the schema。它与您通过 Solarium 发送数据的方式没有任何关系。

    在无模式模式下,id 字段始终设置为字符串,因为无法对唯一字段进行标记(嗯,可以,但它会给出奇怪的、不明显的错误)。

    在您的情况下,我建议将 price 字段定义为整数/长字段(如果一直是整数),将 name 字段定义为字符串字段。请注意,string 字段仅在完全匹配时生成匹配,因此在您的情况下,您必须搜索带有精确大小写的 value124 才能获得匹配。

    您还可以在明确定义字段时调整字段的multiValued 属性。这样您就只能在 JSON 结构中返回字符串,而不是包含该字符串的数组。

    【讨论】:

    • 是的。我已经知道如何手动更改架构。现在我的问题是How to change field type or set field type dynamically using solarium plugin
    • 你不能。请求support for the Schema API is still open 的问题。您可以自己手动提出 JSON 请求using the Schema API 或提交 PR 以在 Solarium 中实现它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-04
    • 1970-01-01
    • 1970-01-01
    • 2016-08-01
    • 2016-03-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多