lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erick Erickson <erickerick...@gmail.com>
Subject Re: No hits while searching!
Date Wed, 27 May 2009 12:38:47 GMT
The most common issue with this kind of thing is that UN_TOKENIZEDimplies no
case folding. So if your case differs you won't get a match.

That aside, the very first thing I'd do is get a copy of Luke (google Lucene
Luke)
and examine the index to see if what's in your index is what you *think* is
in there.

The second thing I'd do is look at query.toString() to see what the actual
query is. You can even paste the output of toString() into Luke and see
what happens.

I'm not sure what buildMultiTermPrefixQuery is all about, but I assume
you have a good reason for using that. But the other strategy I use for
this kind of "what happened?" question is to peel back to simpler cases
until I get what I expect, then build back up until it breaks.....

But really get a copy of Luke, it's a wonderful tool that'll give you lots
of
insight about what's *really* going on...

Best
Erick

On Wed, May 27, 2009 at 12:43 AM, vanshi <nilu.thakur@gmail.com> wrote:

>
> In my web application, I need search functionality on first name and last
> name in 2 different ways, one search must be based on 'Metaphone Analyzer'
> giving all similar sounding names as result and another search should be
> exact match on either first name or last name. The name sounds like search
> has already been coded previously and I need to add another exact match
> search to the application. For this, I have a Lucene Index based out on
> fields from database tables which already had the names field indexed with
> metaphone analyzer. I added 2 more fields in the existing document, which
> indexes first name/last name as UN_TOKENIZED. While searching for exact
> match, I create a term query to look in to newly created UN_TOKENIZED
> fields
> as shown in the code snippets......however this is not getting any hits. I
> would like to know is there anything wrong conceptually?
>
> //creating fields for the document
> FIRST_NAME(Field.Store.NO, Field.Index.TOKENIZED),
>                FIRST_NAME_EXACT(Field.Store.NO, Field.Index.UN_TOKENIZED),
>                LAST_NAME(Field.Store.NO, Field.Index.TOKENIZED),
>                LAST_NAME_EXACT(Field.Store.NO, Field.Index.UN_TOKENIZED),
>
> //name sounds like analyzer class....used while Indexing and searching
> public class NameSoundsLikeAnalyzer extends Analyzer {
>        PerFieldAnalyzerWrapper wrapper;
>
>        /**
>         *
>         */
>        public NameSoundsLikeAnalyzer() {
>                wrapper = new PerFieldAnalyzerWrapper(new StopAnalyzer());
>                wrapper.addAnalyzer(
>
>  PhysicianDocumentBuilder.PhysicianFieldInfo.FIRST_NAME
>                                                .toString(), new
> MetaphoneReplacementAnalyzer());
>
>                wrapper.addAnalyzer(
>
>  PhysicianDocumentBuilder.PhysicianFieldInfo.LAST_NAME
>                                                .toString(), new
> MetaphoneReplacementAnalyzer());
>
>        }
>
>        /**
>         * @see PerFieldAnalyzerWrapper#tokenStream(String, Reader)
>         */
>        @Override
>        public TokenStream tokenStream(String fieldName, Reader reader) {
>                return wrapper.tokenStream(fieldName, reader);
>        }
>
> }
>
> //lastly the query builder
> if(physicianQuery.getExactNameSearch()){
>
>  if(StringUtils.isNotEmpty(physicianQuery.getFirstNameStartsWith())){
>                                TermQuery term = new TermQuery(new
> Term(FIRST_NAME_EXACT.toString(),
> physicianQuery.getFirstNameStartsWith()));
>                                query.add(term,MUST);
>
>                        }
>
>  if(StringUtils.isNotEmpty(physicianQuery.getLastNameStartsWith())){
>                                TermQuery term = new TermQuery(new
> Term(LAST_NAME_EXACT.toString(),
> physicianQuery.getLastNameStartsWith()));
>                                query.add(term,MUST);
>
>                        }
> else{
> //we want metaphone search
> if (StringUtils.isNotEmpty(physicianQuery.getFirstNameStartsWith())) {
>
>  query.add(buildMultiTermPrefixQuery(FIRST_NAME.toString(),
>
>  physicianQuery.getFirstNameStartsWith()), MUST);
>                        }
>
>                        if
> (StringUtils.isNotEmpty(physicianQuery.getLastNameStartsWith())) {
>
>  query.add(buildMultiTermPrefixQuery(LAST_NAME.toString(),
>
>  physicianQuery.getLastNameStartsWith()), MUST);
>                        }
> }
>
>
> --
> View this message in context:
> http://www.nabble.com/No-hits-while-searching%21-tp23735920p23735920.html
> Sent from the Lucene - Java Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message