-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: searching with stopword yields SearchException
PostPosted: Thu Mar 31, 2011 1:22 pm 
Newbie

Joined: Thu Jul 19, 2007 11:21 am
Posts: 12
Hi there,

the exception message is "Try to search with an empty string: "

The only change I made to the application is an attempt for a custom analyzer (mostly copied from 'hibernate search in action").

this is how i annotated the indexed entity:

Code:
@Indexed
@AnalyzerDef(name="caseanalyzer",
        tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class),
        filters = {
                @TokenFilterDef(factory = LowerCaseFilterFactory.class),
                @TokenFilterDef(factory = StopFilterFactory.class,
                params = {
                        @Parameter(name="words", value="stopwords.txt"),
                        @Parameter(name="ignoreCase", value="true")

                })

        }
)
@Analyzer(definition = "caseanalyzer")


in addition to this, hibernate config declares a default stadardanalyzer
Code:
(<property name="hibernate.search.analyzer">org.apache.lucene.analysis.standard.StandardAnalyzer</property>)

which is working just fine.

after indexing with above, luke works just as expected, tried with a couple analyzers in there, stopwords won't retrieve anything while legit words are working fine, lowercased, etc.

however, my program making use of hibernate-search results in the above error.
just a few more details by going up the stack:

- create QueryBuilder
- query.add(qb.keyword().onField("name").matching(search.getSimpleQuery()).createQuery(), SHOULD);
- ConnectedMultiFieldsTermQueryBuilder.createQuery()
- ConnectedMultiFieldsTermQueryBuilder.createQuery(FieldContext)
here
FieldContext.field = name
this.value = value_of_the_stopword
then
searchTerm is assigned the above value

entering this method
Code:
   private List<String> getAllTermsFromText(String fieldName, String localText, Analyzer analyzer) {
      //it's better not to apply the analyzer with wildcard as * and ? can be mistakenly removed
      List<String> terms = new ArrayList<String>();
      if ( termContext.getApproximation() == TermQueryContext.Approximation.WILDCARD ) {
         terms.add( localText );
      }
      else {
         try {
            terms = Helper.getAllTermsFromText( fieldName, localText, analyzer );
         }
         catch ( IOException e ) {
            throw new AssertionFailure( "IO exception while reading String stream??", e );
         }
      }
      return terms;
   }

which returns an empty list of terms (termContext.getApproximation() == EXACT)
because of last step, SearchException( "Try to search with an empty string: " + fieldContext.getField() ) is thrown.

I will continue to investigate this some more, however I would much appreciate any hint on what i might be doing wrong or maybe an idea on a simpler workaround.

thank you,
val


Top
 Profile  
 
 Post subject: Re: searching with stopword yields SearchException
PostPosted: Fri Apr 01, 2011 2:58 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

I need to look at the source myself first, but it seems you are searching for stop word(s) and hence the query string is empty. Should it throw an exception? Not sure. Let me have a look at come back to you.

-hardy


Top
 Profile  
 
 Post subject: Re: searching with stopword yields SearchException
PostPosted: Fri Apr 01, 2011 9:09 am 
Newbie

Joined: Thu Jul 19, 2007 11:21 am
Posts: 12
thanks for your reply.

i found some workarounds, none of them are perfect as either negatively impact performance or i have to keep a testcase for stopwords in case a future version alters the exception/message.

I still believe that i might be doing something incorrect but in any case please let me know of a proven way to make this work. I haven't tried yet using lucene against QueryBuilder but I would rather find a solution working with QB.

using:
hibernate-search: 3.3.0.Final
hibernate-core: 3.6.1.Final

[EDITED]. Note that if I just force the terms.value to stopword value (ConnectedMultiTermQueryBuilder> createQuery(FieldContext) > just on the evaluation that throws the exception, the term query is built just fine ie (name:stopword.value) and the search returns 0 results as expected.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.