导航:首页 > 版本升级 > solr怎么创建索引文件

solr怎么创建索引文件

发布时间:2024-10-17 15:45:35

❶ solr 不设置commit within为什么建不了索引

三种solr提交索引的方式
1. commit
通过api直接commit,这样性能比较差,在我测试下,平均每条commit600ms
HttpSolrServer solrServer = new HttpSolrServer("h//localhost:8080/solr/dtrace");
SolrInputDocument doc1 = new SolrInputDocument();
doc1.addField("id", i);
solrServer.add(doc1);
solrServer.commit();

2. AutoCommit

❷ 如何将solrconfig.xml中row行设置最大

本节详细讲解solrconfig.xml
1.如果配置文件配置错误,是否提示。true要报错,false不报错。

<abortOnConfigurationError>${solr.abortOnConfigurationError:true}</abortOnConfigurationError>

2.solr版本

<信培luceneMatchVersion>LUCENE_31</luceneMatchVersion>

3. 索引文件目录,建索引的目录和查询的目录都是它。

<dataDir>${solr.data.dir:./solr/db/data}</dataDir>
4.一些基础配置
4.1多少个document进行合并

<mergeFactor>10</mergeFactor>
<!-- Sets the amount of RAM that may be used by Lucene indexing
for buffering added documents and deletions before they are

flushed to the Directory. -->
4.2 缓存大小

<ramBufferSizeMB>32</ramBufferSizeMB>
多少个文档自动合并

<mergeFactor>10</mergeFactor>

(回去了,下次再更新。。)
(接着上次的更新)

4.3.
设置域的最大长度

<maxFieldLength>10000</maxFieldLength>
设置写锁的延迟时间
<writeLockTimeout>1000</writeLockTimeout>
设置提交锁的延迟
<commitLockTimeout>10000</commitLockTimeout>
4.4
直接更新的方法:滑贺唯即调用solr默认的url访问。

<updateHandler class="solr.DirectUpdateHandler2">

自动提交的最大文档数,最大时间

<autoCommit>
<maxDocs>10000</maxDocs>
<maxTime>1000</maxTime>
</autoCommit>拍迹

4.5包含所有查询的参数设置 <query>
设置lru缓存

<filterCache class="solr.FastLRUCache"
size="16384"
initialSize="4096"
autowarmCount="4096"/>
设置查询结果缓存

<queryResultCache class="solr.LRUCache"
size="16384"
initialSize="4096"
autowarmCount="1024"/>
设置文档缓存
<documentCache class="solr.LRUCache"
size="16384"
initialSize="16384"/>
是否延迟加载索引域

<enableLazyFieldLoading>true</enableLazyFieldLoading>
设置查询的最大doc数

<queryResultMaxDocsCached>500</queryResultMaxDocsCached>
这个参数暂时未用

<maxWarmingSearchers>2</maxWarmingSearchers>

假如用dataimport这solr自带的导入数据命令时,的参数,即与数据库对应的文件的位置

<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
<str name="config">C:\solr-tomcat\solr\db\conf\db-data-config.xml</str>
</lst>
</requestHandler>

这个标签是用来控制主索引服务器,与从索引服务器分发索引快照的所有属性的

<requestHandler name="/replication" class="solr.ReplicationHandler" >
<lst name="master">
<str name="replicateAfter">commit</str>
<str name="replicateAfter">startup</str>
<str name="confFiles">schema.xml,stopwords.txt,elevate.xml</str>
<str name="commitReserveDuration">00:00:60</str>
<str name="httpBasicAuthUser">345</str>
<str name="httpBasicAuthPassword">345</str>
</lst>
</requestHandler>

这个标签和他的名字是一样的,表示用于集群的组件所有参数

<searchComponent name="clustering"
enable="${solr.clustering.enabled:false}"
class="solr.clustering.ClusteringComponent" >
<!-- Declare an engine -->
<lst name="engine">
<!-- The name, only one can be named "default" -->
<str name="name">default</str>
<!-- Class name of Carrot2 clustering algorithm.

Currently available algorithms are:

* org.carrot2.clustering.lingo.LingoClusteringAlgorithm
* org.carrot2.clustering.stc.STCClusteringAlgorithm

See http://project.carrot2.org/algorithms.html for the
algorithm's characteristics.
-->
<str name="carrot.algorithm">org.carrot2.clustering.lingo.LingoClusteringAlgorithm</str>
<!-- Overriding values for Carrot2 default algorithm attributes.

For a description of all available attributes, see:
http://download.carrot2.org/stable/manual/#chapter.components.
Use attribute key as name attribute of str elements
below. These can be further overridden for indivial
requests by specifying attribute key as request parameter
name and attribute value as parameter value.
-->
<str name="LingoClusteringAlgorithm.desiredClusterCountBase">20</str>

<!-- The language to assume for the documents.

For a list of allowed values, see:
http://download.carrot2.org/stable/manual/#section.attribute.lingo.MultilingualClustering.defaultLanguage
-->
<str name="MultilingualClustering.defaultLanguage">ENGLISH</str>
</lst>
<lst name="engine">
<str name="name">stc</str>
<str name="carrot.algorithm">org.carrot2.clustering.stc.STCClusteringAlgorithm</str>
</lst>
</searchComponent>

当发生集群命令时,对应的相应参数。表示是否开启集群等。

<requestHandler name="/clustering"
startup="lazy"
enable="${solr.clustering.enabled:false}"
class="solr.SearchHandler">
<lst name="defaults">
<bool name="clustering">true</bool>
<str name="clustering.engine">default</str>
<bool name="clustering.results">true</bool>
<!-- The title field -->
<str name="carrot.title">name</str>
<str name="carrot.url">id</str>
<!-- The field to cluster on -->
<str name="carrot.snippet">features</str>
<!-- proce summaries -->
<bool name="carrot.proceSummary">true</bool>
<!-- the maximum number of labels per cluster -->
<!--<int name="carrot.numDescriptions">5</int>-->
<!-- proce sub clusters -->
<bool name="carrot.outputSubClusters">false</bool>

<str name="defType">edismax</str>
<str name="qf">
text^0.5 features^1.0 name^1.2 sku^1.5 id^10.0 manu^1.1 cat^1.4
</str>
<str name="q.alt">*:*</str>
<str name="rows">10</str>
<str name="fl">*,score</str>
</lst>
<arr name="last-components">
<str>clustering</str>
</arr>
</requestHandler>

默认查询条件

<admin>
<defaultQuery>*:*</defaultQuery>

<!-- configure a healthcheck file for servers behind a
loadbalancer
-->
<!--
<healthcheck type="file">server-enabled</healthcheck>
-->
</admin>

❸ solr的索引数据可以存放到数据库吗

