solrsolr-query-syntax

Query SolR for uniq value in multiple field


i'm looking for a particular SolR query that can select a value in a field, only if it is unique.

for exemple, here is some documents :

<doc>
  <id>1</id>
  <folder_id>abc;def;ghi</folder_id>
</doc>

<doc>
  <id>2</id>
  <folder_id>def</folder_id>
</doc>

If I ask solr for the folder_id:"def", it will gives me back the two documents, but I want only the one with id: 2

What I want is to be able to retrieve all the documents that have the key def and only this one. Unfortunatly I can't be able to retreive all the other keys to be able to create a query like this one folder_id:"def" AND NOT folder_id:("abc", "ghi")

enter image description here

Let me know if you guys need some more info


Solution

  • Use the String as field type for your field instead of text.

    String stores a word/sentence as an exact string without performing tokenization etc. Commonly useful for storing exact matches, e.g, for facetting. Text typically performs tokenization, and secondary processing (such as lower-casing etc.).

    Currently you have field type as Text and it is tokenizing the text and creating separate tokens. Hence you are getting 2 results.

    If you apply the String type to your field then you will be able to achieve the exact match.

    You can also have the KeywordTokenizer with lowercasefilter factory for your field.

    If you want tokenization then you can have 2 fields, one with String type and other with Text type. It all depends on your requirement.