Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MongoDB集合的Solr索引_Mongodb_Solr_Indexing_Mongo Collection - Fatal编程技术网

MongoDB集合的Solr索引

MongoDB集合的Solr索引,mongodb,solr,indexing,mongo-collection,Mongodb,Solr,Indexing,Mongo Collection,假设我有一个代表一些朋友列表的测试应用程序。应用程序使用一个集合,其中所有文档的格式如下: _id : ObjectId("someString"), name : "George", description : "some text", age : 35, friends : { [ { name: "Peter", age: 30 town: { name_town: "Pari

假设我有一个代表一些朋友列表的测试应用程序。应用程序使用一个集合,其中所有文档的格式如下:

_id : ObjectId("someString"),
name : "George",
description : "some text",
age : 35,
friends : {
    [
        {
         name: "Peter",
         age: 30
         town: {
                  name_town: "Paris",
                  country: "France"
               }
        },
        {
         name: "Thomas",
         age: 25
         town: {
                  name_town: "Berlin",
                  country: "Germany"
               }
        }, ...                // more friends
    ]
}
...                          // more documents
如何在schema.xml中描述这样的集合?我需要提出一些方面的问题,比如:“给我乔治的朋友们居住的国家”。另一个用例可能是“返回朋友30岁的所有文档(人员)”等

我最初的想法是通过schema.xml定义将“friends”属性标记为文本字段:

<fieldType name="text_wslc" class="solr.TextField" positionIncrementGap="100">
....
<field name="friends" type="text_wslc" indexed="true" stored="true" />

....
并尝试在文本中搜索“年龄”和“30”等词,但这不是一个非常可靠的解决方案


请撇开逻辑上不完善的集合架构不谈。这只是我刚刚面临的类似问题的一个例子

任何帮助或想法都将受到高度赞赏

编辑: 示例“schema.xml”

<?xml version="1.0" encoding="UTF-8" ?>
<schema name="text-schema" version="1.5">
    <types>
        <fieldType name="string" class="solr.StrField" sortMissingLast="true" omitNorms="true"/>
        <fieldType name="long" class="solr.TrieLongField" precisionStep="0" omitNorms="true" positionIncrementGap="0" />
        <fieldType name="trInt" class="solr.TrieIntField" precisionStep="0" omitNorms="true" />
        <fieldType name="text_p" class="solr.TextField" positionIncrementGap="100">
            <analyzer type="index">
                <tokenizer class="solr.WhitespaceTokenizerFactory"/>
                <filter class="solr.TrimFilterFactory"/>
                <filter class="solr.WordDelimiterFilterFactory"/>
                <filter class="solr.LowerCaseFilterFactory"/>
            </analyzer>
            <analyzer type="query">
                <tokenizer class="solr.WhitespaceTokenizerFactory"/>
                <filter class="solr.TrimFilterFactory"/>
                <filter class="solr.WordDelimiterFilterFactory"/>
                <filter class="solr.LowerCaseFilterFactory"/>
            </analyzer>
        </fieldType>
    </types>

    <fields>
            <field name="_id" type="string" indexed="true" stored="true" required="true" />
            <field name="_version_" type="long" indexed="true" stored="true"/>
            <field name="_ts" type="long" indexed="true" stored="true"/>
            <field name="ns" type="string" indexed="true" stored="true"/>               
            <field name="description" type="text_p" indexed="true" stored="true" />
            <field name="name" type="text_p" indexed="true" stored="true" />
            <field name="age" type="trInt" indexed="true" stored="true" />  
            <field name="friends" type="text_p" indexed="true" stored="true" />         <!-- Here is the problem - when the type is text_p, all fields are considered as a text; optimal solution would be something like "collection" tag to mark name_town and town as descendant of the field 'friends' but unfortunately, this is not how the solr works-->

            <field name="town" type="text_p" indexed="true" stored="true"/> 
            <field name="name_town" type="string" indexed="true" stored="true"/>    
            <field name="town" type="string" indexed="true" stored="true"/> 
    </fields>

    <uniqueKey>_id</uniqueKey>

_身份证

由于Solr是以文档为中心的,因此您需要尽可能地将其扁平化。根据您给出的示例,我将创建一个schema.xml,如下所示


. 您需要在solrconfig.xml中对此进行配置


相应的join查询如下所示:
q={!join from=id to=friends}age:[30 to*]

这解释如下

  • 使用
    年龄:[30至*]
    搜索所有30岁或以上的人
  • 然后你拿着他们的身份证,以所有其他人的朋友身份加入
  • 这将返回其friends属性中ID与初始查询匹配的所有人员
由于我没有忘记这一点,您可以看看我在github上的solrsample项目。我在这里添加了一个测试用例,用于处理这个问题:


Cheffe,谢谢您准确回答了问题。但也许我没有真正强调模式不应该被改变。让我们假设该模式已声明。您能否找到任何可能的解决方案来访问指定的数据?user1949763,在这种情况下,我需要更多的schema.xml。充其量是整个
元素,包括您的
类型。但是定义相当模糊,因为我无法克服限制……好吧,如果您想坚持您的模式想法,我看不到满足您需求的解决方案。您将需要连接功能,因为您希望执行类似嵌套实体的操作。没有其他可靠的方法可以在不遇到更新地狱的情况下查询类似的内容。