SOLR查询以检查是否设置了字段(SOLR query to check if a field is set)
所以我在我的文档中添加了一个名为“theField”的新字段。 他们中的一些人设法正确设置了其他人没有设置的字段
如何进行SOLR查询以仅选择“theField”字段设置正确的文档?
so I added a new field called 'theField' to my documents. Some of them managed to have the fields set correctly others don't
How do I go about making a SOLR query to only select documents whose 'theField' field is set properly?
原文:https://stackoverflow.com/questions/18987111
最满意答案
您每次都在循环中重置
new_title
。for row in reader: for r in rgx_list: new_title = row['title'] # here - discards what you replace rgx = re.compile(r) new_title = re.sub(rgx, '', new_title)
应该改为
for row in reader: new_title = row['title'] # here - only assign once for r in rgx_list: rgx = re.compile(r) new_title = re.sub(rgx, '', new_title)
我想
'.'
应该是r'\.'
您可能还想以最佳方式阅读一些解决方案, 以从Python中的字符串中去除标点符号
You've reset
new_title
each time over the loop.for row in reader: for r in rgx_list: new_title = row['title'] # here - discards what you replace rgx = re.compile(r) new_title = re.sub(rgx, '', new_title)
Should instead be
for row in reader: new_title = row['title'] # here - only assign once for r in rgx_list: rgx = re.compile(r) new_title = re.sub(rgx, '', new_title)
And I think
'.'
should ber'\.'
You may also want to read some of the solutions at Best way to strip punctuation from a string in Python
相关问答
更多-
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
您可以将可选的空格字符\s*粘贴在正则表达式中的每个其他字符之间。 虽然被授予,它会变得有点长。 /cats/ - > /c\s*a\s*t\s*s/ You can stick optional whitespace characters \s* in between every other character in your regex. Although granted, it will get a bit lengthy. /cats/ -> /c\s*a\s*t\s*s/
-
我如何搜索字符串中的模式并将其替换为空格?(How can i search for pattern in string and replace it with a whitespace?)[2023-06-04]
您每次都在循环中重置new_title 。 for row in reader: for r in rgx_list: new_title = row['title'] # here - discards what you replace rgx = re.compile(r) new_title = re.sub(rgx, '', new_title) 应该改为 for row in reader: new_title = row['ti ... -
使用gsub来匹配一个A然后是最少数量的不是A的其他字符,直到我们到达B 将匹配替换为方括号包围的匹配。 在下面, x是输入字符串(如在问题中并在最后的注释中重复),但它可能是这样的字符串的字符向量,例如c(x, x) ,它应该仍然有效。 没有包被使用。 gsub("(A[^A]*?B)", "[\\1]", x) ## [1] "CCBC[ACB]AHG[AB]GG[ARB]JDFDF[ADFDFB]FDFD" 注意: x <- "CCBCACBAHGABGGARBJDFDFADFDFBFDFD" U ...
-
在这个特定的情况下,你可以去 regexp $pat $str val 大括号阻止了替换,所以您将字符串“$ pat”与您的数据字符串进行匹配。 如果您在模式中将元字符与变量替换一起使用,如 if {[regexp -nocase \s$name\s\w+\s\w+\s(\d+) $str val val1]} … 你需要阻止一个替换(反斜杠替换),同时允许另一个替换(反斜杠替换)。 这可以用来完成 if {[regexp -nocase [subst -nobackslashes {\s$name\s ...
-
如果我正确理解您的问题,您只需打开输入和输出文件,然后检查该行是否包含旧信息,并以标签结束并相应地写入相应的内容。 with open('in.txt') as f, open('out.txt', 'r') as output: for line in f: if line.endswith(label) and not line.startswith(new_info): output.write(replacement_text) els ...
-
SQL小提琴 Oracle 11g R2架构设置 : SELECT 1 FROM DUAL; 查询1 : WITH test(col) as( select 'i want to increase those numbers 25 and 250' from dual union all select 'i want to increase those numbers 999 and 99' from dual ) SELECT col, ( SELECT LISTAGG( ...
-
这个解决方案假设你总是有一个空间在你的字符串的末尾......它应该转换 这里是一个示例字符串HELLO ... 至: 这里是我想要的一个例子stringtext ...因为这是我理解你想要做的。 代码如下: NSString *string = @"Here is an example string HELLO "; NSRange rangeToSearch = NSMakeRange(0, [string length] - 1); // get a range without the space ...
-
也许如果你调整原始代码有点像这样: $patterns = array("/.*jacket.*/i", "/.*jeans.*/i"); $replacements = array("jacket", "jeans"); $string = 'Red jackets'; $replaced_string = preg_replace($patterns, $replacements, $string); 把那些.*放在那里将清除字符串的其余部分......然后只留下你想要的替换字符串。 Maybe if ...
-
你可以一个接一个地分开做两个正则表达式。 请尝试以下方法 newString1 = newString1.replaceAll("le", "lo").replaceAll("We", "Wo"); You can do two regular expressions separatelt one after the other. Please try the following newString1 = newString1.replaceAll("le", "lo").replaceAll("We", ...