2

I create query by QueryParser:

QueryParser parser = new QueryParser(Version.LUCENE_30, "Text", new RussianAnalayzer());
parser.setDefaultOperator(QueryParser.Operator.AND);
Query query = parser.parse(searchString);

When I use the phrase where the words have variations, I'm getting the united with "AND", like: "term1 term2" -> "term1 AND "term2_1 AND term2_2"". How can I get query like : "term1 AND "term2_1 OR term2_2"" without splitting string for words?

Great thanks.

KhCO
  • 73
  • 1
  • 6

1 Answers1

0

I'm not entirely sure I understand you. How is term2 split into multiple terms? Is it just a list of terms stored in a variable that you're talking about, something like: term1 = "term1" term2 = "term2_1 term2_2" query = term1 + " " + term2;

Or is it really only two terms, which are split up automatically (by the analyzer or something perhaps)?

At any rate, I think it would probably serve your purpose to change the second line given to:

parser.setDefaultOperator(QueryParser.Operator.OR);
//Or just delete this line if you prefer, OR is the default behavior.

and pass a query that makes sense given that behavior, such as:

"term1 AND (term2)"

Which is, presumably, equivalent to:

"term1 AND (term2_1 term2_2)"
femtoRgon
  • 32,893
  • 7
  • 60
  • 87
  • Thanks for the answer. RussianAnalayzer() converts term2 in variation(normal form) of this word in russian language like : красная -> красная красный. And when I give sentence for Lucene I need get a result query like union all the word of sentence but variant of word must be union by OR. When I give a sentence I don't know which of the word have variant. If I put AND in sentence manually and then give in QueryParser whith DefaultOperator OR in result I get all the same "term1 AND "term2_1 AND term2_2"" – KhCO Nov 08 '12 at 11:37
  • That sounds like an issue with the RussianStemmer, I think. I'm noticing some complaints about the RusianAnalyzer, I'd see if you see the same issue using a different analyzer. A couple of alternatives are posted in answer to this question: http://stackoverflow.com/questions/63896/analyzer-for-russian-language-in-lucene-and-lucene-net – femtoRgon Nov 08 '12 at 18:10
  • Just for fun, you could also try using '+' instead of 'and', like "+term1 +term2" instead of "term1 AND term2", but those two should be identical, and I have no reason to believe it would work any differently. Just might be worth a quick look. – femtoRgon Nov 08 '12 at 18:17
  • Thanks for your help. For this time the best alternative for me it's that I had override the QueryParser. (Different way is to use RussianLuceneMorphology and not use QueryParser) – KhCO Nov 09 '12 at 11:41