4 Replies Latest reply on Aug 29, 2012 7:31 AM by paulpa63

    Case Sensitivity Searches for Infinispan Query Module

    paulpa63 Newbie

      Hi,

       

      We are using Infnispan 5.1.5 and make extensive use of the Query Module for data retrieval.  In our system we have a User type with a String name attribute marked with @Field.  In our search/retrieval code we use the following code:

       

      SearchManager sm = Search.getManager(cache);

      QueryBuilder qb = searchManager.buildQueryBuilderForClass(User.class).get();

      Query nameQuery = qb.phrase().onField("name").sentence(name).createQuery();

       

      This code returns a user object with name "Fred" when the name parameter specified in the sentence clause of the above Query statement is equal to "fred".  What is the simplest way to force the matching on the name attribute to work case sensitively?

       

      Paul

        • 1. Re: Case Sensitivity Searches for Infinispan Query Module
          Hardy Ferentschik Novice

          Hi Paul,

           

          you will need to specify/configure the right analyzer (for indexing and searching). Per default Lucene will use the StandardAnalyzer which is a combination of StandardTokenizer with StandardFilter, LowerCaseFilter and StopFilter using a list of English stop words. The problem in your case is the LowerCaseFilter which you don't need.

           

          To configure your analyzer you can use the @AnalyzerDef annotation. It looks sometimes like this:

           

          @AnalyzerDef(name = "case-sensitive",

                  tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class),

                  filters = {

                          @TokenFilterDef(factory = LowerCaseFilterFactory.class),

                          @TokenFilterDef(factory = SnowballPorterFilterFactory.class, params = {

                                  @Parameter(name = "language", value = "English")

                          })

          })

          @Indexed

          public class MyClass {

                  @Field(index = Index.YES, analyze = Analyze.YES, analyzer = @Analyzer(definition = "case-sensitive"))

                  private String myField;

          }

           

          Have a look also at the Analysis chapter of the Hibernate Search online docs - http://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#d0e3385

           

          It is important that you use the  case sensitive analyzer at query time as well in case you are using a QueryParser.

          Hope this helps.

           


          1 of 1 people found this helpful
          • 2. Re: Case Sensitivity Searches for Infinispan Query Module
            paulpa63 Newbie

            Hi Hardy,

             

            Thanks for your response.  I did try making some changes along these lines but ran into a "cannot be resolved to a type" error on the SnowballPorterFilterFactory class when that is referenced in the analyzer specification.  I am including all of the jars from the query module of Infinispan 5.1.5.FINAL so this seems odd to me?

             

            Re your final comment, as I am using a QueryBuilder I assume there would be no further configuration / declaration required in my case on the query end?

             

            Thanks in advance,

             

            Paul

            • 3. Re: Case Sensitivity Searches for Infinispan Query Module
              Sanne Grinovero Master

              Hi Paul,

              sorry for the delay. Holiday times for most of us

               

              Many Analyzers are optional dependencies, and distributed only with Hibernate Search, not with Infinispan as it's too big already. The SnowballPorterFilterFactory isn't actually needed to implement just case-sensitive search - it's just an example of how to define a custom text analysis. The SnowballPorterFilterFactory provides  sofisticated language analysis using stemming.

               

              If that's what you're looking for, you can download the additional optional jars from:

              http://www.hibernate.org/subprojects/search/download

               

              But for your simple case I guess you could leave that filter our:

               

               

              @AnalyzerDef(name = "case-sensitive",

                      tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class),

                      filters = {

                              @TokenFilterDef(factory = LowerCaseFilterFactory.class),

              })

              1 of 1 people found this helpful
              • 4. Re: Case Sensitivity Searches for Infinispan Query Module
                paulpa63 Newbie

                Hi Sanne,

                 

                Thanks for your reply.  I have included solr-core and solr-solrj from Hibernate Search and the application now compiles and runs with the custom Analyzer definition.  I have specified this analyzer in the @FIeld annotation on the relevant object name attrribute.  However, I am still not achieving case sensitive search.  (I have not made any other changes to the SearchManager/QueryBuilder/Query code?)

                 

                Paul

                 

                PS I trust you enjoyed your holiday!