use query to set filter on fields

2011-01-04 Thread Raymi

Hi,

I'm evaluating SOLR and have a question about query processing. Is it 
possible to set filters on fields according to the terms entered in the 
query? I know that I can use dismax to search in multiple fields. 
However, what I want to achieve for a given query is the following:

 - parse all terms in the query
 - determine values of different fields that match these terms
 - set filters for these values
 - return all documents matching the filters

Example:
documents representing cars with fields "manufacturer" and "color"
query for "red ford" sets filters manufacturer=ford, color=red

One can then use faceted navigation to further drill down.

Is this possible with SOLR?

Thanks.
Cheers,

Dominik


Re: use query to set filter on fields

2011-01-04 Thread Raymi

I'm evaluating SOLR and have a question about query
processing. Is it possible to set filters on fields
according to the terms entered in the query? I know that I
can use dismax to search in multiple fields. However, what I
want to achieve for a given query is the following:
  - parse all terms in the query
  - determine values of different fields that match these
terms
  - set filters for these values
  - return all documents matching the filters

Example:
documents representing cars with fields "manufacturer" and
"color"
query for "red ford" sets filters manufacturer=ford,
color=red

One can then use faceted navigation to further drill down.


So do you have an existing java program that recognizes red as color and ford 
as manufacturer? And


No, I don't.
But since I'll store documents in solr having "color" set to "red", 
"green", "blue" and "manufacturer" set to "ford", "bmw" etc. the 
information is available.




Re: use query to set filter on fields

2011-01-04 Thread Raymi

No, I don't.
But since I'll store documents in solr having "color" set
to "red",
"green", "blue" and "manufacturer" set to "ford", "bmw"
etc. the
information is available.


Okey information is available but the difficult part is recognize those things 
from the free form text query. There is no such mechanism is Solr.

If you can build such program, you can inject it to solr using a custom solr 
plugin.



I'm not sure, whether I made myself very clear. I don't think that it is 
difficult to evaluate the query. Here's a (very inefficient) algorithm 
in pseudocode that would do, what I have in mind:


query = ...

foreach (term in query)
  foreach (field in SOLR.config.fields)
result = SOLR.query(field:term)
if result.size > 0
  filters.addFilter(field=term)
  break
end
  end
end

return SOLR.filter(filters)


Re: use query to set filter on fields

2011-01-04 Thread Raymi

I'm not sure, whether I made myself very clear. I don't
think that it is difficult to evaluate the query. Here's a
(very inefficient) algorithm in pseudocode that would do,
what I have in mind:

query = ...

foreach (term in query)
   foreach (field in SOLR.config.fields)
 result = SOLR.query(field:term)
 if result.size>  0
   filters.addFilter(field=term)
   break
 end
   end
end

return SOLR.filter(filters)


Okey if you have already something, I think simplest place to put this is a 
custom search handler. http://wiki.apache.org/solr/SolrPlugins
Other option can be QParserPlugin.


public final class CustomSearchHandler extends SearchHandler {

@Override
   public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) 
throws IOException, ParseException, InstantiationException, 
IllegalAccessException {


   ModifiableSolrParams solrParams = new   
ModifiableSolrParams(req.getParams());
   String query = req.getParams().get(CommonParams.Q, "*:*");

foreach (term in query)
foreach (field in SOLR.config.fields)  =>  
http://wiki.apache.org/solr/LukeRequestHandler
  result = SOLR.query(field:term)
  if result.size>  0
filters.addFilter(field=term)  =>  solrParams.add(CommonParams.FQ, 
"field:term");
break
  end
end
  end

  req.setParams(solrParams);
  super.handleRequestBody(req, rsp);
}


Ok. Thank you very much for your help and the starting points. I'll give 
it a try. Maybe I come up with a smarter way than my "brute force" 
algorithm.