1
votes

I am new to Lucene.net ,Here I would like to know how to make a lucene search query almost like an sql query .Lemme give more..

I have set of parameter values,Let assume like a stored procedure has set of parameters .Now I want to build a query with all this parameters.

        searchParams.UseLast = Convert.ToBoolean(base.Arguments["UseLast"]);
        searchParams.LastEditedFrom= Convert.ToDateTime(base.Arguments["LastEditedFrom"]);
        searchParams.LastEditedTo = Convert.ToDateTime(base.Arguments["LastEditedTo"]);
        searchParams.Reviewed = Convert.ToBoolean(base.Arguments["Reviewed"]);
        searchParams.Approved = Convert.ToBoolean(base.Arguments["Approved"]);
        searchParams.Include = Convert.ToBoolean(base.Arguments["Include"]);
        searchParams.IsVisibleToUser = Convert.ToBoolean(base.Arguments["IsVisibleToUser"]);
        searchParams.IsEntry = Convert.ToBoolean(base.Arguments["IsEntry"]);
        searchParams.UserId = Convert.ToInt32(base.Arguments["UserId"]);

        IEnumerable Categories = base.Arguments["Categories"] as IEnumerable;
        IEnumerable Departments = base.Arguments["Departments"] as IEnumerable;

        String mQuery = "How to construct it ....!!!" // Need help in this 

        var query = queryParser.Parse(mQuery);
        indexSearcher.Search(query, collector);

Here I want to fetch all records from lucene index which has the value for all the above fields.

1

1 Answers

1
votes

I'm unclear what you are using searchParams for, however in general you may construct your query string (mQuery) in this cases with any of the features of the Lucene query syntax. Here is a link to the documentation for Lucene.Net version 4.8 Query Parser Syntax.

In general, when multiple words are listed in the query they are treated with a logical OR but doc matches that contain all terms are ranked higher than docs with only one term. So for example white dog would match docs containing white dog or white or dog. You can put and in the statement if you only want docs that match all the terms so for example you could say small and white and dog if you only want docs that contain all three terms.

To specify the specific field to search you list the field name followed by a colon. So for example you can search UserId:ron and Categories:dogs. There is much more to the Lucene query syntax but hopefully that will get you started. For more details see the Lucene query syntax doc I referred to.