简体   繁体   中英

Solr query search for multiple instances for single keyword

I'm stuck on this one issue. What i want to do is to query on a Multivalued and see if a value comes up at least try. For example the field must be "FREE","FREE" and not just "FREE" or "FREE","IN_USE".

Field 
<field name="point_statusses" type="string" indexed="true" stored="true" multiValued="true" />

Type
<fieldType name="string" class="solr.StrField" sortMissingLast="true" />

SQL
GROUP_CONCAT(cp.status) as point_statusses

Clarification:

I have an object that has multiple plugs and those all have a status of FREE, IN_USE or ERROR. What i want to do is filter on ones that have two plugs with status FREE and I can't change the structure of the schema.xml. How do i query to for this?

Unfortunately, it cannot be done without applying any changes to schema, because solr.StrField does not preserve term frequency information.

Quote from schema.xml :

  ...
  1.2: omitTermFreqAndPositions attribute introduced, true by default 
        except for text fields.
  ...

However, if you can apply some changes, then the following will work (tested on the Solr 4.5.1):

1) Make one of the following changes to schema:

  • Change field to text_general (or any solr.TextField field);
<field name="point_statusses" type="text_general" indexed="true" stored="true" multiValued="true" />
  • OR add omitTermFreqAndPositions="false" to point_statusses definition:
<field name="point_statusses" type="string" indexed="true" stored="true" multiValued="true" omitTermFreqAndPositions="false"/>

2) Filter by term frequency. Examples:

Search documents having exactly 2 ' FREE ' point_statusses:

{!frange l=2 u=2}termfreq(point_statusses,'FREE')

Or from 2 to 3 ' FREE ' point_statusses:

{!frange l=2 u=3}termfreq(point_statusses,'FREE')

The final solr query may look like this:

http://localhost:8983/solr/stack20746538/select?q=*:*&fq={!frange l=2 u=3}termfreq(point_statusses,'FREE')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM