`
zy19982004
  • 浏览: 663968 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
博客专栏
F6f66edc-1c1a-3859-b76b-a22e740b7aa7
Hadoop学习
浏览量:252466
社区版块
存档分类
最新评论

solr总结 第四部分:solr配置文件详解

    博客分类:
  • Solr
阅读更多

 

 

关于solr配置文文件我所理解的,大部分都是可以在网上查到的。所以主要列举下一些网上大家谈的很少的知识。

1.solrconfig.xml

  • 配置文件(略)
  • 这个文件,我没做很深入的研究。只有一点说明,solr1.3和solr1.4是有区别的
  • solr1.3里面,需要指定solr index date的位置
      <!-- Used to specify an alternate directory to hold all index data
           other than the default ./data under the Solr home.
           If replication is in use, this should match the replication configuration. -->
           <dataDir>${solr.data.dir:./solr/db/data}</dataDir>
  • solr1.4里面,自动把生成index目录:data(和conf同级)-index (索引文件)
    <!-- The directory where your SpellChecker Index should live.   -->
         <!-- May be absolute, or relative to the Solr "dataDir" directory. -->
         <!-- If this option is not specified, a RAM directory will be used -->
         <str name="spellcheckerIndexDir">spell</str>
     

2.db-data-config.xml

  • 配置文件(人所在的公司为例) 
    <!--dataConfig is designed  for member search, by using the table member,organization-->
    <dataConfig>
    	<dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver"
    		url="jdbc:mysql://../test" user=".."
    		password=".." />
    	<document name="private-beta">
    			<!--  field for news search, from member table-->
    			<entity name="member" pk="memid"
    			query="select distinct * from member"
    			deltaQuery="select memid from member 
                            where mem_date_updated > '${dataimporter.last_index_time}'">
    				<field column="memid" name="memid" />
    				<field column="name" name="name" />
    				<field column="mem_first_name" name="mem_first_name" />
    				<field column="mem_last_name" name="mem_last_name" />
    				<field column="mem_org_title" name="mem_org_title" />
    				<field column="mem_org_dept" name="mem_org_dept" />
    				<field column="mem_job_func" name="mem_job_func" />
    				<field column="mem_job_level" name="mem_job_level" />
    				<field column="mem_add_city" name="mem_add_city" />
    				<field column="mem_add_state_code" name="mem_add_state_code" />
    				<field column="mem_add_country_code" name="mem_add_country_code" />
    				<field column="mem_date_created" name="mem_date_created" />
    				<field column="mem_email" name="mem_email" />
    				<field column="mem_orgid" name="mem_orgid" />
    				<field column="mem_add_address" name="mem_add_address" />
    
    				<!--  field for member search, from organization table-->
    				<entity name="organization" pk="orgid" 
    				query="select * from organization where orgid='${member.mem_orgid}'" >
    					<field column="orgid" name="orgid" />		
    					<field column="org_name" name="org_name" />					
    					<field column="org_website" name="org_website" />	
    					<field column="org_website_protocol" name="org_website_protocol" />	
    					<field column="org_subcat_id" name="org_subcat_id" />	
    					<field column="org_subcat_id2" name="org_subcat_id2" />	
    					<field column="org_subcat_id3" name="org_subcat_id3" />	
    					<field column="org_subcat_id4" name="org_subcat_id4" />	
    					<field column="org_subcat_id5" name="org_subcat_id5" />							
    				</entity>
    
    		</entity>
    
    	</document>
    </dataConfig>
     
  • delta-import:通过deltaQuery,查到数据库中未被索引记录的ids(id1,id2...),然后执行deltaImportQuery,如果没用deltaImportQuery,就通过Query去组装deltaImportQuery。对于上面的配置文件,就应该组装成这样的query:select  distinct * from member where memid = id1,把这条记录导入索引库里面,然后再导id2。曾以为solr应该组装select .. from .. where .. and memid in (id1, id2)这样的query,可好像它并没这样做。
  • 只有deltaQuery里面select的field和PK一样时(都为memid),才会组装成select  distinct * from member where memid = id1。否则组装成select  distinct * from member and memid = id1,增量导入时会报错。突然明白了
    solr wiki 写道
    pk : The primary key for the entity. It is optional and only needed when using delta-imports. It has no relation to the uniqueKey defined in schema.xml but they both can be the same.
  • left join:涉及到多个表之间有外键连接时,solr源码里面给我们展示的,是<entity></entity>里面,去引用上一层<entity></entity>对应表的外键:orgid='${member.mem_orgid}'。那么,我们何不直接将配置文件中的Query改为:select  distinct * from member left join organization o on orgid = mem_orgid。这样就可以不用分层,把所有<field></field>定义到一块了。这样是可行的,只是效率还是个未知数。不过推荐分层的<entity></entity>,逻辑清楚。

3.schema.xml

  • 配置文件
        <!-- This is an example oTokenFilterFactoriesf using the KeywordTokenizer along
             With various  to produce a sortable field
             that does not include some properties of the source text
          -->
        <fieldType name="alphaOnlySort" class="solr.TextField" sortMissingLast="true" omitNorms="true">
          <analyzer>
            <!-- KeywordTokenizer does no actual tokenizing, so the entire
                 input string is preserved as a single token
              -->
            <tokenizer class="solr.KeywordTokenizerFactory"/>
            <!-- The LowerCase TokenFilter does what you expect, which can be
                 when you want your sorting to be case insensitive
              -->
            <filter class="solr.LowerCaseFilterFactory" />
            <!-- The TrimFilter removes any leading or trailing whitespace -->
            <filter class="solr.TrimFilterFactory" />
            <!-- The PatternReplaceFilter gives you the flexibility to use
                 Java Regular expression to replace any sequence of characters
                 matching a pattern with an arbitrary replacement string, 
                 which may include back refrences to portions of the orriginal
                 string matched by the pattern.
                 
                 See the Java Regular Expression documentation for more
                 infomation on pattern and replacement string syntax.
                 
                 http://java.sun.com/j2se/1.5.0/docs/api/java/util/regex/package-summary.html
              -->
            <filter class="solr.PatternReplaceFilterFactory"
                    pattern="([^a-z])" replacement="" replace="all"
            />
          </analyzer>
        </fieldType>
    
     <fields>
     
    		<!--  field for member search,all field  is in one-to-one correspondence with the field in db-data-config.xml -->
    		<!--  field from member table-->
    		<field name="memid" type="long" indexed="true" stored="true"
    		multiValued="false" required="true"/>
    		...
    		<field name="mem_orgid" type="long" indexed="true" stored="true"
    			multiValued="false"/>
    
    
    		<!--  field from organization table-->
    		<field name="orgid" type="long" indexed="true" stored="true"
    			multiValued="false"/>
    		<field name="org_name" type="alphaOnlySort" indexed="true" stored="true"
    			multiValued="false" />
    		...
    
    
    
  • alphaOnlySort:对于org_name这样的field,一般我们会将其定义为text类型,如果同时我们需要按org_name排序,那怎么办?显然,text是不能用了。刚好,alphaOnlySort,可以为我们解决这个问题,你应该可以理解上面那段配置。
  • 特别要说明的是<filter class="solr.PatternReplaceFilterFactory"
                    pattern="([^a-z])" replacement="" replace="all"
            />,排除了所有非字母的文本。举个例子,按上面的配置,你查找“123”这样的公司名,它会匹配到任何公司名为数字的公司。所以我把这段给注释掉了。
  • 如果选择了alphaOnlySort,输入ibm,将无法匹配到ibm.com,因为alphaOnlySort类型的ibm.com并不会被分割(<filter class="solr.WordDelimiterFilterFactory...")。

4.stopwords.txt

  • 配置文件(略)
  • stopwords,只针对定义了texttype的field。
  • 里面定义的一些停用词我们需要注意了,比喻“OR”,你能把它停掉吗。不一定,美国就有Oregon洲缩写为OR,如果你把org_state_code的fieldtype设置为text的话,你搜索OR,传到solr server的url:http://localhost:8888/solr/../select?q=*:*?&fq=org_state_code:OR就会变成http://localhost:8888/solr/../select?q=*:*?&fq=org_state_code:,报错!
  • 所以,要么你将org_state_code定义为其他fieldtype,要么你在stopwords里面除掉这些特殊的words。

 

 

 

 

 

 

 

分享到:
评论
4 楼 zhb01 2013-04-26  
<dataConfig> 
  <dataSource type="JdbcDataSource" 
   driver="oracle.jdbc.driver.OracleDriver" 
   url="jdbc:oracle:thin:@//192.168.1.143:1521/orcl" 
   user="zw" 
   password="zw" 
   /> 
<document name="documents1" > 
        <entity name="t_product"  transformer="ClobTransformer" pk="product_id"
          query="select t.product_id as id,name,productnum,market_price,mall_price,m.pic_url,desc_value from t_product t,t_product_imgs m,t_product_desc d where is_delete='N' and status='3'
and t.product_id=m.product_id and m.is_main='Y' and t.product_id=d.product_id" 
          deltaImportQuery="select product_id,name,productnum,market_price,mall_price,cost from t_product where ID='${dataimporter.delta.id}'" 
          deltaQuery="select product_id  from t_product where CREATE_TIME > '${dataimporter.last_index_time}'" 
          deletedPkQuery="select product_id  from t_product where id=0"> 
            <field column="product_id" name="id" /> 
            <field column="name" name="name" /> 
            <field column="productnum" name="productnum" /> 
            <field column="market_price" name="market_price" /> 
            <field column="mall_price" name="mall_price" />
<field column="pic_url" name="pic_url" />
<field column="desc_value" name="desc_value" clob="true"/>
<entity name="t_pro_pra_val"
query="select listagg(ppvalue_value,',') within GROUP (order by t.ppvalue_id)  as proval from   t_pro_pra_val t  where  product_id='${t_product.product_id}'">
<field column="proval" name="proval" />
</entity> 
        </entity> 
  </document> 
</dataConfig>


请教个问题,我进行多表关联时,子表proval存在数据,为什么索引中没有数据
3 楼 xielibohoudi 2013-04-26  
zy19982004 写道
xielibohoudi 写道
你好像请教下上文 db-data-config.xml中 “mem_date_updated” 代表什么意思啊

member    表里的一个字段
代表member最后的更新时间


哦哦  谢谢了
2 楼 zy19982004 2013-04-01  
xielibohoudi 写道
你好像请教下上文 db-data-config.xml中 “mem_date_updated” 代表什么意思啊

member    表里的一个字段
代表member最后的更新时间
1 楼 xielibohoudi 2013-03-28  
你好像请教下上文 db-data-config.xml中 “mem_date_updated” 代表什么意思啊

相关推荐

    solr搜索服务器安装配置

    ### Solr搜索服务器安装配置详解 #### 一、Solr简介 Apache Solr是一款开源的高性能全文搜索引擎,基于Lucene库构建。它采用Java开发,提供了丰富的API接口,支持多种编程语言,使得开发者能够轻松地集成搜索功能到...

    solr 安装与配置

    - SolrHome 是 Solr 服务器所有配置文件的存放位置,创建目录 `/usr/local/solr/solrhome`。 - 使用 `cp -rsolr /usr/local/solr/solrhome` 命令将示例配置复制过去。 - 修改 Solr 工程的 `web.xml` 文件,指定 ...

    solr开发详解

    - **第四步**:添加 Solr 扩展服务包至相应的 Tomcat lib 目录。 - **第五步**:添加 log4j.properties 文件到 Solr 的 lib 目录。 - **第六步**:在 web.xml 文件中指定 solrhome 的路径。 - **SolrHome 和 ...

    solr3.5配置及应用

    为了确保数据的唯一性,通常会为每个文档设置一个唯一的标识符,例如默认情况下使用`id`字段作为唯一键,在Schema配置文件中通过`&lt;uniqueKey&gt;id&lt;/uniqueKey&gt;`来进行定义。 - **核心特性**:Solr具备高效的缓存机制、...

    图解Solr5.3.1与MySQL配置【原创】

    1. **Solr样例文件**:在下载的Solr包的`example`目录中,可以找到许多样例配置文件,这些文件可以帮助开发者更好地理解Solr的各种配置选项。 2. **通过Solr控制台创建核**:除了手动创建核外,还可以通过Solr的管理...

    图解Solr6.6.0安装与MySQL配置

    - 在`solr\WEB-INF\web.xml`文件中配置Solr的HOME目录,确保Solr知道去哪里查找其配置文件和数据。 **2.7 测试Solr** - **2.7.1 JDK版本要求**: Solr 6.x版本要求JDK 8或以上版本。 - **2.7.2 启动Tomcat**: 使用...

    solr6.0 tomcat搭建

    1. **复制日志配置文件**: 将 `E:\solr-6.6.2/server/resources/log4j.properties` 复制到 `Tomcat/solr/WEB-INF/classes` 文件夹下。 2. **修改 web.xml 文件**: - 在 `Tomcat/solr` 目录下找到 `web.xml` 文件,...

    solr学习资料

    4. **整合配置**:创建 Solr home 目录,配置 SolrCore,将 Solr 解压后的 war 文件放入 Tomcat 的 webapps 目录下,启动 Tomcat 即可运行 Solr。 总结来说,Solr 是一个强大的全文搜索解决方案,尤其适合大型网站...

    solr教材-PDF版

    - **3.3.2 定制索引服务**:根据业务模型调整Solr配置,优化索引过程。 - **3.3.3 定制搜索服务**:针对特定需求配置搜索参数,提升搜索体验。 **3.4 搜索引擎配置** - **3.4.1 SolrSchema设计(如何定制索引的结构...

    solr学习入门教程

    典型的Solr主目录包括bin(用于放置集群复制脚本)、conf(配置文件)、data(索引文件)、lib(依赖库)、schema.xml(模式定义文件)等关键部分。理解并熟悉这些目录的用途对于正确配置和运行Solr至关重要。 ####...

    Solr in action

    - **配置文件解读**:详细解释Solr配置文件的作用及各项参数的意义。 - **环境配置**:根据不同的部署环境(如开发、测试、生产),介绍如何调整Solr的配置。 - **性能调优**:针对Solr在实际应用过程中可能遇到的...

    solr培训.ppt

    ### Solr培训知识点详解 #### 一、Lucene与Solr概述 - **Lucene**: - Lucene是Apache软件基金会的一个子项目,它是一个开放源代码的全文检索引擎工具包,主要用于软件开发人员方便地实现全文检索功能或基于此...

    Linux安装单机版Solr.docx

    - 修改`/usr/local/solr/tomcat-solr/webapps/solr/WEB-INF/web.xml`文件,删除注释,并修改第43行指定`solrhome`地址为`/usr/local/solr/solrhome`。 5. **启动Solr**: - 使用`/usr/local/solr/tomcat-solr/bin...

    tomcart 部署 solr5.0的部署方法

    - 修改新增实例的配置文件`E:\Solr\solr-5.5.0\solr-5.5.0\server\solr\case\conf\solr-data-config.xml`。 ```xml url="jdbc:sqlserver://服务器地址;DatabaseName=数据库名称" user="用户名" password=...

    solr全文检索

    `solr/home`目录包含`conf`和`data`子目录,`conf`下有`schema.xml`和`solrconfig.xml`等配置文件,`data`则存储索引数据。 **三、Schema配置** 1. **`schema.xml`**:定义字段类型(types)、字段(fields)以及...

    ik-analyzer-solr5-5.x

    标题“ik-analyzer-solr5-5.x”指的是针对Solr搜索引擎的...在Solr 5.x及更高版本中,正确引入`ik-analyzer-solr5-5.x.jar`并配置相应的字典和配置文件,能确保IK分词器正常运行,从而提高中文文本的检索效率和准确性。

    详解java整合solr5.0之solrj的使用

    msgs.add(new Message("4", "第四个测试solr测试文件", new String[]{"中华人民共和国万岁", "中华上下五千年那年"})); msgs.add(new Message("5", "第5个好朋友是什么意思呢?", new String[]{"上海是个好地方", ...

Global site tag (gtag.js) - Google Analytics