This project is read-only.

Multiple field searches

Aug 20, 2008 at 4:24 PM
This might be my misunderstanding of the docs, but I'm having trouble getting a multiple field query to work.  I'm also curious how to rank the results, if I wanted one field to count for more than the other in an intermixed fashion (e.g. tiebreaker kind of boost).

The query I attempted was based on one of the examples (I thought), and looked like so:



mmCustomers = dbi.Get<Customer>().Where(c => (c.ContactTitle.Match(new string[]{"marketing","manager"})) || (c.Address.Match(new string[]{"rue"})));


where dbi is an instance of my DatabaseIndexSet<NorthwindDataContext> (for learning off of).  the first part of the query works fine by itself, the exception started when I added in the OR logic (||) to try and bring in the other field. 

any thoughts?

the exception I got was:
Lucene.Net.QueryParsers.ParseException was unhandled
  Message="Encountered \":\" at line 1, column 59.\nWas expecting one of:\n    <AND> ...\n    <OR> ...\n    <NOT> ...\n    \"+\" ...\n    \"-\" ...\n    \"(\" ...\n    \")\" ...\n    \"^\" ...\n    <QUOTED> ...\n    <TERM> ...\n    <FUZZY_SLOP> ...\n    <PREFIXTERM> ...\n    <WILDTERM> ...\n    \"[\" ...\n    \"{\" ...\n    <NUMBER> ...\n    "
       at Lucene.Net.QueryParsers.QueryParser.Jj_consume_token(Int32 kind) in C:\downloads\lucene\Lucene.Net\QueryParser\QueryParser.cs:line 1412
       at Lucene.Net.QueryParsers.QueryParser.Clause(String field) in C:\downloads\lucene\Lucene.Net\QueryParser\QueryParser.cs:line 884
       at Lucene.Net.QueryParsers.QueryParser.Query(String field) in C:\downloads\lucene\Lucene.Net\QueryParser\QueryParser.cs:line 801
       at Lucene.Net.QueryParsers.QueryParser.Parse(String query) in C:\downloads\lucene\Lucene.Net\QueryParser\QueryParser.cs:line 154
       at Lucene.Linq.Expressions.ParsingQueryTranslator.Translate(String query, String[] defaultFieldNames) in C:\downloads\lucene\Lucene.Linq\Expressions\ParsingQueryTranslator.cs:line 73
       at Lucene.Linq.Expressions.ParsingQueryTranslator.Translate(Expression expression) in C:\downloads\lucene\Lucene.Linq\Expressions\ParsingQueryTranslator.cs:line 51
       at Lucene.Linq.Expressions.QueryProvider.Translate(Expression expression) in C:\downloads\lucene\Lucene.Linq\Expressions\QueryProvider.cs:line 193
       at Lucene.Linq.Expressions.QueryProvider.Execute(Expression expression) in C:\downloads\lucene\Lucene.Linq\Expressions\QueryProvider.cs:line 67
       at Lucene.Linq.Expressions.QueryProvider.System.Linq.IQueryProvider.Execute[S](Expression expression) in C:\downloads\lucene\Lucene.Linq\Expressions\QueryProvider.cs:line 58
       at System.Linq.Queryable.Count[TSource](IQueryable`1 source)
       at First_Lucene.Program.Main(String[] args) in C:\Documents and Settings\pvencill\My Documents\Visual Studio 2008\Projects\First Lucene\First Lucene\Program.cs:line 23
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
Aug 20, 2008 at 5:05 PM
Edited Aug 20, 2008 at 5:07 PM

Ok, this was me being an idiot.  Seems that I didn't put in metadata mapping info for the Address field, which is what was throwing the error.  my mistake, sorry to bother you all.  :D 

I'd still like to udnerstand how ranking works in these situations, though.  Basically, i'd like to be able to do a Boost on a class of terms, rather than on individual terms.  e.g. boost a field's weight, vice boosting a term's weight, if I'm clear.




Aug 21, 2008 at 6:40 AM
Boosting fields happens at Index time. This will naturally give certain fields higher importance over others.

FieldAttribute should have a boost property on it, which is settable on the property itself.

[Field(Type=Blah, Boost = 3.0f)]
object MyField {get;set;}

I remember putting the stub in, and vaguely remember adjusting the indexer to use the supplied boosts. What I definitely did not do is add a Unit test, which should be something to do.

Try this out Paul, if the Boost property isn't there, please add a issue in the tracker and I'll add it later. You're also free to submit a patch.

Aug 21, 2008 at 6:42 AM
Just added this issue