1

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.

Ciel
  • 4,290
  • 8
  • 51
  • 110

1 Answers1

4

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.

synhershko
  • 4,472
  • 1
  • 30
  • 37
  • Unfortunately this did not work. It still uses the various individual parts of the word. – Ciel Jan 28 '14 at 19:25
  • The query works properly when done in the Raven administration interface; If I type in "1", it only pulls up `Item `'. But in the actual code running, with exactly what I showed you above, it still finds the other two items. – Ciel Jan 28 '14 at 19:29
  • This, in itself, is an evidence that this field is not using KeywordAnalyzer. KeywordAnalyzer will not be able to find "Item 1" given "1" as a query. – synhershko Jan 29 '14 at 09:00
  • I am going to try and make a failing test. – Ciel Jan 29 '14 at 18:08
  • Hey there, I have produced a failing test, as promised: https://gist.github.com/ciel/141f2d70ede4dff55fe9 – Ciel Jan 30 '14 at 16:40
  • I'm pretty sure its caused by the fix to this bug: http://issues.hibernatingrhinos.com/issue/RavenDB-1526 . For now use `.Where(x => ..)` instead of search, and if you feel like it report this as a bug to the mailing list or the tracker. – synhershko Jan 30 '14 at 19:34
  • I was under the understanding that search was not respective of how many documents you tried to pull, but "Where" only looked at the immediate ones that are taken; is this still true? There are situations where I need to try and find one or two documents when there are thousands more to search through than I can actually return in a single query. – Ciel Jan 30 '14 at 19:42
  • 1
    The only difference between Where and Search is related to analysis of the text being used to query, they both will respect the query size operators the same. – synhershko Jan 30 '14 at 20:02
  • Thank you, this answers a lot. I had avoided using `Where` because I was under the (incorrect) assumption that it only worked on the amount of results actually taken, where `Search` would go through all of the documents and then return up to the amount of results requested. – Ciel Feb 01 '14 at 14:47
  • Though this confuses me; If `Where` does this, what is the purpose of `Search`? – Ciel Feb 01 '14 at 14:47