尝试一下:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">
<fragment
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapsActivity" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:layout_alignParentBottom="true"
android:layout_marginBottom="70dp">
<Button
android:id="@+id/btnStart"
android:layout_width="130dp"
android:layout_height="130dp"
android:onClick="socorro"
android:background="@drawable/rec"
/>
</LinearLayout>
</RelativeLayout>
,
该代码的第一个版本不等同于该代码的第二个版本。第一个版本不执行查询,而是使用Scroll API(elasticsearch.helpers.scan)。
Search.query()
方法将构建或扩展搜索对象,而不是将查询发送到elasticsearch。因此,以下代码行具有误导性:
results = s.query("multi_match",query=query,fields=fields,fuzziness='AUTO')
应该是这样的:
# execute() added at the end
results = s.query("multi_match",fuzziness='AUTO').execute()
# scan() removed
for hit in results:
print(hit.meta.score)
,
尝试像这样:
using System;
using Microsoft.Management.Infrastructure;
using Microsoft.Management.Infrastructure.Options;
using System.Linq;
namespace MachineTimeStamps
{
class Program
{
/// <summary>
/// Print the system Uptime and Last Bootup Time (using Win32_OperatingSystem LocalDateTime & LastBootUpTime properties).
/// </summary>
public static void Main(string[] args)
{
var uptime = GetSystemUptime("COMPUTER_NAME");
if (!uptime.HasValue)
{
throw new NullReferenceException("GetSystemUptime() response was null.");
}
var lastBootUpTime = GetSystemLastBootUpTime("COMPUTER_NAME");
if (!lastBootUpTime.HasValue)
{
throw new NullReferenceException("GetSystemLastBootUpTime() response was null.");
}
Console.WriteLine($"Uptime: {uptime}");
Console.WriteLine($"BootupTime: {lastBootUpTime}");
Console.ReadKey();
}
/// <summary>
/// Retrieves the duration (TimeSpan) since the system was last started.
/// Note: can be used on a local or a remote machine.
/// </summary>
/// <param name="computerName">Name of computer on network to retrieve uptime for</param>
/// <returns>WMI Win32_OperatingSystem LocalDateTime - LastBootUpTime</returns>
private static TimeSpan? GetSystemUptime(string computerName)
{
string namespaceName = @"root\cimv2";
string queryDialect = "WQL";
DComSessionOptions SessionOptions = new DComSessionOptions();
SessionOptions.Impersonation = ImpersonationType.Impersonate;
CimSession session = CimSession.Create(computerName,SessionOptions);
string query = "SELECT * FROM Win32_OperatingSystem";
var cimInstances = session.QueryInstances(namespaceName,queryDialect,query);
if (cimInstances.Any())
{
var cimInstance = cimInstances.First();
var lastBootUpTime = Convert.ToDateTime(cimInstance.CimInstanceProperties["LastBootUpTime"].Value);
var localDateTime = Convert.ToDateTime(cimInstance.CimInstanceProperties["LocalDateTime"].Value);
var uptime = localDateTime - lastBootUpTime;
return uptime;
}
return null;
}
/// <summary>
/// Retrieves the last boot up time from a system.
/// Note: can be used on a local or a remote machine.
/// </summary>
/// <param name="computerName">Name of computer on network to retrieve last bootup time from</param>
/// <returns>WMI Win32_OperatingSystem LastBootUpTime</returns>
private static DateTime? GetSystemLastBootUpTime(string computerName)
{
string namespaceName = @"root\cimv2";
string queryDialect = "WQL";
DComSessionOptions SessionOptions = new DComSessionOptions();
SessionOptions.Impersonation = ImpersonationType.Impersonate;
CimSession session = CimSession.Create(computerName,query);
if (cimInstances.Any())
{
var lastBootUpTime = Convert.ToDateTime(cimInstances.First().CimInstanceProperties["LastBootUpTime"].Value);
return lastBootUpTime;
}
return null;
}
}
}
,
试试这个:
s = s.params(preserve_order=True).sort("_score")
然后 scan
可以返回 score
。
Scan 默认会用 ['_doc']
填充排序,这就是它不会返回分数的原因。
本文链接:https://www.f2er.com/3136416.html