简体   繁体   English

在逗号分隔列表中搜索字符串

[英]Search string in comma separated list

I'm trying to search a table of recipes that DON'T include any of the search terms in it's ingredients.我正在尝试搜索不包含任何搜索词的食谱表。 The ingredients of each recipe are stored in one field, separated by commas.每个配方的成分存储在一个字段中,以逗号分隔。

I've tried using WHERE NOT MATCH...AGAINST but that doesn't work in cases like when I search for Peas.我试过使用 WHERE NOT MATCH...AGAINST 但这在我搜索豌豆时不起作用。 It will return results with pea protein in them.它将返回带有豌豆蛋白的结果。 I need to not have that.我不需要那个。 This is also a problem with pluralization.这也是多元化的问题。

I tried using NOT REGEXP but I'm not too familiar with regular expressions and all the Googling I've done for the last two days hasn't produced a result.我尝试使用 NOT REGEXP,但我对正则表达式不太熟悉,而且我过去两天所做的所有谷歌搜索都没有产生结果。

Is there ANY way I can search this field in this table for multiple values and exclude them in the results?有什么方法可以在此表中的该字段中搜索多个值并将它们排除在结果中吗?

Check out the operators for the MATCH... AGAINST...查看 MATCH... AGAINST... 的运算符

I think what you are looking for is:我认为您正在寻找的是:

WHERE MATCH(ingredients) AGAINST ("-pea*" in boolean mode)

Examples:例子:

pea protein,radish
// not returned (as desired)

peas,beans
// not returned (as desired)

But there may still be issues:但可能仍然存在问题:

peanut butter,bacon
// not returned (not as desired)

green pea soup,bacon
// returned (not as desired)

I'm sort of feeling like to do this 'right' you would need meta data on each ingredient .我有点想“正确”地做这件事,你需要每种成分的元数据。

Or alternatively you have allergen 'tags' that you apply to recipes -- separate from the ingredients themselves.或者,您可以将过敏原“标签”应用于食谱——与成分本身分开。

For instance if someone is allergic to 'gluten' that's not actually an ingredient at the recipe level.例如,如果有人对“麸质”过敏,那实际上并不是配方级别的成分。 It's a property of many recipe ingredients tho...它是许多配方成分的属性,但...

This approach would require you to compile a list of all known allergens and then apply them to the recipes, not sure of your context but allergen tagging could work as a folksonomy task.这种方法需要您编制所有已知过敏原的列表,然后将它们应用于食谱,不确定您的上下文,但过敏原标记可以作为一项民俗学任务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM