2009-12-14 83 views
1

我能够通过solr DIH导入数据。保持索引索引中的关系数据库结构?

在我的数据库中,我有4个表:

threads: id, user_id, country_id 

tags: id 

thread_tag_map: thread_id, tag_id 

countries: id 

posts: id, thread_id 

我想Solr中的每个文件包括:

thread_id 
tag_id 
country_id 
post_id 

例如:

thread_id: 1 
tag_id: 23 
tag_id: 34 
country_id: 43 
post_id: 4 
post_id: 23 
post_id: 23 

我应该如何映射它?

我还没有能够为此配置data-config.xml。我没有成功地遵循DIH教程。

这里是我的schema.xml:

<schema name="example" version="1.2"> 
    <types> 
    <fieldType name="string" class="solr.StrField" sortMissingLast="true"/> 
    <fieldType name="int" class="solr.TrieIntField" precisionStep="0" positionIncrementGap="0"/> 
    <fieldType name="uuid" class="solr.UUIDField" indexed="true" /> 
    <fieldType name="text_rev" class="solr.TextField" positionIncrementGap="100"> 
     <analyzer type="index"> 
     <tokenizer class="solr.WhitespaceTokenizerFactory"/> 
     <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" /> 
     <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="1" catenateNumbers="1" catenateAll="0" splitOnCaseChange="0"/> 
     <filter class="solr.LowerCaseFilterFactory"/> 
     <filter class="solr.ReversedWildcardFilterFactory" withOriginal="true" 
      maxPosAsterisk="3" maxPosQuestion="2" maxFractionAsterisk="0.33"/> 
     </analyzer> 
     <analyzer type="query"> 
     <tokenizer class="solr.WhitespaceTokenizerFactory"/> 
     <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/> 
     <filter class="solr.StopFilterFactory" 
       ignoreCase="true" 
       words="stopwords.txt" 
       enablePositionIncrements="true" 
       /> 
     <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="0" catenateNumbers="0" catenateAll="0" splitOnCaseChange="0"/> 
     <filter class="solr.LowerCaseFilterFactory"/> 
     </analyzer> 
    </fieldType> 
</types> 


<fields> 
    <field name="id" type="uuid" indexed="true" stored="true" default="NEW"/> 
    <field name="threads.title" type="text_rev" indexed="true" stored="true"/> 
    <field name="posts.body" type="text_rev" indexed="true" stored="true"/> 
    <dynamicField name="*id" type="int" indexed="false" stored="true"/> 
</fields> 

<uniqueKey>id</uniqueKey> 

<defaultSearchField>posts.body</defaultSearchField> 

<solrQueryParser defaultOperator="OR"/> 
</schema> 
+0

还没有人已经做到这一点,可以给我一些帮助? – ajsie 2009-12-14 13:36:20

+0

请张贴您的schema.xml – 2009-12-14 18:28:16

回答

2

好像你只是想确定这些字段:

THREAD_ID

TAG_ID

COUNTRY_ID

POST_ID

作为schema.xml中索引的“字符串”字段。 post_id应该是多值的=“true”。有关格式指导的信息,请参阅默认的schema.xml文件。还是......

http://wiki.apache.org/solr/SchemaXml

这里唯一棘手的事情实际上是查询的数据库,而不是配置Solr的。只要写一个连接查询,你可以得到所有的ID,你需要和使用的Solr客户端库你的语言来构建一个简单的datastruction,如(JSON-Y):

[{"thread_id":"1", 
    "tag_id":"14", 
    "country_id":"2", 
    "post_id":["5", 
      "7", 
      "18" 
      ] 
},...and more...] 

由于Solr的不是RDBMS,您必须通过执行多个查询或使用子查询来伪造您的搜索。另一个选择可能是使用Solr通过全文搜索来检索您的主题或帖子,然后使用此处的ID来运行MySQL查询,以便为您提供所需的其他所有内容。