On 5 May 2010 14:19, Erik Hatcher <erik.hatc...@gmail.com> wrote:
> But, I think you need to elaborate on what you're doing in your Lucene
> application to know more specifically.

Hi Erik,
perhaps, this is another way to explain and maybe solve my issue...

At query time (everything here is just an illustrative example):

  PerFieldAnalyzerWrapper analyzer =
    new PerFieldAnalyzerWrapper(new WhitespaceAnalyzer());
      analyzer.addAnalyzer("title", new SimpleAnalyzer());
      analyzer.addAnalyzer("author", new StandardAnalyzer());
      ...

  // Lucene is doing the analysis client side...
  QueryParser parser = new QueryParser("", analyzer);
  Query lucene_query = parser.parse("title:dog title:The author:me
author:the the cat is on the table");
  ...
  // Solr query is build from the query string analyzed by Lucene
  SolrQuery solr_query = new SolrQuery();
  solr_query.setQuery(lucene_query.toString());

This way, I don't need to do the per field analysis over dynamic
fields with Solr (on the server side).

Similarly, but a little bit more involuted, at indexing time:

  String value = "The CAT is on the table";

Instead of (i.e. Lucene legacy/old existing application):

  IndexWriter writer = new IndexWriter(directory, analyzer);
  Document lucene_document = new Document();
  Field field = new Field("title", value, Field.Store.YES,
Field.Index.TOKENIZED);
  lucene_document.add(field);
  writer.addDocument(lucene_document);

I will do something like:
                
  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 do you think?

Thanks again,
Paolo

Reply via email to