【问题标题】:Solr Query with 'in' and 'not in' for the same fieldSolr 查询同一字段的“in”和“not in”
【发布时间】:2014-09-24 19:17:09
【问题描述】:

我是 Solr 的新手,我正在尝试创建一个查询,该查询将返回在“成分”字段(制表符分隔的字符串)中具有一个或多个值的所有文档,但排除那些具有其他一些值的文档同一字段上的值。我们正在运行 Solr 4.9

这里是架构:

<fields>  
<field name="_version_" type="long" indexed="true" stored="true" multiValued="false"/>
<field name="uri" type="string" indexed="true" stored="true" required="true" multiValued="false" /> 
<field name="title"  type="text_general"    indexed="true"  stored="true" multiValued="false" />
<field name="text"  type="text_general"    indexed="true"  stored="true" multiValued="false" />
<field name="ingredient"  type="tab-delimited-string"    indexed="true"  stored="true" multiValued="false" />

这里是一个文档示例:

  {
    "text": "Preheat oven to 350 degrees F.\n\nPlace potatoes, heavy cream, egg, salt, parmesan and marjoram in a blender container.\n\nCover and blend at high speed for about 30 seconds.\n\nFill dough in a greased baking dish and bake uncovered for 25-30 minutes at 350 F.\n\nPlace remaining ingredients (without the mozzarella) in a blender, cover and blend at high speed for about 10 seconds.\n\nSpread sauce on potato dough, cover with mozzarella and some sprinkles of oil and bake again uncovered for 20-25 minutes at 350 F.",
    "ingredient": "1/2 cup parmesan cheese, grind\t1 lb potato, uncooked,skin removed,diced\t1/2 cup heavy cream\t1 egg\t1 teaspoon salt\t1/2 teaspoon marjoram\t2 cloves garlic, chopped\t1 1/3 cups Tomatoes, diced\tsalt\tpepper\tbasil\t1 cup mozzarella cheese, finely grated\tolive oil",
    "uri": "http://www.food.com/recipe/potato-pizza-58181",
    "title": "Potato Pizza",
    "_version_": 1477518762807656400
  },

在搜索和阅读了一些手册后,我想出了这个:

title:pizza AND ingredient:"olive oil"  AND -ingredient:("beer" "potatoes")

但它不起作用。我也试过下面的东西,但它也不起作用

title:pizza AND ingredient:"olive oil"  AND -ingredient:"beer " "potatoes"
title:pizza AND ingredient:"olive oil"  AND -ingredient:"beer" AND -ingredient:"potatoes"

我得到的结果是成分字段中有土豆或啤酒。有什么想法吗?我错过了什么吗?

谢谢!

【问题讨论】:

  • 试试:title:pizza AND ingredient:("olive oil" AND NOT (beer OR potatoes))
  • 刚刚试了一下,还是不行,谢谢你的努力。这可能与我不知道的某种类型的缓存有关吗?
  • ingredient是什么字段?您可以发布您的架构吗?
  • 使用架构更新问题
  • 我应该让成分字段多值吗?

标签: solr solr-query-syntax


【解决方案1】:

我想出了这个,我只需要在我的搜索词前/附加 *。

title:pizza AND ingredient:"olive oil"  AND -ingredient:(*beer* *potatoes*)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-17
    • 2013-05-23
    相关资源
    最近更新 更多