Java Solr SolrJ获取新建索引文件的id值(Java Solr SolrJ get id value of the newly indexed file)
我有一个实体,我想链接到通过SolrJ上传到solr的索引文件。 最好它是实体上的一个字段,其文件的条目标识为值。 事情是 - 我不知道如何在上传之后获得该ID。 代码如下:
//File tempFile; //MultipartFile file; tempFile = File.createTempFile(prefix, postfix); file.transferTo(tempFile); ContentStreamUpdateRequest req = new ContentStreamUpdateRequest("/update/extract"); req.addFile(tempFile, file.getContentType()); req.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true); NamedList list = solrClient.request(req); System.out.println(list); //{responseHeader={status=0,QTime=1328}} tempFile.delete();
I have an entity, which I want to link to an indexed file uploaded to solr via SolrJ. Preferably it would be a field on the entity with the file's entry id as value. Thing is - I don't know how to get that id after it just being uploaded. Here is the code:
//File tempFile; //MultipartFile file; tempFile = File.createTempFile(prefix, postfix); file.transferTo(tempFile); ContentStreamUpdateRequest req = new ContentStreamUpdateRequest("/update/extract"); req.addFile(tempFile, file.getContentType()); req.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true); NamedList list = solrClient.request(req); System.out.println(list); //{responseHeader={status=0,QTime=1328}} tempFile.delete();
原文:https://stackoverflow.com/questions/42250674
最满意答案
我已经尝试了这个并且似乎工作正常,因为我怀疑语法和逻辑看起来是正确的。 您可以尝试添加对
ToList
的调用,这将使其在检查它是一个整数列表时更加清晰。 如果没有,那么肯定会有其他事情发生。 这是我建议的代码:IEnumerable<int> rpList = dataBits .Where(bit => bit.bitPos > 2) .Select(bit => bit.risePeriod) .ToList();
I've tried this and it seems to be working fine, as I suspected as the syntax and logic looks correct. You could try adding a call to
ToList
which will make it more clear when inspected that it is a list of integers. If not, there must be something else going on here. Here's the code I suggest:IEnumerable<int> rpList = dataBits .Where(bit => bit.bitPos > 2) .Select(bit => bit.risePeriod) .ToList();
相关问答
更多-
你想用如下的linq语句替换你使用ForEach的地方: string MyListOfMyStrings = String.Join(",", (from myObject in myObjectList select myObject.MyString).ToArray()); 请参阅linq的MSDN指南 You want to replace where you are using ForEach with a linq statement like below: string MyListOfM ...
-
如何使用Linq从对象列表中获取唯一的属性列表?(How do I use Linq to obtain a unique list of properties from a list of objects?)[2023-12-18]
IEnumerableids = list.Select(x=>x.ID).Distinct(); IEnumerable ids = list.Select(x=>x.ID).Distinct(); -
您可以使用Enumerable.Contains : var query = from t2 in list2 where list1.Contains(t2.Id) select t2; 如果list1中的值是唯一的,你也可以使用更高效的 Join : var query = from t2 in list2 join t1 in list1 on t2.Id equals t1 se ...
-
使用GroupBy 。 objectList.GroupBy(o => o.Property1); http://www.codeproject.com/articles/35667/How-to-Use-LINQ-GroupBy.aspx Use GroupBy. objectList.GroupBy(o => o.Property1); http://www.codeproject.com/articles/35667/How-to-Use-LINQ-GroupBy.aspx
-
如果我正确地理解了你的话: var result = unsortedFlights .OrderByDescending(f => totalCityFilters[f.DestinationID]) .ThenBy( f => f.FinalPrice) .ToList(); 如果totalCityFilters的值是您想先订购的数量。 If i have understood you correctly: var resu ...
-
换句话说,你只需要从keywords提取任何单词的项目。 所以,在LINQ中可以通过如下方式完成: var model = articles .Where(a => keywords.Any(k => a.Title.Contains(k) || a.Description.Contains(k))) .ToList(); 如果标题或描述不包含任何keywords ,则不会将其添加到结果列表中。 请注意,与foreach相比,它不会提高时间复杂度,但它可能会提高可读性。 一般来说,任何迭代 ...
-
我已经尝试了这个并且似乎工作正常,因为我怀疑语法和逻辑看起来是正确的。 您可以尝试添加对ToList的调用,这将使其在检查它是一个整数列表时更加清晰。 如果没有,那么肯定会有其他事情发生。 这是我建议的代码: IEnumerable
rpList = dataBits .Where(bit => bit.bitPos > 2) .Select(bit => bit.risePeriod) .ToList(); I've tried this and it seems to be working ... -
那这个呢: plan.Components.Where(c => c.active).Select (c => c.qty.HasValue ? (int)c.qty.Value : 0 ) 它应该做必要的过滤。 What about this: plan.Components.Where(c => c.active).Select (c => c.qty.HasValue ? (int)c.qty.Value : 0 ) It should do the required filtering.
-
你有什么是功能上Except使用整个项目的平等,而不是使用相等的整个项目,你想执行Except使用选定的属性作为关键。 虽然您可以提供自定义的IEqualityComparer ,但只能比较名称,编写该比较器是一些容易出错的样板代码。 我们可以写出一种方法,可以非常容易地对投影键执行Except : public static IEnumerable
ExceptBy ( this IEnumerable source, IEn ... -
您可以使用GroupBy + OrderByDescending : List
maxDepthGroupList = Beams .GroupBy(b => b.Depth) .OrderByDescending(g => g.Key) .First() .ToList(); You can use GroupBy + OrderByDescending: List maxDepthGroupList = Beams .GroupBy( ...