1

i got the following code:

Lucene.Net.Analysis.Analyzer analyzer = new Lucene.Net.Analysis.Standard.StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29);

    var mainQuery = new Lucene.Net.Search.BooleanQuery();

    foreach (var str in fields)
    {
        var parser = new Lucene.Net.QueryParsers.QueryParser(Lucene.Net.Util.Version.LUCENE_29, str, analyzer);
        mainQuery.Add(parser.Parse(search +"*"), Lucene.Net.Search.BooleanClause.Occur.SHOULD);
    }

    Lucene.Net.Search.TopScoreDocCollector collector = Lucene.Net.Search.TopScoreDocCollector.create(21, true);

    searcher.Search(mainQuery, collector);
    hits = collector.TopDocs().scoreDocs;

and life was good. until i noticed, that i get results that are also NotActive. so i said to myself, ok , no problem, lets add another query to the mainQuery just after the for loop like so:

var parser2 = new Lucene.Net.QueryParsers.QueryParser(Lucene.Net.Util.Version.LUCENE_29, "StateProperties.IsActive", analyzer);
    mainQuery.Add(parser2.Parse("True"), Lucene.Net.Search.BooleanClause.Occur.MUST);

unfortunally, this does not work. anyone can point me to the right direction of doing this ? i have read about filters, and even managed to apply one, but then i lose the scores ( well, not really lose, but they are way off the original query ). i also read about TermQueryWrapper, but could not find how to implement that ( so i dont know if thats what i need, even due it seems to be the right direction ).

EDIT: i forgot to mention, all the fields in fields are ANALYZED, the StateProperties.IsActive is NOT_ANALYZED.

Rafael Herscovici
  • 16,558
  • 19
  • 65
  • 93
  • I've never been familiar with the 2.X syntax for Lucene, I got started with 3. But the approach of adding another boolean query should work. I've certainly used that approach before. When you say it doesn't work, does this mean that it doesn't restrict as it should? Or that you get nothing back? – dnuttle Nov 24 '11 at 13:07
  • `Title:sinatra +StateProperties.IsActive:True` returns all documents ( except the "Sinatra" document, which its active state is false ). on the other hand, `Title:sinatra +StateProperties.IsActive:False` returns no documents, even due i KNOW that there is a doc named "sinatra" and its IsActive value is False. btw, how did you start with lucene 3 ? since all i see in the website is Lucene.Net 2.9.2 ? – Rafael Herscovici Nov 24 '11 at 13:16
  • Sorry, should have mentioned, I work in java rather than .NET, at least when it comes to lucene. – dnuttle Nov 24 '11 at 14:04
  • 1
    Are you familiar with Luke? http://www.getopt.org/luke/ Try getting that to look at your data directly. I've said, "I know that there is a record..." before and been wrong. From what I can see here, my guess is that your assumptions about your indexed data must have a mistake. For example, could the value be "false" instead of "False"? You said the field is not analyzed, so it would have to be an exact match. And/or are you using an analyzer that might change the query? Generally, if you use an analyzer on one searchable field, then it should be used on all of them. – dnuttle Nov 25 '11 at 13:10
  • i am familier with luke, and have verified that the document exists exactly as i search for it, its Title is "Sinatra" and the IsActive value is False. i am using the standard analayzer, and using only one instance of it. – Rafael Herscovici Nov 26 '11 at 08:10
  • What I meant is that, you said that the StateProperties.IsActive field is not analyzed, but you are using an analyzer when you search. I suspect that this is the root of the problem. Can you try re-indexing, and using the analyzer on this field as well, to see if the result changes? – dnuttle Nov 26 '11 at 11:57
  • i have tried that, with same results – Rafael Herscovici Nov 28 '11 at 10:29

0 Answers0