Re: Quick SolrJ query how-to question.

2013-05-14 Thread Jienan Duan
hi,
the solrQuery.setQuery() method just set the 'q' param in the query string.
You need call other method to set up all necessary param:
solrQuery.setFields(); --> this set up the 'fl' param
solrQuery.setStart(); --> this set up the 'start' param
solrQuery.setRows(); --> this set up the 'rows' param
solrQuery.setSort();  --> this set up the 'sort'param

You can look into
http://lucene.apache.org/solr/4_2_1/solr-solrj/org/apache/solr/client/solrj/SolrQuery.htmlto
see more details about SolrQuery.


2013/5/14 Luis Cappa Banda 

> Hello, guys!
>
> I would like to do something like this. Let's suppose we have:
>
> *
> *
> *(...) *
> *
> *
> *String query = "q=*:*&start=0&rows=20&sort=date%20desc";*
> *
> *
> *SolrQuery solrQuery = new SolrQuery();*
> *solrQuery.setQuery(query);*
> *
> *
> *server.query(solrQuery);*
> *
> *
> *(...)*
>
>
>
> I tried that and it fails. My question is: is it possible to define a
> SolrQuery with the complete REST encoded query String without parsing
> manually all the query parameters and using SolrQuery methods to set them?
>
> Regards,
>
> --
> - Luis Cappa
>



-- 
--
不走弯路,就是捷径。
http://www.jnan.org/


Re: Quick SolrJ query how-to question.

2013-05-14 Thread Jienan Duan
I don't see any method in SolrServer like what you want.But I think you
just need write some code with HttpClient ,make a http request use the
complete query string.

2013/5/14 Luis Cappa Banda 

> I know that, but I was wondering if it exists another way just to set the
> complete query (including q, fq, sort, etc.) embedded in a SolrQuery object
> as the same way that you query using some kind of RequestHandler. That way
> would be more flexible because you don't need to parse the complete query
> checking q, fg, sort... parameters one by one and setting them with
> setFields(), setStart(), setRows(), etcetera. Solr is doing that query
> parse internally when you execute queries with it's REST API and maybe
> there exist a way to re-use that functionality to just set a String to a
> SolrQuery and that SolrQuery does internally all the magic.
>
> Thanks in advance,
>
>
> 2013/5/14 Jienan Duan 
>
> > hi,
> > the solrQuery.setQuery() method just set the 'q' param in the query
> string.
> > You need call other method to set up all necessary param:
> > solrQuery.setFields(); --> this set up the 'fl' param
> > solrQuery.setStart(); --> this set up the 'start' param
> > solrQuery.setRows(); --> this set up the 'rows' param
> > solrQuery.setSort();  --> this set up the 'sort'param
> >
> > You can look into
> >
> >
> http://lucene.apache.org/solr/4_2_1/solr-solrj/org/apache/solr/client/solrj/SolrQuery.htmlto
> > see more details about SolrQuery.
> >
> >
> > 2013/5/14 Luis Cappa Banda 
> >
> > > Hello, guys!
> > >
> > > I would like to do something like this. Let's suppose we have:
> > >
> > > *
> > > *
> > > *(...) *
> > > *
> > > *
> > > *String query = "q=*:*&start=0&rows=20&sort=date%20desc";*
> > > *
> > > *
> > > *SolrQuery solrQuery = new SolrQuery();*
> > > *solrQuery.setQuery(query);*
> > > *
> > > *
> > > *server.query(solrQuery);*
> > > *
> > > *
> > > *(...)*
> > >
> > >
> > >
> > > I tried that and it fails. My question is: is it possible to define a
> > > SolrQuery with the complete REST encoded query String without parsing
> > > manually all the query parameters and using SolrQuery methods to set
> > them?
> > >
> > > Regards,
> > >
> > > --
> > > - Luis Cappa
> > >
> >
> >
> >
> > --
> > --
> > 不走弯路,就是捷径。
> > http://www.jnan.org/
> >
>
>
>
> --
> - Luis Cappa
>



-- 
--
不走弯路,就是捷径。
http://www.jnan.org/


Re: Quick SolrJ query how-to question.

2013-05-14 Thread Jienan Duan
Why are you parsing te response to a QueryResponse object? I think it's
much easier to parse a json format response to you business object.


2013/5/14 Luis Cappa Banda 

