Get available values from specific field

For example, if I have got a field in my lucene index that is called, say "color". And of course it's value differs.

Then i have a "Advanced search page" with a dropdown, in that dropdown I would like to display all the available values (distinct) that the "color" field contains.

Lucene version is Version.LUCENE_29.

EDIT: Found a solution, Find all available values for a field in lucene .net

   private List<string> GetAvailableFields(string fieldName)
       List<string> fieldValues;

       using (var readerRepository = new LucineRepository(RepositoryPath))
           var reader = readerRepository.Reader;
           fieldValues = reader.UniqueTermsFromField(fieldName).ToList(); 

       return fieldValues;

public static class ReaderExtentions
    public static IEnumerable<string> UniqueTermsFromField(this IndexReader reader, string field)
        var termEnum = reader.Terms(new Term(field));

            var currentTerm = termEnum.Term();

            if (currentTerm.Field() != field)
                yield break;

            yield return currentTerm.Text();
        } while (termEnum.Next());

Cheers, Tommy.


Lucene doesn't provide 'distinct' functionality.

you have to write your own code to achieve that

you can try the below code snippet:

var document = new Document();
document.Add(new Field("color", "foo", Field.Store.YES, Field.Index.NOT_ANALYZED));

TermEnum terms = indexReader.Terms(new Term("color"));
// enumerate the colors

Need Your Help

Mobile redirect with full link to go to full site

javascript html

I would like to finally find a solution for this with maybe some steps. i have the below javascript to point to a mobile site. and this works well.

How to get model data annotations to implement application validation without implementing at DB level as well using EF? entity-framework validation entity-framework-4

I like the idea of using the data annotations to specify validation of fields within the Model. However in EF I notice that it wants to implement this at DB level ie [Required] becomes a "not null"...