在solr与tomcat整合文章中,我用的索引库是,现在就以这个为例。
首先要准备jar包:solr-dataimporthandler-4.8.1.jar、solr-dataimporthandler-extras-4.8.1.jar和mysql-connector-java-5.0.7-bin.jar这三个包到solr的tomcat的webapps\solr\WEB-INF\lib下
在这个文件夹的conf下配置两个文件,添加一个文件。先配置solrconfig.xml。
在该文件下添加一个新节点。
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
<str name="config">data-config.xml</str>
</lst>
</requestHandler>
在solrconfig.xml的同目录下创建data-config.xml。
配置:
复制代码
<dataConfig>
<dataSource type="JdbcDataSource"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/courseman"
user="root"
password="mysql" />
<document>
<entity name="student"
query="SELECT * FROM student">
<field column="id" name="id" />
<field column="name" name="name" />
<field column="gender" name="gender" />
<field column="major" name="major" />
<field column="grade" name="grade" />
</entity>
</document>
</dataConfig>
复制代码
schemal.xml的配置
复制代码
<?xml version="1.0" ?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding right ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a of the License at

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<schema name="example core one" version="1.1">
<fieldtype name="string" class="solr.StrField" sortMissingLast="true" omitNorms="true"/>
<fieldType name="long" class="solr.TrieLongField" precisionStep="0" positionIncrementGap="0"/>
<fieldType name="int" class="solr.TrieIntField" precisionStep="0" positionIncrementGap="0"/>
<!-- general -->
<field name="id" type="int" indexed="true" stored="true" />
<field name="gender" type="string" indexed="true" stored="true" />
<field name="name" type="string" indexed="true" stored="true" />
<field name="major" type="string" indexed="true" stored="true" />
<field name="grade" type="string" indexed="true" stored="true" />
<field name="_version_" type="long" indexed="true" stored="true"/>
<!-- field to use to determine and enforce document uniqueness. -->
<uniqueKey>id</uniqueKey>
<!-- field for the QueryParser to use when an explicit fieldname is absent -->
<defaultSearchField>name</defaultSearchField>
<!-- SolrQueryParser configuration: defaultOperator="AND|OR" -->
<solrQueryParser defaultOperator="OR"/>
</schema>
复制代码
默认的文件不是这样的,稍微改动了一下。
field 的type类型是根据fieldtype 的name定义的。class是solr自定义的不能更改。
shcema.xml文件的field字段的属性介绍:
(1)name:字段名称
(2)type:字段类型(此处type不是java类型,而是下面定义的fieldType)
(3)indexed:是否索引看true--solr会对这个字段进行索引,只有经过索引的字段才能被搜索、排序等;false--不索引
(4)stored:是否存储看true--存储,当我们需要在页面显示此字段时,应设为true,否则false。
(5)required:是否必须看true--此字段为必需,如果此字段的内容为空,会报异常;false--不是必需
(6)multiValued:此字段是否可以保存多个值看
(7)omitNorms:是否对此字段进行解析看有时候我们想通过某个字段的完全匹配来查询信息,那么设置 indexed="true"、omitNorms="true"。
(8)default:设置默认值
有这样一个FieldType描述:
<fieldType name="text_general" positionIncrementGap="100">
<analyzer type="index">
<tokenizer/>
<filter ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />
<filter/>
</analyzer>
<analyzer type="query">
<tokenizer/>
<filter ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />
<filter synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
<filter/>
</analyzer>
</fieldType>
属性说明:
(1)name:类型名称,<field>中的type引用的就是这个name
(2)class:solr自定义的类型
(3)<analyzer type="index">定义建立索引时使用的分词器及过滤器
(4)<analyzer type="query">定义搜索时所使用的分词器及过滤器
(5)<tokenizer/>定义分词器
(6)<filter/>定义过滤器
uniqueKey属性
<uniqueKey>id</uniqueKey>
类似于数据表数据的id,solr索引库中最好定义一个用于标示document唯一性的字段,此字段主要用于删除document。
defaultSearchField属性
就是你在做query搜寻时若不指定特定栏位做检索时, Solr就会只查这个栏位.
<defaultSearchField>default</defaultSearchField>
Field属性
是用来复制你一个栏位里的值到另一栏位用. 如你可以将name里的东西到major里, 这样solr做检索时也会检索到name里的东西.
<Field source="name" dest="major"/>
现在可以将数据库的数据导入solr了。
点击Execute就可以了。

阅读全文

与solr怎么创建索引文件相关的资料

热点内容
萌动歌姬安卓停服 浏览:985
pe装机工具镜像文件路径怎么选 浏览:113
win10sd卡无法读取 浏览:211
苹果手机被偷了怎么才能找回来 浏览:643
linux扫描网段ip 浏览:733
新旧改造文件名 浏览:114
激光下料软件用的是NC文件 浏览:711
以什么年龄来学c编程 浏览:938
网络素鸡什么意思 浏览:492
赚微信红包的纸牌游戏 浏览:699
删除win10主板密钥 浏览:191
linux删除最近文件 浏览:762
js字符串转移字符串 浏览:191
怎么用循环把数据录入list 浏览:925
爱奇艺错误代码104解决 浏览:303
三菱编程用什么语言好 浏览:298
电子琴编程干什么的 浏览:989
xar有什么文件 浏览:485
sogou输入法官方下载linux 浏览:916
word文件如何转换成excel并保存 浏览:692

友情链接