簡體   English   中英

如何使用日光浴室查詢創建String類型的Solr文檔

[英]How to create solr document with String type using solarium query

我通過php中的solarium插件創建solr文檔。

但是所有文檔都存儲了text_general數據類型( id字段除外)。 text_general是solr系統中的默認數據類型。

我的疑問是為什么id字段僅以存儲的字符串類型為默認值。

並且如果有可能的話,可以使用solarium插件添加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}]
  }}

這取決於在Solr安裝中架構中定義的字段類型。 它與您如何通過Solarium發送數據沒有任何關系。

在無模式模式下, id字段始終設置為字符串,因為不能對唯一字段進行標記化(可以,但是可以給出奇怪的,非顯而易見的錯誤)。

在您的情況下,我建議將price字段定義為整數/長字段(如果一直是整數),將name字段定義為字符串字段。 請注意, string字段只會在完全匹配時產生匹配,因此在您的情況下,您必須使用精確的大小寫搜索value124才能獲得匹配。

在顯式定義字段時,還可以調整字段的multiValued屬性。 這樣,您只將字符串返回到JSON結構中,而不是包含該字符串的數組。

暫無
暫無

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

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