You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by je...@sevajug.org on 2006/11/03 03:00:12 UTC
Query question
I am wanting to be able to put sets of data in a very structured way and
query Lucene for only 100% matches. Is there a way to do this? I seem to
be getting back at best 0.30685282. I appreciate any help and insite.
Jeff Richley, Vice President
Southeast Virginia Java Users Group
jeff.richley@sevajug.org
http://www.sevajug.org
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: Query question
Posted by je...@sevajug.org.
Chris, thank you so much for your help. I guess I was interpretting the
score incorrectly. Wasn't getting it through this thick head, I'm rolling
along now. You all have done a great job with this!
>
> : I know I am getting very close on this one but can't seem to get the
> score
> : above .306. My guess is that I need to do something different in my
>
> 1) you didn't setOmitNorms(true)
>
> 2) why do you care what the score is? .. you said you only wanted exact
> matches: if you don't tokenize, and you build your queries explicitly (all
> MUST or MUST_NOT, no sloppy phrases, etc..) the matches you get will only
> be exact matches.
>
> 3) if you really care about the numeric score values, don't use Hits,
> those scores are "psuedo-normalized"
>
> 4) the Searcher.explain method can be used to understand why you are
> getting a particular score value. most likely you can get a score of
> "1.0" by subclassing Similarity in a creative way, but see point#2.
>
>
> : > 1) Use only UN_TOKENIZED fields when adding your documents, and if
> you
> : > use QueryParser to build your queries for you, use the KeywordAnalyzer
> to
> : > make sure no lowercasing or stemming takes place.
> : > 2) OMIT_NORMs when indexing .. they only matter if you want the
> lengths
> : > of fields to affect the score, and you don't -- you only want to know
> if
> : > it matched or not.
> : > 3) if you want to require name="jeff" and age="33" make sure you
> : > construct a query where all clauses are mandatory .. the default in
> the
> : > query parser is "SHOULD" meaning only one clause is mandatory, and the
> : > other clauses increase the score.
>
>
>
>
> -Hoss
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>
Jeff Richley, Vice President
Southeast Virginia Java Users Group
jeff.richley@sevajug.org
http://www.sevajug.org
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: Query question
Posted by Chris Hostetter <ho...@fucit.org>.
: I know I am getting very close on this one but can't seem to get the score
: above .306. My guess is that I need to do something different in my
1) you didn't setOmitNorms(true)
2) why do you care what the score is? .. you said you only wanted exact
matches: if you don't tokenize, and you build your queries explicitly (all
MUST or MUST_NOT, no sloppy phrases, etc..) the matches you get will only
be exact matches.
3) if you really care about the numeric score values, don't use Hits,
those scores are "psuedo-normalized"
4) the Searcher.explain method can be used to understand why you are
getting a particular score value. most likely you can get a score of
"1.0" by subclassing Similarity in a creative way, but see point#2.
: > 1) Use only UN_TOKENIZED fields when adding your documents, and if you
: > use QueryParser to build your queries for you, use the KeywordAnalyzer to
: > make sure no lowercasing or stemming takes place.
: > 2) OMIT_NORMs when indexing .. they only matter if you want the lengths
: > of fields to affect the score, and you don't -- you only want to know if
: > it matched or not.
: > 3) if you want to require name="jeff" and age="33" make sure you
: > construct a query where all clauses are mandatory .. the default in the
: > query parser is "SHOULD" meaning only one clause is mandatory, and the
: > other clauses increase the score.
-Hoss
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: Query question
Posted by je...@sevajug.org.
Thought I attached the code :)
package com.infinity.naxx.sandbox;
import java.io.IOException;
import java.util.Iterator;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.KeywordAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.Term;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.Hit;
import org.apache.lucene.search.Hits;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.PhraseQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.store.RAMDirectory;
public class LuceneTest {
public static void main(String[] args) {
try {
Analyzer analyzer = new KeywordAnalyzer();
RAMDirectory directory = new RAMDirectory();
IndexWriter writer = new IndexWriter(directory, analyzer, true);
Document document = new Document();
Field location = new Field("location", "/a/b/c", Field.Store.YES,
Field.Index.UN_TOKENIZED);
document.add(location);
Field name = new Field("name", "Jeff Richley", Field.Store.YES,
Field.Index.UN_TOKENIZED);
document.add(name);
writer.addDocument(document);
writer.optimize();
writer.close();
IndexSearcher searcher = new IndexSearcher(directory);
QueryParser parser = new QueryParser("name", analyzer);
Query query = parser.parse("\"Jeff Richley\"");
System.out.println("Searching: " + query.toString());
Hits hits = searcher.search(query);
System.out.println("There were " + hits.length() + " hits");
for (Iterator iter = hits.iterator(); iter.hasNext();) {
Hit hit = (Hit) iter.next();
System.out.println(hit.getScore() + " "
+ hit.getDocument().get("location"));
}
} catch (IOException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}
}
}
> I know I am getting very close on this one but can't seem to get the score
> above .306. My guess is that I need to do something different in my
> query. If at all possible, could you take a quick look at my test code
> and point me in the correct direction? I know everyone is very busy, so
> any help would be greatly appreciated.
>
>>
>> : 1.) I have data like name="Jeff" lastname="Richley" age="33" and I
>> need
>> to
>> : be able to query by any combination such as name="Jeff" age="33". But
>> if
>> : I query with name="Jeffrey" there is no match.
>> :
>> : 2.) The name value pairs are not really controlled until the end user
>> is
>> : inserting information or querying. I may have the data from the
>> previous
>> : example and then have another that has address information and then
>> : something totally unrelated such as stock prices. The point is, I
>> can't
>> : guarantee what exactly will be in the data.
>>
>> Lucene will fit your needs because of your second point nicely,
>> Documents
>> don't need to all have hte same fields.
>>
>> as to your first point, and your question about 100% matches, Lucene
>> should be able to meet your needs perfectly, you just have to understand
>> how to ask it the right question. lemme give you a quick check list of
>> things to keep in mind, and as you dig into the documentation these will
>> make more sense...
>>
>> 1) Use only UN_TOKENIZED fields when adding your documents, and if you
>> use QueryParser to build your queries for you, use the KeywordAnalyzer
>> to
>> make sure no lowercasing or stemming takes place.
>> 2) OMIT_NORMs when indexing .. they only matter if you want the lengths
>> of fields to affect the score, and you don't -- you only want to know if
>> it matched or not.
>> 3) if you want to require name="jeff" and age="33" make sure you
>> construct a query where all clauses are mandatory .. the default in the
>> query parser is "SHOULD" meaning only one clause is mandatory, and the
>> other clauses increase the score.
>>
>>
>>
>> -Hoss
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
>> For additional commands, e-mail: java-user-help@lucene.apache.org
>>
>>
>
>
> Jeff Richley, Vice President
> Southeast Virginia Java Users Group
> jeff.richley@sevajug.org
> http://www.sevajug.org
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
Jeff Richley, Vice President
Southeast Virginia Java Users Group
jeff.richley@sevajug.org
http://www.sevajug.org
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: Query question
Posted by je...@sevajug.org.
I know I am getting very close on this one but can't seem to get the score
above .306. My guess is that I need to do something different in my
query. If at all possible, could you take a quick look at my test code
and point me in the correct direction? I know everyone is very busy, so
any help would be greatly appreciated.
>
> : 1.) I have data like name="Jeff" lastname="Richley" age="33" and I need
> to
> : be able to query by any combination such as name="Jeff" age="33". But
> if
> : I query with name="Jeffrey" there is no match.
> :
> : 2.) The name value pairs are not really controlled until the end user is
> : inserting information or querying. I may have the data from the
> previous
> : example and then have another that has address information and then
> : something totally unrelated such as stock prices. The point is, I can't
> : guarantee what exactly will be in the data.
>
> Lucene will fit your needs because of your second point nicely, Documents
> don't need to all have hte same fields.
>
> as to your first point, and your question about 100% matches, Lucene
> should be able to meet your needs perfectly, you just have to understand
> how to ask it the right question. lemme give you a quick check list of
> things to keep in mind, and as you dig into the documentation these will
> make more sense...
>
> 1) Use only UN_TOKENIZED fields when adding your documents, and if you
> use QueryParser to build your queries for you, use the KeywordAnalyzer to
> make sure no lowercasing or stemming takes place.
> 2) OMIT_NORMs when indexing .. they only matter if you want the lengths
> of fields to affect the score, and you don't -- you only want to know if
> it matched or not.
> 3) if you want to require name="jeff" and age="33" make sure you
> construct a query where all clauses are mandatory .. the default in the
> query parser is "SHOULD" meaning only one clause is mandatory, and the
> other clauses increase the score.
>
>
>
> -Hoss
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>
Jeff Richley, Vice President
Southeast Virginia Java Users Group
jeff.richley@sevajug.org
http://www.sevajug.org
Re: Query question
Posted by Chris Hostetter <ho...@fucit.org>.
: 1.) I have data like name="Jeff" lastname="Richley" age="33" and I need to
: be able to query by any combination such as name="Jeff" age="33". But if
: I query with name="Jeffrey" there is no match.
:
: 2.) The name value pairs are not really controlled until the end user is
: inserting information or querying. I may have the data from the previous
: example and then have another that has address information and then
: something totally unrelated such as stock prices. The point is, I can't
: guarantee what exactly will be in the data.
Lucene will fit your needs because of your second point nicely, Documents
don't need to all have hte same fields.
as to your first point, and your question about 100% matches, Lucene
should be able to meet your needs perfectly, you just have to understand
how to ask it the right question. lemme give you a quick check list of
things to keep in mind, and as you dig into the documentation these will
make more sense...
1) Use only UN_TOKENIZED fields when adding your documents, and if you
use QueryParser to build your queries for you, use the KeywordAnalyzer to
make sure no lowercasing or stemming takes place.
2) OMIT_NORMs when indexing .. they only matter if you want the lengths
of fields to affect the score, and you don't -- you only want to know if
it matched or not.
3) if you want to require name="jeff" and age="33" make sure you
construct a query where all clauses are mandatory .. the default in the
query parser is "SHOULD" meaning only one clause is mandatory, and the
other clauses increase the score.
-Hoss
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: Query question
Posted by je...@sevajug.org.
Ah good question. The data that I am needing to query on is not a set
definition of tables or columns like a database is. Let me give two
examples:
1.) I have data like name="Jeff" lastname="Richley" age="33" and I need to
be able to query by any combination such as name="Jeff" age="33". But if
I query with name="Jeffrey" there is no match.
2.) The name value pairs are not really controlled until the end user is
inserting information or querying. I may have the data from the previous
example and then have another that has address information and then
something totally unrelated such as stock prices. The point is, I can't
guarantee what exactly will be in the data.
If you need any other information, let me know. I do realize that Lucene
may not really be a perfect fit. That is why I am doing my research
before the project gets ramped up. Once again, thanks for any help.
Jeff Richley
> An example (simplified, to be sure) would help a lot. What does a 100%
> match
> mean? Why do you care? What problem are you trying to solve? Why wouldn't
> a
> database server you better?
>
> Best
> Erick
>
> On 11/2/06, jeff.richley@sevajug.org <je...@sevajug.org> wrote:
>>
>> I am wanting to be able to put sets of data in a very structured way and
>> query Lucene for only 100% matches. Is there a way to do this? I seem
>> to
>> be getting back at best 0.30685282. I appreciate any help and insite.
>>
>>
>> Jeff Richley, Vice President
>> Southeast Virginia Java Users Group
>> jeff.richley@sevajug.org
>> http://www.sevajug.org
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
>> For additional commands, e-mail: java-user-help@lucene.apache.org
>>
>>
>
Jeff Richley, Vice President
Southeast Virginia Java Users Group
jeff.richley@sevajug.org
http://www.sevajug.org
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: Query question
Posted by Erick Erickson <er...@gmail.com>.
An example (simplified, to be sure) would help a lot. What does a 100% match
mean? Why do you care? What problem are you trying to solve? Why wouldn't a
database server you better?
Best
Erick
On 11/2/06, jeff.richley@sevajug.org <je...@sevajug.org> wrote:
>
> I am wanting to be able to put sets of data in a very structured way and
> query Lucene for only 100% matches. Is there a way to do this? I seem to
> be getting back at best 0.30685282. I appreciate any help and insite.
>
>
> Jeff Richley, Vice President
> Southeast Virginia Java Users Group
> jeff.richley@sevajug.org
> http://www.sevajug.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>