> Yeah, unfortunately that's what I'm doing right now, but parsing the
> resultant String from the HttpClient response into a QueryResponse seems to
> be imposible... I think that this would be a great feature to include in
> next Solr release. I'm sure that many people will find useful to execute
> raw String queries with SolrQuery instead setting manually that query into
> SolrQuery with the setters methods defined.
>
> Regards,
>
>
>
> 2013/5/14 Jienan Duan 
>
> > I don't see any method in SolrServer like what you want.But I think you
> > just need write some code with HttpClient ,make a http request use the
> > complete query string.
> >
> > 2013/5/14 Luis Cappa Banda 
> >
> > > I know that, but I was wondering if it exists another way just to set
> the
> > > complete query (including q, fq, sort, etc.) embedded in a SolrQuery
> > object
> > > as the same way that you query using some kind of RequestHandler. That
> > way
> > > would be more flexible because you don't need to parse the complete
> query
> > > checking q, fg, sort... parameters one by one and setting them with
> > > setFields(), setStart(), setRows(), etcetera. Solr is doing that query
> > > parse internally when you execute queries with it's REST API and maybe
> > > there exist a way to re-use that functionality to just set a String to
> a
> > > SolrQuery and that SolrQuery does internally all the magic.
> > >
> > > Thanks in advance,
> > >
> > >
> > > 2013/5/14 Jienan Duan 
> > >
> > > > hi,
> > > > the solrQuery.setQuery() method just set the 'q' param in the query
> > > string.
> > > > You need call other method to set up all necessary param:
> > > > solrQuery.setFields(); --> this set up the 'fl' param
> > > > solrQuery.setStart(); --> this set up the 'start' param
> > > > solrQuery.setRows(); --> this set up the 'rows' param
> > > > solrQuery.setSort();  --> this set up the 'sort'param
> > > >
> > > > You can look into
> > > >
> > > >
> > >
> >
> http://lucene.apache.org/solr/4_2_1/solr-solrj/org/apache/solr/client/solrj/SolrQuery.htmlto
> > > > see more details about SolrQuery.
> > > >
> > > >
> > > > 2013/5/14 Luis Cappa Banda 
> > > >
> > > > > Hello, guys!
> > > > >
> > > > > I would like to do something like this. Let's suppose we have:
> > > > >
> > > > > *
> > > > > *
> > > > > *(...) *
> > > > > *
> > > > > *
> > > > > *String query = "q=*:*&start=0&rows=20&sort=date%20desc";*
> > > > > *
> > > > > *
> > > > > *SolrQuery solrQuery = new SolrQuery();*
> > > > > *solrQuery.setQuery(query);*
> > > > > *
> > > > > *
> > > > > *server.query(solrQuery);*
> > > > > *
> > > > > *
> > > > > *(...)*
> > > > >
> > > > >
> > > > >
> > > > > I tried that and it fails. My question is: is it possible to
> define a
> > > > > SolrQuery with the complete REST encoded query String without
> parsing
> > > > > manually all the query parameters and using SolrQuery methods to
> set
> > > > them?
> > > > >
> > > > > Regards,
> > > > >
> > > > > --
> > > > > - Luis Cappa
> > > > >
> > > >
> > > >
> > > >
> > > > --
> > > > --
> > > > 不走弯路,就是捷径。
> > > > http://www.jnan.org/
> > > >
> > >
> > >
> > >
> > > --
> > > - Luis Cappa
> > >
> >
> >
> >
> > --
> > --
> > 不走弯路,就是捷径。
> > http://www.jnan.org/
> >
>
>
>
> --
> - Luis Cappa
>



-- 
--
不走弯路,就是捷径。
http://www.jnan.org/


Re: It seems a bug of deal with synonym.

2013-03-01 Thread Jienan Duan
Hi,liwei.
I have met this problem before,and my solution is expanding synonyms first
,then normalizing.For example,'北京市' and ‘北京’ are synonyms,in indexing
process,my programme convert them to '北京市',and in searching process do the
same logic.

In solr.SynonymFilterFactory,posIncreament between synonyms and original
token is 0,so you can use SynonymFilterFactory create a TokenSet for the
queryString,then normalize the synonyms in the tokenSet.

There is a piece of code,I think it may help you understand my solution:

// req is a SolrQueryRequest
Analyzer analyzer = req.getSchema().getQueryAnalyzer();
final TokenizerChain tokennizerChain = (TokenizerChain)
req.getSchema().getField("title").getType().getQueryAnalyzer();
SynonymFilterFactory sff = null;
for (TokenFilterFactory tf :
tokennizerChain.getTokenFilterFactories()) {
if (tf instanceof SynonymFilterFactory) {
sff = (SynonymFilterFactory) tf;
}
}
if (null == analyzer) {
return;
}

