Solr新增文件到索引

2021-06-10 02:31:09 字數 1504 閱讀 2208

solr新增文件非常方便,不用像lucene那樣乙個乙個新增field,省去了很多的麻煩下面看操作

方法一:

note:id為唯一,不可重複,如果重複,solr會自動將索引中id相同的元素更新為現在的屬性

域的名稱可以在schema.xml的field中設定,預設的有很多field,我們也可以使用預設的

<

field

name

="news_title"

type

="textcomplex"

indexed

="true"

stored

="true"

/>

<

field

name

="news_content"

type

="textcomplex"

indexed

="true"

sotred

="true"

/>

方法2:直接新增物件

2.1 定義物件

package com.solr.entity;

import org.apache.solr.client.solrj.beans.field;

public class news

public news(string id, string title, string content)

public string getid()

@field

public void setid(string id)

public string gettitle()

@field("news_title")

public void settitle(string title)

public string getcontent()

@field("news_content")

public void setcontent(string content)

} 2.2 新增物件到索引

@test

public void test2() catch (solrserverexception e) catch (ioexception e)

}note:如果物件的某個域裡面的屬性為陣列,我們需要在schema.xml的field中設定 multivalued="true"

solr文件索引最佳實踐

others solr solr的文件生成後,需要將其提交到solr集群,提交的方法有以下三種 每生成乙個文件就直接提交至solr cloudsolrclient client new cloudsolrclient solr zk solrinputdocument doc2 new solrin...

Solr 新增 更新 刪除索引

索引中無則新增,有則更新 1.在doc標籤和field標籤中增加權重 boost 增加權重後,可以在搜尋的時候做權重過濾。05991 angrybird 2.field標籤 update add set inc 在4.0之後的版本可以自動對field做增加和刪除了。增加字段例子 05991 angr...

Solr配置從Mysql匯入資料到索引庫

1.在solr的解壓縮檔案中solr 4.10.4 dist下面,找到solr dataimporthandler 4.10.4.jar與 還有mysql的驅動的jar放在solrhome下的collection1下的lib中,沒有lib資料夾可以新建 例如我的home在 g solr servic...