chriseldredge / Lucene.Net.Linq

LINQ provider to run native queries on a Lucene.Net index
Other
151 stars 66 forks source link

Can not find items with special chars -,(,), issue with build query #25

Closed mykhayloArtymyshyn closed 11 years ago

mykhayloArtymyshyn commented 11 years ago

when do search by MERSEDES-BENZ, lucene.net.linq builds query {text:mersedes-benz} and has no results, lucene luke builds {text:mersedes text:benz} and find all items

chriseldredge commented 11 years ago

Which Query Parser are you using in Luke?

mykhayloArtymyshyn commented 11 years ago

Luke splits MERSEDES-BENZ to 2 terms indepent on settings in QueryParser tab

chriseldredge commented 11 years ago

The Luke QueryParser behaves differently than the Lucene.Net QueryParser as you can see in these example tests:

using Lucene.Net.Analysis.Standard;
using Lucene.Net.QueryParsers;
using NUnit.Framework;
using Version = Lucene.Net.Util.Version;

namespace Lucene.Net.Linq.Tests.Integration
{
    [TestFixture]
    public class QueryParserTests
    {
        readonly QueryParser parser = new QueryParser(Version.LUCENE_30, "Text", new StandardAnalyzer(Version.LUCENE_30));

        [Test]
        public void TreatsHyphenAsExactPhrase()
        {
            var query = parser.Parse("MERSEDES-BENZ");
            Assert.That(query.ToString(), Is.EqualTo("Text:\"mersedes benz\""));
        }

        [Test]
        public void MultiWord()
        {
            var query = parser.Parse("MERSEDES BENZ");
            Assert.That(query.ToString(), Is.EqualTo("Text:mersedes Text:benz"));
        }
    }
}

This behavior is not specific to Lucene.Net.Linq. Perhaps the Lucene.Net users group can explain why it behaves differently.

Incidentally isn't the brand spelled Mercedes-Benz (with a "c", not an "s")?

mykhayloArtymyshyn commented 11 years ago

I'm not sure that is lucene.net behaviour. In the ReflectionFieldMapper.CreateQuery method(ln 142) I got mercedes-benz as pattern parameter instead of mercedes-benz (The same for \ instead of \ or ( instead of (). So in this method I use pattern.Replace("\", string.Empty) instead of pattern, and it start to work as I need. Thanks.