StringReader reader = new StringReader(qstr);
StringBuilder buffer = new StringBuilder(128);
Set tokenSet = new LinkedHashSet();
TokenStream tokens = null;
TokenStream sf = null;
try {
// analysis title field
tokens = analyzer.reusableTokenStream("title", reader);

if (sff != null) {
sf = sff.create(tokens);
sf.reset();
CharTermAttribute termAtt = (CharTermAttribute)
sf.getAttribute(CharTermAttribute.class);
PositionIncrementAttribute positionIncrementAttribute =
sf.getAttribute(PositionIncrementAttribute.class);
OffsetAttribute offsetAttribute =
sf.getAttribute(OffsetAttribute.class);
Set dumplicatedTokenSet = new HashSet();
while (sf.incrementToken()) {
final String token = (new
String(termAtt.toString())).toLowerCase();
final int posIncr =
positionIncrementAttribute.getPositionIncrement();
// *then you can normaizing the synonms to a standard
word*
}
}
}

Best Regards.


2013/3/1 liwei 

> in org.apache.solr.parser.SolrQueryParserBase, there is a function:
> "protected Query newFieldQuery(Analyzer analyzer, String field, String
> queryText, boolean quoted)  throws SyntaxError"
>
> The below code can't process chinese rightly.
>
> "  BooleanClause.Occur occur = positionCount > 1 && operator ==
> AND_OPERATOR ?
> BooleanClause.Occur.MUST : BooleanClause.Occur.SHOULD;
>
> "
>
> For example, “北京市" and “北京" are synonym, if I seach "北京市动物园", the expected
> parse result is "+(北京市 北京) +动物园", but actually it would be parsed to "+北京市
> +北京 +动物园".
>
> The code can process English, because English word is seperate by space,
> and only one position.
>
> In order to process Chinese, I think it can charge by position increment,
> but not by position count.




-- 
--
不走弯路,就是捷径。
http://www.jnan.org/


MySQL Exception: Communications link failure WITH DataImportHandler

2012-08-15 Thread Jienan Duan
Hi all:
I'm using DataImportHandler load data from MySQL.
It works fine on my develop machine and online environment.
But I got an exception on test environment:

> Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:
>> Communications link failure
>
>
>> The last packet sent successfully to the server was 0 milliseconds ago.
>> The driver has not received any packets from the server.
>
> at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
>> Method)
>
> at
>> sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
>
> at
>> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
>
> at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
>
> at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
>
> at
>> com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
>
> at com.mysql.jdbc.MysqlIO.(MysqlIO.java:343)
>
> at
>> com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2132)
>
> ... 26 more
>
> Caused by: java.net.ConnectException: Connection timed out
>
> at java.net.PlainSocketImpl.socketConnect(Native Method)
>
> at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
>
> at
>> java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
>
> at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
>
> at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
>
> at java.net.Socket.connect(Socket.java:529)
>
> at java.net.Socket.connect(Socket.java:478)
>
> at java.net.Socket.(Socket.java:375)
>
> at java.net.Socket.(Socket.java:218)
>
> at
>> com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:253)
>
> at com.mysql.jdbc.MysqlIO.(MysqlIO.java:292)
>
> ... 27 more
>
> This make me confused,because the test env and online env almost
same:Tomcat runs on a Linux Server with JDK6,MySql5 runs on another.
Even I wrote a simple JDBC test class it works,a jsp file with JDBC code
also works.Only DataImportHandler failed.
I'm trying to read Solr source code and found that it seems Solr has it's
own ClassLoader.I'm not sure if it goes wrong with Tomcat on some specific
configuration.
Dose anyone know how to fix this problem? Thank you very much.

Best Regards.

Jienan Duan

-- 
--
不走弯路,就是捷径。
http://www.jnan.org/


Re: MySQL Exception: Communications link failure WITH DataImportHandler

2012-08-16 Thread Jienan Duan
Hi all:
I have resolved this problem by configuring a jndi datasource in tomcat.
But I still want to find out why it throw an exception in DIH when I
configure datasource in data-configure.xml but a jndi resource.

Regards.

2012/8/16 Jienan Duan 

