Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Search using delimiters:: '_', '/', '>', etc
PostPosted: Wed Mar 21, 2012 5:01 am 
Newbie

Joined: Wed Mar 21, 2012 4:43 am
Posts: 7
Hello. I need a help. I added full-text search in my application, but I have some problems. When user tries to use the search using any delimiter(' ', '.', '_', etc), then the search doesn't work. I see following error in my log -
Code:
Handler execution resulted in exception
org.hibernate.search.SearchException: phrase query returns no term. Is there a problem with your analyzers? !
   at org.hibernate.search.query.dsl.impl.ConnectedMultiFieldsPhraseQueryBuilder.createQuery(ConnectedMultiFieldsPhraseQueryBuilder.java:146)
   at org.hibernate.search.query.dsl.impl.ConnectedMultiFieldsPhraseQueryBuilder.createQuery(ConnectedMultiFieldsPhraseQueryBuilder.java:75)
....


Top
 Profile  
 
 Post subject: Re: Search using delimiters:: '_', '/', '>', etc
PostPosted: Wed Mar 21, 2012 5:49 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Can you post your query and some example code? The phrase query will use your analyzer to create the terms for the query. If there are no terms it throws this exception. I am currently not sure whether this could be better handled. A more concrete example might help to clarify things.

--Hardy


Top
 Profile  
 
 Post subject: Re: Search using delimiters:: '_', '/', '>', etc
PostPosted: Wed Mar 21, 2012 10:03 am 
Newbie

Joined: Wed Mar 21, 2012 4:43 am
Posts: 7
It's my query:
Code:
QueryBuilder queryBuilder = fullTextSession.
            getSearchFactory().
            buildQueryBuilder().
            forEntity(Post.class).
            get();
      org.apache.lucene.search.Query luceneQuery = queryBuilder.phrase().
            onField("firstField").
            andField("secondField").
            sentence(searchText).
            createQuery();
      Query query = fullTextSession.createFullTextQuery(luceneQuery);
      query.setMaxResults(DEFAULT_MAX_RECORD);


It's my index definition:
Code:
@AnalyzerDefs({
   @AnalyzerDef(name = "russianAnalyzer",
      tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class),
       filters = {
         @TokenFilterDef(factory = LowerCaseFilterFactory.class),
            @TokenFilterDef(factory = SnowballPorterFilterFactory.class,
                        params =  @Parameter(name="language", value="Russian"))
         }
   ),
   @AnalyzerDef(name = "defaultAnalyzer",
      tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class),
      filters = {
         @TokenFilterDef(factory = StandardFilterFactory.class),
         @TokenFilterDef(factory = LowerCaseFilterFactory.class),
            @TokenFilterDef(factory = SnowballPorterFilterFactory.class)
      }
   )
})
@Indexed
...

    @Fields({
       @Field(name = "firstField",
             index = Index.TOKENIZED, analyzer = @Analyzer(definition = "russianAnalyzer")),
       @Field(name = "secondField",
             index = Index.TOKENIZED, analyzer = @Analyzer(definition = "defaultAnalyzer"))   
    })
    public String getContent() {
        return content;
    }
...


Top
 Profile  
 
 Post subject: Re: Search using delimiters:: '_', '/', '>', etc
PostPosted: Wed Mar 21, 2012 10:33 am 
Newbie

Joined: Wed Mar 21, 2012 4:43 am
Posts: 7
Search text examples: "////", ".....", "___", etc


Top
 Profile  
 
 Post subject: Re: Search using delimiters:: '_', '/', '>', etc
PostPosted: Thu Mar 22, 2012 3:57 am 
Newbie

Joined: Wed Mar 21, 2012 4:43 am
Posts: 7
I can use String.removeAll to delete all delimiters, but I think that Hibernate search has special mechanism for these cases.


Top
 Profile  
 
 Post subject: Re: Search using delimiters:: '_', '/', '>', etc
PostPosted: Thu Mar 22, 2012 5:04 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
The problem is not these characters alone, but rather that you only have only these punctuation characters. For example something like "foo bar." should just work fine. The problem with "..//" is that after it is passed through the analyzer there are no tokens left to use for the query. You could check the input for that and don't query in this case (there won't be any results either way), but I am wondering whether Search could handle this better.

--Hardy


Top
 Profile  
 
 Post subject: Re: Search using delimiters:: '_', '/', '>', etc
PostPosted: Thu Mar 22, 2012 5:35 am 
Newbie

Joined: Wed Mar 21, 2012 4:43 am
Posts: 7
hardy.ferentschik wrote:
The problem is not these characters alone, but rather that you only have only these punctuation characters. For example something like "foo bar." should just work fine. The problem with "..//" is that after it is passed through the analyzer there are no tokens left to use for the query.
--Hardy

I know. The problem is that my search text doesn't contain any letter or number.
Thank you.


Top
 Profile  
 
 Post subject: Re: Search using delimiters:: '_', '/', '>', etc
PostPosted: Fri Mar 23, 2012 4:08 am 
Newbie

Joined: Wed Mar 21, 2012 4:43 am
Posts: 7
I have the same problem when my search text contains only word from stopword.txt. What do I do?


Top
 Profile  
 
 Post subject: Re: Search using delimiters:: '_', '/', '>', etc
PostPosted: Fri Mar 23, 2012 4:57 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
That's pretty much the same problem. One workaround is to skip the query DSL and use Lucene's MultiFieldQueryParser directly.

--Hardy


Top
 Profile  
 
 Post subject: Re: Search using delimiters:: '_', '/', '>', etc
PostPosted: Fri Mar 23, 2012 5:19 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
I also created a Jira issue - https://hibernate.onjira.com/browse/HSEARCH-1074


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.