Solrj query

Hello everybody,

I need to query multiple values ​​by index (just like query sql (id1, id2, id3) sql) using SolrJ, in other words, I want to get documents whose fields correspond to a set of values.

Since solrj api is roughly documented, I expect someone to be able to help me

Hello

+5
source share
4 answers

You can do something like:

SolrQuery solrQuery = new SolrQuery().setQuery("myField:id1 OR myField:id2 OR myField:id3");
QueryResponse rsp = server.query(solrQuery);

or

SolrQuery solrQuery = new SolrQuery().setQuery("myField:(id1 OR id2 OR id3)");
QueryResponse rsp = server.query(solrQuery);
+6
source

In the schema conf / schema.xml definition file for the schema, you can specify the default operator, make sure it is OR:

<solrQueryParser defaultOperator="OR"/>

You can then separate the words with spaces in your query, and this will result in the words OR:

solrQuery.setQuery("myField:(id1 id2 id3)")
0
source

, Solr 5 , , :

String mQueryString="term:business OR term:\"information security\"";
SolrQuery query = new SolrQuery();
query.setQuery(mQueryString);
0

,

1- , StringUtils,

Set<String> pdfFamilies = new HashSet<String>();
String familyIdsString = StringUtils.join(pdfFamilies , 'OR');
solrQuery = new SolrQuery("FAM_ID: ( " + familyIdsString + " )");

2-Using SPACE as a separator between the values ​​below

Set<String> pdfFamilies = new HashSet<String>();
String familyIdsString = StringUtils.join(pdfFamilies , ' ');
solrQuery = new SolrQuery("FAM_ID: ( " + familyIdsString + " )");
0
source

All Articles