我正在使用Java来查询Solr服务器,以查找在我感兴趣的一组已知ID中具有ID的结果.
我能想到的最好的方法是获得我感兴趣的这些结果是创建一个看起来像这样的长查询字符串:
q=(item_id:XXX33-3333 OR item_id:YYY42-3445 OR item_id:JFDE-3838)
queryString
在发出请求之前,我生成了这个String,并且我最终想要的请求中包含超过1500个这样的id.我正在使用HTTP POST来进行查询:
HttpPost post = new HttpPost(url);
post.setHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
StringEntity entity = new StringEntity(queryString, "UTF-8");
entity.setContentType("application/x-www-form-urlencoded; charset=utf-8");
post.setEntity(entity);
HttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(post);
Run Code Online (Sandbox Code Playgroud)
如果我将查询限制为前1000个ID,它会成功,我会按照我的预期得到结果.但是,如果我将查询增加到包含我真正感兴趣的所有1500,我会得到一个HTTP 400响应代码,其中包含以下错误:
HTTP/1.1 400 org.apache.lucene.queryParser.ParseException: Cannot parse '[my query here...]
在Solr查询中我可以和OR一起使用的数量是否有限制?当我超过1000时,还有另一个原因可能会失败吗?我已经进行了实验,它在1024左右失败了(我的ID几乎都是相同的长度)所以它似乎暗示有一个字符或术语限制.
或者,如果有人对如何以另一种更智能的方式检索我正在寻找的物品有一个很好的建议,我很乐意听到它.我的备份解决方案只是查询所有项目的Solr ,解析结果,并使用属于我感兴趣的集合的那些.我宁愿不这样做,因为数据源可能有数万个项目,而且效率低下.
在我的应用程序中,我已注册广播接收器以接收系统意图ACTION_DEVICE_STORAGE_LOW.我希望每当手机内存不足时就播放这个内容.所以,我下载了一些额外的应用程序(我的手机有一个非常小的内部存储器),导致操作系统显示系统内存不足的通知.手机剩下10-15 MB.但是,我的广播接收器从未收到过这种意图.然而,系统通知保留在通知栏中,由于内存不足,我无法浏览互联网.
每当显示低内部存储器通知时,是否应该广播此意图?或者是否有一些甚至更低的内存阈值将发送我尚未在手机上播放的广播?在文档中,它只说"广播操作:指示设备上存储器状况不佳的粘性广播".因为它实际上并没有定义"低记忆条件",所以我不知道我做错了什么,或者我还没有达到这个条件.
这是我的BroadCastReceiver的代码:
public class MemoryBroadcastReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(Intent.ACTION_MEDIA_MOUNTED)) {
Log.isExternalStorageProblem = false;
Log.clearNotification(Log.externalMemoryNotificationID);
}
if (action.equals(Intent.ACTION_DEVICE_STORAGE_OK)) {
Log.isInternalStorageLow = false;
Log.clearNotification(Log.internalMemoryNotificationID);
}
if (action.equals(Intent.ACTION_DEVICE_STORAGE_LOW)) {
Log.isInternalStorageLow = true;
Log.displayMemoryNotification("Internal Storage Low",
"The internal storage is low, Please fix this.",
"Please clear cache and/or uninstall apps.", Log.internalMemoryNotificationID);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我有一个初始化接收器的服务,添加了intent过滤器并注册它(以及其他内容):
private MemoryBroadcastReceiver memoryBroadcastReciever = new MemoryBroadcastReceiver();
public void registerBroadcastReceiver() {
IntentFilter filter = new IntentFilter(); …
Run Code Online (Sandbox Code Playgroud) 我正在使用Facebook SDK在我的Android应用程序中显示Facebook帖子.我有格式的每个帖子的created_time:
2012-01-04T12:28:52+0000
Run Code Online (Sandbox Code Playgroud)
我能够将其解析为Java Date对象,如下所示:
public static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss+SSSS";
public static Date parseDate(String str) {
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
try {
Date date = sdf.parse(str);
} catch(ParseException e) {
Log.w(TAG, "Unable to parse date string \"" + str + "\"");
}
return date;
}
Run Code Online (Sandbox Code Playgroud)
然后,我试图显示一条消息,描述自使用此方法创建帖子以来经过的时间:
public static String timeAgoInWords(Date from) {
Date now = new Date();
long difference = now.getTime() - from.getTime();
long distanceInMin = difference / 60000;
if ( 0 <= distanceInMin && distanceInMin <= …
Run Code Online (Sandbox Code Playgroud)