2

I have a need to create a specific index to perform a search on a particular field from an inherited template. That part of creating the index and returning matching results is fairly straight forward.

The issue I am having is that when doing a search that would not be an intended match for the field, I am getting false results because the Lucene.NET document field '_name' contains the search criteria and is considering that a match.

I am using the Advanced Database Crawler, and have gone as far in the investigation to exclude almost every field possible until I used Luke to uncover the problem.

How can I exclude document fields such as '_name' from being searchable to exclude this situation from returning the results not intended?

Patrick Jones
  • 1,896
  • 14
  • 26
mservais
  • 570
  • 1
  • 7
  • 20
  • Currently used a field level search parameter in ADC to workaround the issue. Still would be great to know if the exclusion is still possible. – mservais Nov 05 '12 at 20:07

1 Answers1

0

Lucene documents have a RemoveField method. In your custom DatabaseCrawler you could normally remove fields from the document:

public class MyCustomCrawler : Sitecore.Search.Crawlers.DatabaseCrawler
{
        protected override void AddAllFields(Lucene.Net.Documents.Document document, Sitecore.Data.Items.Item item, bool versionSpecific)
        {
            document.RemoveField("SomeFieldName");
            ...
        }
}

In this case the fields are added after "AddAllFields'. It happens in "AddSpecialFields", so you can do something like this:

protected override void AddSpecialFields(Document document, Sitecore.Data.Items.Item item)
{
    // Do nothing, don't call base.AddSpecialFields
}
Patrick Jones
  • 1,896
  • 14
  • 26
  • Wouldn't physically removing the field '_name' from the document cause some issues for Lucene? While this will stop the field from being searched, I would think it would also remove a key identifiable field from Lucene. – mservais Dec 16 '12 at 04:29
  • It did not cause any issue in my tests, or in other indexes I have used that had no need for that field. This is something Sitecore's base DatabaseCrawler does, not something Lucene depends on. – Patrick Jones Dec 22 '12 at 02:26