Domanda

I am attempting to do a query in RavenDB using the Search method, but I am running into an issue in that it completely ignores the KeywordAnalyzer set up. So in a situation where I have ...

  • Item 1
  • Item 2
  • Item 3

Trying to search for "Item 1" pulls up all three items, despite having set the analyzer on the name field to be the KeywordAnalyzer, like this ...

Map = items => from item in items
               select new Result {
                   Id = item.Id,
                   Name = item.Name
               };

Index(i => i.Name, FieldIndexing.Analyzed);
Analyze(n => n.Name, "KeywordAnalyzer");

At which point, I use the index like this;

var results = RavenSession
    .Query<Models.Items.Item, Indexes.Item__ByName>()
    .Customize(c => c.WaitForNonStaleResults())
    .Search(n => n.Name, name)
    .ToList();

My expectations are that when I search for "Item 1", I only get back "Item 1". Not all of the other items. But this just does not seem to be listening to me.

È stato utile?

Soluzione

This is because you have 2 conflicting definitions:

Index(i => i.Name, FieldIndexing.Analyzed);
Analyze(n => n.Name, "KeywordAnalyzer");

The first tells it to use StandardAnalyzer, the second KeywordAnalyzer.

Remove the first line and you're set.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top