Search by fields in Lutsen

I am a complete noobie with Lucene and still a huge, huge fan.

Now I am looking for resources to store data and search through C # and dotnet. Any LINQ samples will be a big bonus for me.

In particular, if I have a document that has two fields defined as a title and description, how can I search in both?

in the example below, I would like to search for both headers and description fields.

eg:

doc = new Document(); text = "Oven leek pie"; doc.Add(new Field("title", text, Field.Store.YES, Field.Index.TOKENIZED)); doc.Add(new Field("instructions", "Bake for 40 minutes", Field.Store.YES, Field.Index.TOKENIZED)); iwriter.AddDocument(doc); 

and then;

  // Parse a simple query that searches for "text": Lucene.Net.QueryParsers.QueryParser parser = new QueryParser("title", analyzer); Query query = parser.Parse("baked bacon and leek pizza"); 
+7
source share
2 answers
 string[] fields = new string[2]; fields[0] = "title"; fields[1] = "instructions"; Lucene.Net.QueryParsers.MultiFieldQueryParser multiFieldParser = new MultiFieldQueryParser(fields, analyzer); Query multiFieldQuery = multiFieldParser.Parse("20"); Hits multiHits = isearcher.Search(multiFieldQuery); 
+10
source share

There are many ways to search fields in Lucene. Sam Doshi describes somewhat in this answer to another StackOverflow question: How do I enable multiple fields in QueryParser?

+2
source share

All Articles