在结果中返回函数值

Want to pass the IT exam speedily? Here are the newest PDF test resources, including Cisco, Microsoft, IBM, Oracle, EMC and so on. These dumps will help you pass the test quickly, which is also the most effective way to pass the exam.
http://www.itexamlibrary.com/
Itexamlibrary provides high quality IT Certification exam dumps and latest pdf materials.
cisco
Exam dumps PDF, and practice exam questions can help you pass the exam quickly and smoothly. 100% quality guarantee, you can get a full refund if you lost the exam! You can trust it
300-115 pdf
This exam materials will improve your pass rate.
300-208 exam dumps
It will help you pass the exam quickly, which is also the best way to pass the test.
200-355 exam material
Cisco certified, exam dumps PDF download online,various cisco exam material Let You pass exam easily.
210-065 dumps exam
About cisco, Microsoft, IBM and other exam you know how much? There are a variety of sources to help you understand and pass the certification exam quickly.
70-532 exam guide
Do you want to pass the IT certification exam quickly? These materials will help you achieve your dream of passing exams.
300-101 exam questions
Itexamlibrary provides high quality IT Certification exam dumps.And this dumps will help you pass exam easilly.

假设你有一个服务,你的用户可以搜索不同的公司,用户输入一个简单的关键字,可以返回匹配关键字的公司,但是有一天,用户要求返回的公司列表中可以显示公司跟用户的距离,这是该怎么做呢?

准备工作

在开始之前,需要先了解字段别名功能,具体可以参看这里

怎么做

1.假设我们在 schema.xml 中定义了如下索引结构:


<field name="id" type="string" indexed="true" stored="true"
required="true" multiValued="false" />
<field name="name" type="text" indexed="true" stored="true"/>
<field name="loc" type="location" indexed="true" stored="true"/>
<dynamicField name="*_coordinate" type="double" indexed="true"
stored="false" />

2.我们需要定义 location 字段类型,如下所示:


<fieldType name="location" class="solr.LatLonType"
subFieldSuffix="_coordinate"/>

3.再假设我们有以下索引数据


<add>
<doc>
<field name="id">1</field>
<field name="name">Company 1</field>
<field name="loc">56.4,40.2</field>
</doc>
<doc>
<field name="id">2</field>
<field name="name">Company 2</field>
<field name="loc">50.1,48.9</field>
</doc>

<doc>
<field name="id">3</field>
<field name="name">Company 3</field>
<field name="loc">23.18,39.1</field>
</doc>
</add>

4.现在可以通过以下语句查询到名称中匹配 company  的公司

q=name:company&fl=*

5.假设我们已经获得了客户端位置是 50.0, 28.0,然后我们打算在公司结果列表中显示客户端跟这些公司的距离。这时我们需要将以下参数加载 fl 中:

dist:geodist(loc,50.0,28.0)

这样整个查询看起来像这样:

q=name:company&fl=*,dist:geodist(loc,50.0,28.0)

查询返回的内容如下所示:


<?xml version="1.0" encoding="UTF-8"?>
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">0</int>
<lst name="params">
<str name="q">name:company</str>
<str name="fl">*,dist:geodist(loc,50.0,28.0)</str>
</lst>
</lst>
<result name="response" numFound="3" start="0">
<doc>
<str name="id">1</str>
<str name="name">Company 1</str>
<str name="loc">56.4,40.2</str>
<double name="dist">1077.4200268973314</double>
</doc>
<doc>
<str name="id">2</str>
<str name="name">Company 2</str>
<str name="loc">50.1,48.9</str>
<double name="dist">1487.4260767512278</double>
</doc>
Chapter 4
153
<doc>
<str name="id">3</str>
<str name="name">Company 3</str>
<str name="loc">23.18,39.1</str>
<double name="dist">3134.746384852772</double>
</doc>
</result>
</response>

上面结果中 dist 就是客户要的距离字段。

Copyright © All Rights Reserved · Green Hope Theme by Sivan & schiy · Proudly powered by WordPress