Hi,
thank you for your reply.

What you suggested is a good idea and I am probably going to follow it.

However, I'd like to hear a comment on the approach of doing the parsing
using Lucene and then constructing a SolrQuery from a Lucene Query:

  QueryParser parser = new QueryParser("", analyzer);
  Query lucene_query = parser.parse("title:dog title:The author:me
author:the the cat is on the table");
  ...
  SolrQuery solr_query = new SolrQuery();
  solr_query.setQuery(lucene_query.toString());

What are the drawbacks of this approach?

Similarly, at indexing time:

  StringBuffer solr_value = new StringBuffer();
  TokenStream ts = analyzer.tokenStream("title", new StringReader(value));
  Token token;
  while ((token = ts.next()) != null) {
    solr_value.append(token.termText()).append(" ");
  }
  SolrInputDocument solr_document = new SolrInputDocument();
  solr_document.addField("title", solr_value.toString());
  ...

What are the drawbacks of this approach?

Paolo


Chris Hostetter wrote:
: : The "source" of my problems is the fact that I do not know in advance the
: field names. Users are allowed to decide they own field names, they can,
: at runtime, add new fields and different Lucene documents might have
: different field names.

I would suggest you abstract away the field names your users pick and the underlying fieldnames you use when dealing with solr -- so create the list of fieldTypes you want to support (with all of the individual analzyer configurations that are valid) and then create a dynamicField corrisponding to each one.

then if your user tells you they want an "author" field associated with the type "text_en" you can map that in your application to "author_text_end" at both indexing and query time.

This will also let you map the same "logical field names" (from your user's perspective) to different "internal field names" (from Solr's perspective) based on usage -- searching the "author" field might be against "author_text_en" but sorting on "author" might use "author_string".

(Some notes were drafted up a while back on making this kind of field name aliasing a feature of Solr, but nothing ever came of it...
  http://wiki.apache.org/solr/FieldAliasesAndGlobsInParams
)

-Hoss

Reply via email to