Solr 查询语法 与solrj笔记

本节实例query schema

<fields>
   <field name="seq" type="string" indexed="true" stored="true" required="true" multiValued="false" /> 
   <field name="senddatetime" type="date" indexed="fase" stored="true" required="true" multiValued="false" /> 
   <field name="keywords" type="string" indexed="true" stored="true" />
   <field name ="mobile" type="string" indexed="true" stored="true"/>
    <field name ="description" type="text_general" indexed="true" stored="true"/>

	<field name="_version_" type="long" indexed="true" stored="true"/>

  </fields>
 

q

The q parameter is normally the main query for the request. See Solr query syntax for more information on different types of queries and syntaxes.

query.setQuery("*:*");

query.setQuery("keywords: \"LP kind 199\"");

query.setQuery("*:* AND NOT seq:a4ec88f8-e0d8-4841-8b02-a88b778d3aa6");

query.setQuery("*:* OR -seq:a4ec88f8-e0d8-4841-8b02-a88b778d3aa6");

sort

query.addSortField("senddatetime", ORDER.desc);

start

query.setStart(0);

rows

query.setRows(20);

pageDoc and pageScore

fq

"fq" stands for Filter Query.

This parameter can be used to specify a query that can be used to restrict the super set of documents that can be returned, without influencing score. It can be very useful for speeding up complex queries since the queries specified with fq are cached independently from the main query. Caching means the same filter is used again for a later query (i.e. there's a cache hit). See SolrCaching to learn about the caches Solr uses.

query.addFilterQuery(" senddatetime:[2012-11-19T00:59:59.999Z TO 2013-03-06T23:59:59.999Z+1YEAR]");

query.addFilterQuery(" senddatetime:[NOW-3MONTHS TO NOW]");

Caching of filters

fl

This parameter can be used to specify a set of fields to return, limiting the amount of information in the response. When returning the results to the client, only fields in this list will be included.

query.setFields("keywords description seq");

df

df stands for default search field.

        query.setQuery("1316779836");        query.set("df", "mobile");

相关推荐