Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.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
带通配符的字符串数组字段中的RavenDb方面搜索_Ravendb_Faceted Search - Fatal编程技术网

带通配符的字符串数组字段中的RavenDb方面搜索

带通配符的字符串数组字段中的RavenDb方面搜索,ravendb,faceted-search,Ravendb,Faceted Search,是否可以在string[]字段中进行RavenDb分面搜索,在该字段中,我只想显示以特定字符串开始的值的分面(计数),而不是范围 我将尝试用一个简单的例子更好地解释我自己,想象一下有一个包含以下条目的索引 ID | Values ------------------------- 1 | CatPersian, CatNormal, DogLabrador 2 | CatPersian, Camel, DogPoodle 3 | CatNormal, CatBengali, DogNorm

是否可以在
string[]
字段中进行RavenDb分面搜索,在该字段中,我只想显示以特定字符串开始的值的分面(计数),而不是范围

我将尝试用一个简单的例子更好地解释我自己,想象一下有一个包含以下条目的索引

ID | Values
-------------------------
1  | CatPersian, CatNormal, DogLabrador
2  | CatPersian, Camel, DogPoodle
3  | CatNormal, CatBengali, DogNormal
4  | DogNormal
我将对上述文档执行查询,Facet搜索将在“Values”字段中包含一个“Cat*”范围。这可能吗?然后,我会根据猫的不同值得到一个结果,比如:

  • 波斯猫[2]
  • CatNormal[2]
  • 孟加拉猫[1]

  • 是的,你可以这样做。为数组编制索引,然后正常使用facet。 让我们看看完整的例子。您拥有以下文件:

    {
        "Name": "John",
        "FavoriteAnimals": [
            "Cats",
            "Dogs",
            "Snails"
        ],
        "@metadata": {
            "@collection": "Kids"
        }
    }
    
    {
        "Name": "Jane",
        "FavoriteAnimals": [
            "Cats",
            "Rabits"
        ],
        "@metadata": {
            "@collection": "Kids"
        }
    }
    
    现在,创建以下索引:

    from k in docs.Kids
    from animal in k.FavoriteAnimals
    select new { Animal = animal }
    
    并运行此查询:

    from index 'YourIndex'
    where startsWith(Animal , 'ca')
    select facet('Animal')
    
    from index 'YourIndex'
    where startsWith(FavoriteAnimals , 'ca')
    select facet('FavoriteAnimals')
    
    结果将是:

    {
        "Name": "Animal",
        "Values": [
            {
                "Count": 2,
                "Range": "cats"
            }
        ]
    }
    
    或者,您可以使用此索引:

    from k in docs.Kids
    select new { k.FavoriteAnimals }
    
    并运行此查询:

    from index 'YourIndex'
    where startsWith(Animal , 'ca')
    select facet('Animal')
    
    from index 'YourIndex'
    where startsWith(FavoriteAnimals , 'ca')
    select facet('FavoriteAnimals')
    
    这里的区别是,您将获得具有匹配项的文档的所有匹配项。 所以在这种情况下

    {
        "Name": "Animal",
        "Values": [
            {
                "Count": 2,
                "Range": "cats"
            },
            {
                "Count": 1,
                "Range": "dogs"// also, snails, rabbits
            }
        ]
    }
    

    你能举个例子吗,或者有相关的文档吗?据我所知,对于方面范围搜索,您应该为介于1-5、6-10之间的值提供一个“范围”。然而,在这种情况下,我需要更类似于通配符搜索的东西,其中facet范围将只是“Cat*”。然后,我需要每个不同项匹配该通配符的结果,而不是作为一个组告诉我整个“Cat*”组的计数。