Uploaded image for project: 'Spring Data for Apache Solr'
  1. Spring Data for Apache Solr
  2. DATASOLR-375

Unable to search on enumerated fields

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.1.1 (Ingalls SR1)
    • Component/s: Core
    • Labels:
      None

      Description

      The core issue has been explained well in the linked StackOverflow post. Although that post has been open for a long time now, there are no comments on it, probably because it was originally not tagged with spring-data-solr.

      Consider the following:

      package org.example.content;
      
      public enum ArticleVisibility { PUBLIC, PRIVATE }
      
      @SolrDocument(solrCoreName="article")
      public class Article {
        @Field("id")
        @Id
        private String id;
      
        @Field("title")
        private String title;
      
        @Field("visibility")
        private ArticleVisibility visibility;
      }
      
      public interface ArticleRepository extends SolrCrudRepository<Article, String> {
        List<Article> findAllByTitleAndVisibility(String title, ArticleVisibility visibility);
      }
      
      articleRepository.save(new Article("A11", "About Spring Data", ArticleVisibility.PRIVATE);
      articleRepository.save(new Article("B22", "About Spring Data JPA", ArticleVisibility.PUBLIC);
      articleRepository.save(new Article("C33", "About Spring Data MongoDB", ArticleVisibility.PUBLIC);
      articleRepository.save(new Article("D44", "About Spring Data Neo4J", ArticleVisibility.PUBLIC);
      articleRepository.save(new Article("E55", "About Spring Data Solr", ArticleVisibility.PUBLIC);
      

      With this code and data in place, I would expect articleRepository.findAllByTitleAndVisibility("About Spring Data", ArticleVisibility.PUBLIC) to return the entries from B22 to E55. However, none are returned.

      The reason is that the values of the visibility field get stored in the index as either org.example.content:PUBLIC or org.example.content:PRIVATE whereas the query executed by Spring Data Solr is similar to title:"About Spring Data" AND visibility:"PUBLIC".

      The limited debugging I have performed reveals that the values org.example.content:PUBLIC and org.example.content:PRIVATE are written by SolrJ based on the value of the key visibility in the SolrInputDocument passed to it by SolrTemplate. However, the query is created by Spring Data Solr and does not follow the same steps, leading to the mismatch.

        Attachments

          Activity

            People

            Assignee:
            cstrobl Christoph Strobl
            Reporter:
            manish.in.java Manish
            Last updater:
            Oliver Drotbohm
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: