Matt
Matt

Reputation: 631

Do documents in Lucene have to contain the same fields?

I'm considering / working on implementing a search engine for our company's various content types, and am attempting to wrap my head around Lucene (specifically the .net flavor).

For the moment, my primary question is whether or not documents one indexes have to contain the same fields.

For instance:

Document1:

Document2:

...and so forth

Upvotes: 8

Views: 423

Answers (3)

RHT
RHT

Reputation: 5054

It all depends on how you have indexed your documents in Lucene. All Documents must be added to the Index. You can use IndexWriter or write your own class to do that. Before adding a document to the Index, you should break it up in name value pairs. Subsequently you can query Lucene for these name values using QueryParser. For example, following query will return all documents with the phrases "I'm a document, baby" in the title and "Here are some important things" in the body.

title:("I'm a document, baby") body:("Here are some important things")

I have just shown a simple example but you can create a more powerful search query, in many different ways.

The classes which I have mentioned are from java but .net should be similar.

Upvotes: 0

bmargulies
bmargulies

Reputation: 100032

Nothing in lucene forces uniformity.

If you search on a field named 'fred', and not all docs have 'fred,' that search will not find the fredless docs.

Upvotes: 15

Sands
Sands

Reputation: 547

If you wish to index on a specific field, I guess all documents must have the same fields.

Upvotes: 0

Related Questions