Lucene.Net multi-user search across multiple fields and the use of wild cards and search phrases, search fuzzy

I am very new to lucene.net. I index data for multiple fields using lucene.net. so i made index data

                    Document doc = new Document();
                    doc.Add(new Field("ID", oData.ID.ToString() + "_" + oData.Type, Field.Store.YES, Field.Index.UN_TOKENIZED));
                    doc.Add(new Field("Title", oData.Title, Field.Store.YES, Field.Index.TOKENIZED));
                    doc.Add(new Field("Description", oData.Description, Field.Store.YES, Field.Index.TOKENIZED));
                    doc.Add(new Field("Url", oData.Url, Field.Store.YES, Field.Index.TOKENIZED));
                    writer.AddDocument(doc);

Now, when the user is searching, the user can enter data such as Audi BMW ECU

1) I want every word like [Audi] [BMW] [ECU] to have to look against i fields such as name, description, url. each word should look for three fields called title, description, url . so what do i need to do. what code i need to write.

2) for the second time, the phrase " Audi BMW ECU " should be in the search field for the title, description, URL .

3) can a user use a wildcard when searching, for example, Audi BMW ECU * or Audi BMW ECU? 4) I want to add a fuzzy search along with a search for several words, therefore, if the user spelling is incorrect, then the result will come.

please call me how I could combine all the logic and functionality in my code and routine as a result, I got the result of all kinds of user input.

if possible, discuss this issue in detail.

+5
source share
1 answer

QueryParser , , Lucene Query. MultiFieldQueryParser, , . , .

var fields = new[] { "Title", "Description", "Url" };
var analyzer = new StandardAnalyzer(Version.LUCENE_30);
var queryParser = new MultiFieldQueryParser(Version.LUCENE_30, fields, analyzer);
var query = queryParser.Parse("Audi BMW ECU");

(Title:audi Description:audi Url:audi) (Title:bmw Description:bmw Url:bmw) (Title:ecu Description:ecu Url:ecu).

, . Lucene.

var fields = new[] { "Title", "Description", "Url" };
var analyzer = new StandardAnalyzer(Version.LUCENE_30);
var queryParser = new MultiFieldQueryParser(Version.LUCENE_30, fields, analyzer);
var query = queryParser.Parse("\"Audi BMW ECU\"");

Title:"audi bmw ecu" Description:"audi bmw ecu" Url:"audi bmw ecu".

QueryParser , * ? . ; " ~ 0,5". , . Parser.

, , . , (, , ). , , . .

+12

All Articles