vvekselva
vvekselva

Reputation: 823

Lucene Indexing

In my lucene index documents I've three fields viz first name, middle name and last name. So if a search is made it should be performed in any of the fields in the index. So instead of maintaining two separate indexes, (one with full contexts - with concatenated strings of the three fields like all index and another with separate fields.) I've used only the latter approach i.e. I've maintained only the index with separate fields. So if a search text is submitted then three separate term queries are combined and the search is made with the combined boolean query. So if the search text matches any of the fields then the search result would be obtained. Now the problem is if the search text is with spaces in between, with first-name as the first word and the middle name as the last word, how to accomplish this search using the index with the separate fields. Is there are any ways to accomplish this?

Upvotes: 0

Views: 270

Answers (1)

naresh
naresh

Reputation: 2113

You need not maintain two separate indexes. Have a single index with four fields:

  1. first name
  2. middle name
  3. last name
  4. full name (full name is indexed as part of this field)

Let the default search field be full name and if users want to narrow it down further, they can issue queries on first/middle/last name fields as well.

Upvotes: 1

Related Questions