> Hi all:
> I'm using DataImportHandler load data from MySQL.
> It works fine on my develop machine and online environment.
> But I got an exception on test environment:
>
>> Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:
>>> Communications link failure
>>
>>
>>> The last packet sent successfully to the server was 0 milliseconds ago.
>>> The driver has not received any packets from the server.
>>
>> at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
>>> Method)
>>
>> at
>>> sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
>>
>> at
>>> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
>>
>> at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
>>
>> at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
>>
>> at
>>> com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
>>
>> at com.mysql.jdbc.MysqlIO.(MysqlIO.java:343)
>>
>> at
>>> com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2132)
>>
>> ... 26 more
>>
>> Caused by: java.net.ConnectException: Connection timed out
>>
>> at java.net.PlainSocketImpl.socketConnect(Native Method)
>>
>> at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
>>
>> at
>>> java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
>>
>> at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
>>
>> at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
>>
>> at java.net.Socket.connect(Socket.java:529)
>>
>> at java.net.Socket.connect(Socket.java:478)
>>
>> at java.net.Socket.(Socket.java:375)
>>
>> at java.net.Socket.(Socket.java:218)
>>
>> at
>>> com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:253)
>>
>> at com.mysql.jdbc.MysqlIO.(MysqlIO.java:292)
>>
>> ... 27 more
>>
>> This make me confused,because the test env and online env almost
> same:Tomcat runs on a Linux Server with JDK6,MySql5 runs on another.
> Even I wrote a simple JDBC test class it works,a jsp file with JDBC code
> also works.Only DataImportHandler failed.
> I'm trying to read Solr source code and found that it seems Solr has it's
> own ClassLoader.I'm not sure if it goes wrong with Tomcat on some specific
> configuration.
> Dose anyone know how to fix this problem? Thank you very much.
>
> Best Regards.
>
> Jienan Duan
>
> --
> --
> 不走弯路,就是捷径。
> http://www.jnan.org/
>
>


-- 
--
不走弯路,就是捷径。
http://www.jnan.org/


Re: MySQL Exception: Communications link failure WITH DataImportHandler

2012-08-16 Thread Jienan Duan
It happens immediately upon connection,the jdbc string is correct.
This problem only happens when DIH trying get a connection to mysql,the
network and database server are fine.
So I guess it caused by some security configuration on the server and that
config has blocked the connection.
But other app's jdbc connection and Tomcat's JNDI datasource are
insusceptible.
PS: I use Solr 3.5

Regards.

2012/8/17 Gora Mohanty 

> On 16 August 2012 14:07, Jienan Duan  wrote:
> > Hi all:
> > I have resolved this problem by configuring a jndi datasource in tomcat.
> > But I still want to find out why it throw an exception in DIH when I
> > configure datasource in data-configure.xml but a jndi resource.
> [...]
>
> When does this error happen? Immediately upon connection,
> or randomly at some point of time. If the former, double
> check your mysql configuration string.
>
> With Solr 1.4, we occasionally saw DIH connection failures
> to the database, but those were rare, probably attributable
> to network issues, and largely went away when:
>   (a) We first moved to a different JDBC driver
>   (b) Moved from SQL server to mysql.
> Is it possible that there are network issues between your live
> Solr and the database server? Are you monitoring the load
> on the database server, and the volume of network traffic?
>
> Regards,
> Gora
>



-- 
--
不走弯路,就是捷径。
http://www.jnan.org/


Re: How to implement Index time boost via DIH?

2012-08-16 Thread Jienan Duan
Hi
Why don't you do this at the searching time?ex:
q=fullName:foo+lastUpdatedBy:bar&qf=fullName^2+lastUpdatedBy^0.5

2012/8/17 bbarani 

> Hi,
>
> I am trying to implement index time boost via DIH. but I want to boost at
> field level rather than document level. Ex:
>
> Consider there are 2 fields in a document: LastUpdatedBy, fullName. After
> indexing both the fields, I am copying the data from both the field in to a
> default search field. Now when search happens on default search field I
> want
> fullNameto get more priority than LastUpdatedBy even though both might have
> the search keyword.
>
> Note: I have tried dismax handler before for runtime boosting, want to try
> index time boosing using DIH.
>
> Thanks!!!
>
> Thanks,
> BB
>
>
>
> --
> View this message in context:
> http://lucene.472066.n3.nabble.com/How-to-implement-Index-time-boost-via-DIH-tp4001720.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>



-- 
--
不走弯路,就是捷径。
http://www.jnan.org/