lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "G.Long" <jde...@gmail.com>
Subject Re: problem with a query
Date Thu, 08 Sep 2011 08:10:34 GMT
OK, thank you for the explanation :)

Gary.

Le 07/09/2011 17:34, Ian Lea a écrit :
> There appears to be a mismatch between your usage of KeywordAnalyzer
> and PhraseQuery.  As the javadoc says, KeywordAnalyzer is generally
> used for data like zip codes and product ids, whereas phrase queries
> are used for finding phrases within longer pieces of text.
>
> Adding your whole value as one term to a PhraseQuery may work, because
> it has been indexed as one term, but it would be less confusing to
> just use a TermQuery.
>
> The code where you split the value up doesn't work because it is
> looking for multiple terms whereas you've only got the one - because
> you used KeywordAnalyzer.
>
>
> --
> Ian.
>
>
> On Wed, Sep 7, 2011 at 1:35 PM, G.Long<jdevgl@gmail.com>  wrote:
>> Hi Rick :)
>>
>> I found the problem but I think It needs explanations.
>>
>> In the code where the query was created, there was a peace of code as
>> following :
>>
>> if(value.contains(" ")){
>>                 String[] words = value.split(" ");
>>                 PhraseQuery param = new PhraseQuery();
>>                 for (String word : words){
>>                     param.add(new Term(key,word));
>>                 }
>>                 query.add(param, BooleanClause.Occur.MUST);
>>                 return query;
>> }
>>
>> I replaced it by :
>>
>> PhraseQuery pQuery = new PhraseQuery();
>> pQuery.add(new Term(key, value));
>> query.add(pQuery, BooleanClause.Occur.MUST);
>> return query;
>>
>> So there is no more split on the value and it is passed in the phraseQuery
>> in one shot.
>>
>> If I dump the query with query.toString(), the result is exactly the same,
>> but the query with the first version of the code doesn't work whereas the
>> second one do.
>>
>> the value is like : "/library/authors/Martin/Game of Thrones/chapter I"
>>
>> So the first code split the value after Game, of and chapter and rebuilt the
>> entire phrase whereas the second one made the phrase with the entire value.
>>
>> But why does it provide a different result?
>>
>> Regards,
>> Gary
>>
>>
>> Le 07/09/2011 13:15, Erick Erickson a écrit :
>>> Nothing really jumps out, but here's an idea:
>>> Dump query.toString() and see if it's what you
>>> expect as the parsed query.
>>>
>>> And make absolutely sure that the directory you open
>>> in your Java code is the same one you open in Luke. You'd
>>> be amazed how much time I've spent tracking down
>>> mistakes like that<G>.
>>>
>>> Best
>>> Erick
>>>
>>> "It's not the things you don't know that'll kill you, it's the things
>>> you *do* know that aren't true".
>>>
>>> On Wed, Sep 7, 2011 at 5:47 AM, G.Long<jdevgl@gmail.com>    wrote:
>>>> Hi :)
>>>>
>>>> I have a lucene index with fields analyzed with Keyword Analyzer. In my
>>>> java
>>>> program, I search for a document by creating a query with two boolean
>>>> parameters like : +param1:"foo" +param2:"bar"
>>>>
>>>> The query return no result but If I run the same query with Luke, it
>>>> returns
>>>> the result I'm looking for :/
>>>>
>>>> I'm using the same method to initialyze the index writer and searcher :
>>>>
>>>> directory = FSDirectory.open(indexFolder);
>>>> PerFieldAnalyzerWrapper pfaWrapper = getPerfFieldAnalyzer();
>>>> IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_31,
>>>> pfaWrapper);
>>>> config.setOpenMode(OpenMode.CREATE_OR_APPEND);
>>>> iwriter = new IndexWriter(directory, config);
>>>> isearcher = new IndexSearcher(directory);
>>>>
>>>> (The default analyzer for PerFieldAnalyzer is KeywordAnalyzer. I'm using
>>>> it
>>>> because there are two fields in my index which use StandardAnalyzer but
>>>> these are not the ones I'm using in my query)
>>>>
>>>> To create my query, I use the following code:
>>>>
>>>> Analyzer analyzer = new KeywordAnalyzer();
>>>> QueryParser parser = new QueryParser(Version.LUCENE_31, key, analyzer);
>>>> Query param = parser.parse(value);
>>>> query.add(param, BooleanClause.Occur.MUST);
>>>>
>>>> And then the execution of my query:
>>>>
>>>> TopFieldCollector collector = TopFieldCollector.create(new
>>>> Sort(SortField.FIELD_DOC), 200000, true, false, false, false);
>>>> isearcher.search(query, collector);
>>>> ScoreDoc[] hits = collector.topDocs().scoreDocs;
>>>>
>>>> Any ideas of why the query isn't returning anything although the params
>>>> of
>>>> the query correspond to an existing result?
>>>>
>>>> In Luke, I specify the Keyword Analyzer and it works.
>>>>
>>>> Thank you for your help :)
>>>>
>>>> Gary
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
>>>> For additional commands, e-mail: java-user-help@lucene.apache.org
>>>>
>>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
>>> For additional commands, e-mail: java-user-help@lucene.apache.org
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
>> For additional commands, e-mail: java-user-help@lucene.apache.org
>>
>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message