0

I have a MySQL DB indexed with Solr, and for my purpose I need to query the data inside this DB. I'd like to perform "soft" query, like every search engine on the web.

I'm trying to set two sample field inside schema.xml

<uniqueKey>organization_id</uniqueKey>

<field name="organization_id" type="string" indexed="true" stored="true" required="true"/>
<field name="name" type="string" indexed="true" stored="true"/>

This is my solrconfig.xml

<requestHandler name="/dataimport"
 class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
  <str name="config">data-config.xml</str>
</lst>
</requestHandler>

And, finally, data-config.xml

<dataConfig> <dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost/organizations2" user="****" password="****" /> <document name="content"> <entity name="id" query="SELECT * FROM organization" deltaImportQuery="SELECT * FROM organization" deltaQuery="SELECT * FROM organization"> <field column="organization_id" name="organization_id" /> <field column="name" name="name" /> </entity> </document> </dataConfig>

It's possible to make classic query, with a similar organization name, and then return the correct company? I'm trying to search all day but no solution.

Thanks a lot

Fabio
  • 159
  • 1
  • 4
  • 13

1 Answers1

0

First ensure the solr instance is running by checking the solr Admin at 8983 port.

Next is to see if you are able to search from solr Admin query screen.

The name field in schema.xml can be "text_string" instead of "string" to support LIKE queries.

Since i am not sure if you are looking for a way to search from Java program based on the question, following lists the options to search from Java: You can search from Java using Apache's solrj package or through URLOpener+InputStreamReader+xpath combination.

Sample java snippet using solrj to search for data:

HttpSolrServer solr = new HttpSolrServer("http://localhost:8983/solr");
SolrQuery query = new SolrQuery();
query.setQuery("company name");

Sample java snippet using URLOpener+InputStreamReader+xpath to search for data:

String solrQuery = "http://localhost:8983/solr/select/?q=company name";
URLOpener uop = new URLOpener();
URLConnection conn= uop.openURL(solrQuery);
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
//Read the contents into string variable qryContent
Document xmlDocument = 
DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(
new ByteArrayInputStream(qryContent.getBytes()));
XPath xPath =  XPathFactory.newInstance().newXPath();
XPathExpression xPathExpression = xPath.compile(expression);
String titleExpression = "/response/result/doc/arr[@name='name']/str";
NodeList allTitleNodes = 
(NodeList)xPathExpression.evaluate(titleExpression,XPathConstants.NODESET);
Community
  • 1
  • 1
bprasanna
  • 2,423
  • 3
  • 27
  • 39
  • Yes, I'm looking for a way to search from a Java program, in particular I'm developing a web-app with Play Framework, and I need to search inside my DB indexed with Solr. – Fabio Dec 03 '14 at 10:49
  • Not work, it's necessary to specify the COMPLETE and CORRECT name of a company. I need to have company based on similarity name, not the exact one. – Fabio Dec 04 '14 at 15:35
  • @Fabio Try adding [solr.NGramFilterFactory](http://www.wunderkraut.com/blog/apache-solr-configuring-partial-word-search-functionality/2012-12-12) or [solr.EdgeNGramFilterFactory](http://stackoverflow.com/questions/13472565/partial-word-search-in-solr-example-sarvesh-i-want-search-like-rves) in your shcmea.xml to perform search for partial words. Example: `` for fieldtype `solr.TextField` – bprasanna Dec 04 '14 at 16:18
  • I can't understand how does it work, what about fuzzy search in Solr? – Fabio Dec 05 '14 at 10:18