How to make Joomla Form Field SQL Empty Value at start - joomla3.0

I'm trying to make a drop down menu for the Country field in Joomla User profile.
<field name="countries" type="sql" label="Country" query="SELECT id, country_name FROM #__countries" key_field="id" value_field="country_name" required="true"/>
How can i make this 'Empty Value' at start and let the user to select? is it possible?
Thank you

<field name="countries" type="sql" label="Country" query="SELECT id, country_name FROM #__countries" key_field="id" value_field="country_name" required="true" default="0">
<option value="0">Empty</option>
</field>

<field name="countries" type="sql" label="Country" query="SELECT 0 AS `id`, '- Please select country -' AS `country_name` UNION SELECT id, country_name FROM #__countries" key_field="id" value_field="country_name" required="true"/>

Related

Solr delta import Query exception

THis is my db configuration file , I am able to full import properly
but getting problem to
delta import
there is two exception
datasource exception related to mysql
DHI
<dataConfig>
<dataSource driver="com.mysql.jdbc.Driver" url="jdbc:mysql://10.30.2.32:3306/artemis" batchSize="-1"
user="username" password="password" />
<document>
<entity name="job" pk="job_id"
query="SELECT * FROM job"
deltaImportQuery="SELECT * FROM job WHERE job_id = '${dataimporter.delta.id}'"
deltaQuery="SELECT job_id FROM job WHERE updated_date > convert_tz('${dataimporter.last_index_time}','+00:00','-05:30')">
<field column="job_id" name="jobId"/>
<field column="keywords" name="keywords"/>
<field column="speaciality" name="speaciality"/>
<field column="salary_min" name="salaryMin"/>
<field column="salary_max" name="salaryMax"/>
<field column="created_date" name="createdDate"/>
<field column="updated_date" name="updatedDate"/>
<field column="updated_date" name="updatedDate"/>
<field column="experience_from" name="experienceFrom"/>
<field column="experience_to" name="experienceTo"/>
<field column="job_title" name="jobTitle"/>
<entity name="city"
query="SELECT * FROM city where city_id ='${job.place_of_interview_id}'"
deltaQuery="select city_id from city where updated_date >convert_tz('${dataimporter.last_index_time}','+00:00','-05:30')"
parentDeltaQuery="select job_id from job where place_of_interview_id='${city.city_id}'"
>
<field column="name" name="city"/>
<entity name="district"
query="SELECT * FROM district where district_id='${city.district_id}'"
deltaQuery="select district_id from district where updated_date > '${dataimporter.last_index_time}'"
parentDeltaQuery="select city_id from city where district_id='${district.district_id}'"
>
<field column="name" name="district"/>
<entity name="state"
query="SELECT * FROM state where state_id='${district.state_id}'"
deltaQuery="select state_id from state where updated_date > '${dataimporter.last_index_time}'"
parentDeltaQuery="select district_id from district where state_id='${state.state_id}'"
>
<field column="name" name="state"/>
<entity name="country"
query="SELECT * FROM country where country_id='${state.country_id}'"
deltaQuery="select country_id from country where updated_date > '${dataimporter.last_index_time}'"
parentDeltaQuery="select state_id from state where country_id='${country.country_id}'"
>
<field column="name" name="country"/>
<entity name="region"
query="SELECT * FROM region where region_id='${country.region_id}'"
deltaQuery="select region_id from region where updated_date > '${dataimporter.last_index_time}'"
parentDeltaQuery="select country_id from country where region_id='${region.region_id}'"
>
<field column="name" name="region"/>
</entity>
</entity>
</entity>
</entity>
</entity>
<entity name="jobFunction"
query="SELECT * FROM job_function where job_function_id='${job.job_function_id}'"
deltaQuery="select job_function_id from job_function where updated_date > '${dataimporter.last_index_time}'"
parentDeltaQuery="select job_id from job where job_function_id='${jobFunction.job_function_id}'"
>
<field column="name" name="jobFunction"/>
<entity name="jobCategory"
query="SELECT * FROM master_data where id='${jobFunction.job_category_id}'"
deltaQuery="select id from master_data where updated_date > '${dataimporter.last_index_time}'"
parentDeltaQuery="select job_function_id from job_function where job_category_id='${jobCategory.id}'"
>
<field column="name" name="jobCategory"/>
</entity>
</entity>
<entity name="companyName"
query="SELECT * FROM employer where employer_id='${job.employer_id}'"
deltaQuery="select employer_id from employer where updated_date > '${dataimporter.last_index_time}'"
parentDeltaQuery="select job_id from job where employer_id='${companyName.employer_id}'"
>
<field column="company_name" name="companyName"/>
</entity>
</entity>
</document>
</dataConfig>
Exception I am getting at delta import
/29/2017, 6:25:47 PM
ERROR true
JdbcDataSource
Ignoring Error when closing connection
java.sql.SQLException: Streaming result set com.mysql.jdbc.RowDataDynamic#15196a0f is still active. No statements may be issued when any streaming result sets are open and in use on a given connection. Ensure that you have called .close() on any active streaming result sets before attempting more queries.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:880)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:876)
at com.mysql.jdbc.MysqlIO.checkForOutstandingStreamingData(MysqlIO.java:3111)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2366)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2594)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2541)
at com.mysql.jdbc.ConnectionImpl.rollbackNoChecks(ConnectionImpl.java:4738)
at com.mysql.jdbc.ConnectionImpl.rollback(ConnectionImpl.java:4630)
at com.mysql.jdbc.ConnectionImpl.realClose(ConnectionImpl.java:4271)
at com.mysql.jdbc.ConnectionImpl.close(ConnectionImpl.java:1515)
at org.apache.solr.handler.dataimport.JdbcDataSource.closeConnection(JdbcDataSource.java:507)
at org.apache.solr.handler.dataimport.JdbcDataSource.close(JdbcDataSource.java:492)
at org.apache.solr.handler.dataimport.DocBuilder.closeEntityProcessorWrappers(DocBuilder.java:288)
at org.apache.solr.handler.dataimport.DocBuilder.closeEntityProcessorWrappers(DocBuilder.java:290)
at org.apache.solr.handler.dataimport.DocBuilder.execute(DocBuilder.java:277)
at org.apache.solr.handler.dataimport.DataImporter.doDeltaImport(DataImporter.java:444)
at org.apache.solr.handler.dataimport.DataImporter.runCmd(DataImporter.java:482)
at org.apache.solr.handler.dataimport.DataImporter$1.run(DataImporter.java:461)
3/29/2017, 6
java.lang.RuntimeException: java.lang.IllegalArgumentException: deltaQuery has no column to resolve to declared primary key pk='jobId'
at org.apache.solr.handler.dataimport.DocBuilder.execute(DocBuilder.java:270)
at org.apache.solr.handler.dataimport.DataImporter.doDeltaImport(DataImporter.java:444)
at org.apache.solr.handler.dataimport.DataImporter.runCmd(DataImporter.java:482)
at org.apache.solr.handler.dataimport.DataImporter$1.run(DataImporter.java:461)
Caused by: java.lang.IllegalArgumentException: deltaQuery has no column to resolve to declared primary key pk='jobId'
at org.apache.solr.handler.dataimport.DocBuilder.findMatchingPkColumn(DocBuilder.java:755)
at org.apache.solr.handler.dataimport.DocBuilder.collectDelta(DocBuilder.java:808)
at org.apache.solr.handler.dataimport.DocBuilder.collectDelta(DocBuilder.java:789)
at org.apache.solr.handler.dataimport.DocBuilder.doDelta(DocBuilder.java:344)
at org.apache.solr.handler.dataimport.DocBuilder.execute(DocBuilder.java:224)
... 3 more
can you replace <'${dataimporter.delta.id}'> to ${dataimporter.delta.job_id} and test.
deltaImportQuery : (Only used in delta-import) .There is a namespace ${dih.delta.column-name} which can be used in this query. e.g: select * from tbl where id=${dih.delta.id} Solr1.4
as above line mentioned that we can only use column name in delta namespace.
reference:
https://wiki.apache.org/solr/DataImportHandler
https://wiki.apache.org/solr/DataImportHandler#Configuration_in_data-config.xml

SQL Templating in SmartGWT

I am trying to use SQL templating in smartgwt to load data from my database into a listgrid but I am not able to get the desired result. This is the raw SQL query which I am trying to adopt in SmartGWT to get the result
SELECT
dbo.province.provincename as province,
dbo.province.capital,
dbo.province.code,
dbo.province.telcode,
dbo.province.taxcode,
dbo.county.countyname as county,
dbo.district.districtname as district,
dbo.zone.alternateName as zone,
dbo.neighbourhood.alternateName as neigbhour,
dbo.city.cityname as city,
dbo.city.taxcode,
dbo.city.fdocode,
count(dbo.customer.customeraltname) as countCustomer
FROM
dbo.county
INNER JOIN
dbo.province
ON
(
dbo.county.provinceID = dbo.province.id)
INNER JOIN
dbo.district
ON
(
dbo.county.id = dbo.district.countyID)
INNER JOIN
dbo.city
ON
(
dbo.district.id = dbo.city.districtID)
INNER JOIN
dbo.zone
ON
(
dbo.city.id = dbo.zone.cityId)
INNER JOIN
dbo.neighbourhood
ON
(
dbo.zone.id = dbo.neighbourhood.zoneId)
INNER JOIN
dbo.customer
ON
(
dbo.neighbourhood.id = dbo.customer.neighbourhoodId)
Group By dbo.province.provincename,
dbo.province.capital,
dbo.province.code,
dbo.province.telcode,
dbo.province.taxcode,
dbo.county.countyname,
dbo.district.districtname,
dbo.zone.alternateName,
dbo.neighbourhood.alternateName,
dbo.city.cityname,
dbo.city.taxcode,
dbo.city.fdocode
Below is my ds.xml
<DataSource ID="CusNeiGroupDS" serverType="sql">
<fields>
<field name="id" type="integer" />
<field name="provincename" title="province" type="text"/>
<field name="capital" title="capital" type="text"/>
<field name="code" title="code" type="text"/>
<field name="telcode" title="telcode" type="text"/>
<field name="taxcode" title="taxcode" type="text" />
<field name="provinceId" type="integer" tableName="county"/>
<field name="countyname" title="county" type="text" tableName="county"/>
<field name="district" title="district" type="text" />
<field name="city" title="city" type="text" />
<field name="zone" title="zone" type="text" />
<field name="neighbour" title="neighbour" type="text" />
<field name="taxcodecity" title="taxcodecity" type="text"
/>
<field name="fdocode" title="fdocode" type="text" />
<!-- <field name="countCustomer" title="countCustomer" type="int" /> -->
</fields>
<operationBindings>
<operationBinding operationId="summary"
operationType="fetch">
<selectClause>
districtname as
district,
alternateName as zone,
alternateName as neigbhour,
cityname
as city,
fdocode
</selectClause>
<tableClause>province, county, district, zone, neighbourhood, city
</tableClause>
<whereClause>
province.Id = county.provinceId
AND district.countyId = county.Id
AND city.districtId = district.Id
AND neighbourhood.zoneId = zone.Id
</whereClause>
</operationBinding>
</operationBindings>
the error I get is
Execute of select: SELECT COUNT(*) FROM CusNeiGroupDS WHERE ('1'='1')
on db: SQLServer threw exception: java.sql.SQLException: Invalid
object name 'CusNeiGroupDS'. - assuming stale connection and retrying
query.
But when I put the table name in the datasource like this,I get output but only from that table which I mention and not from the other tables which are joined with FK.
<DataSource ID="CusNeiGroupDS" serverType="sql" tableName="province">
I was able to achieve this with using includeFrom and foreignKey tags in the datasources. Then create another datasource where i use it to include all the coumns I need from the different tables.Like so
<DataSource ID="neighbourDS_1" serverType="sql" tableName="neighbourhood" inheritsFrom="neighbourDS">
<fields>
<field name="provincename" includeFrom="provinceDS.provincename" />
<field name="capital" includeFrom="provinceDS.capital" />
<field name="code" includeFrom="provinceDS.code" />
<field name="telcode" includeFrom="provinceDS.telcode" />
<field name="countyname" includeFrom="countyDS.countyname" />
<field name="district" includeFrom="districtDS.districtname" />
<field name="city" includeFrom="cityDS.cityname" />
<field name="taxcodecity" includeFrom="cityDS.taxcodecity" />
<field name="fdocode" includeFrom="cityDS.fdocode" />
<field name="zone" includeFrom="zoneDS.zone" />
</fields>
</DataSource>

Struggling with learning solr

I am in the process of redesigning one of our companies site. My boss wants to play around with the idea of replacing all of our navigation with a search box.. the search box should be able to query any of our tables of unrelated data.
So right now I am trying it with 5 tables.
Products
Manufacturers
Category
Ingredients
Uses
So should be able to lookup a product name, a manufacturer name, a category name, an ingredient name, or a use name
When I retrieve the results. if the user clicked on a manufacturer search result.. It will take them to a manufacturer page that lookups all products for that manufacturer.
When clicks on a product page.. link will take them to that actual product information.
Ingredient will take them to a page that will show all products containing that ingredient.
Anyways here is my data config
<dataConfig>
<dataSource driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/xxx" user="xxx" password="xxx" />
<document>
<entity name="manufacturer" transformer="TemplateTransformer" pk="manNum"
query="SELECT manNum, manName FROM manufacturer
WHERE active = 1">
<field column="id" name="id" template="MAN-${manNum}" />
<field column="type" template="manufacturer" name="type"/>
<field column="manName" name="text"/>
<field column="manNum" name="manNum"/>
</entity>
<entity name="product" transformer="TemplateTransformer"
query="SELECT products.prodNum, products.prodName as text, m.manName FROM products JOIN man m USING (manNum)
WHERE products.active = 1
AND (hideWeb = 0 or hideWeb IS NULL)">
<field column="id" template="PROD-${products.prodNum}" name="id"/>
<field column="type" template="product" name="type"/>
<field column="text" name="text"/>
<field column="manName" name="manName"/>
</entity>
<entity name="ingredients" transformer="TemplateTransformer" pk="id"
query="SELECT id, text FROM inglist WHERE sort != ''">
<field column="id" name="id" template="ING-${inglist.id}"/>
<field column="type" template="ingredient" name="type"/>
<field column="text" name="text" />
</entity>
<entity name="uses" transformer="TemplateTransformer" pk="id"
query="SELECT id, text FROM useslist">
<field column="id" name="id" template="USE-${id}"/>
<field column="type" template="use" name="type"/>
<field column="text" name="text"/>
</entity>
<entity name="categories" transformer="TemplateTransformer" pk="id"
query="SELECT id, textShow as text FROM categorylist">
<field column="id" name="id" template="CATEGORY-${id}"/>
<field column="type" template="category" name="type"/>
<field column="text" name="text"/>
</entity>
</document>
</dataConfig>
And my schema..
<fields>
<field name="id" type="string" indexed="true" stored="true"/>
<field name="text" indexed="true" stored="true" type="text"/>
<field name="type" type="string" indexed="false" stored="true"/>
<field name="manName" type="text" indexed="false" stored="true"/>
<field name="manNum" type="string" indexed="false" stored="false"/>
</fields>
Now perhaps I am not doing this the right way... and there may be a better way to handle this.
Anyways the problem I am running into right now is that I am getting the error missing required field "id". Now products query and manufacturer query does not have an id column in the select.. but I thought the transform query should take care of it? If I do the select prodNum as id .. then all the ids are overwritting each other.
Now I could probably concat it in the actual query.. and will do so as a last resort, but would like to know what I am doing wrong with this solution.
EDIT
Nevermind, it was just a noob issue, for some reason I was thinking that the template variable was refering to the table name in the SQL not the entity name,
So I replaced all of the
With
And it worked.
Prefixing the table-specific ID with a distinct character or string is a good idea. I do it in the SQL, which allows me to check the behavior outside of Solr.
select
concat('b',cast(b.id as char)) as id,
...
It Was a noob issue,
for some reason I was thinking that the template variable was refering to the table name in the SQL not the entity name.
I do it like this:
<entity name="GG-Boryslaw-1939-Phonebook"
transformer="TemplateTransformer,DateFormatTransformer"
pk="id"
query="SELECT * FROM boryslaw_1939_phonebook">
<field column="record_id" template="GG-Boryslaw-1939-Phonebook-${GG-Boryslaw-1939-Phonebook.id}" />
<field column="record_type" template="phonebook" />
<field column="record_source" template="Boryslaw Phonebook (1939)" />
<field column="record_date" template="${GG-Boryslaw-1939-Phonebook.Year}" dateTimeFormat="yyyy" />
...etc...
</entity>

Create index on two unrelated table in Solr

I want to create index between two tables, stock and auction. Basically I am working on a product site. So I have to create index on both tables. and they are not related at all.
In data-config.xml, that I created to create index, I wrote the following code
<dataConfig>
<dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost/database" user="root" password=""/>
<document name="content">
<entity name="stock" query="select ST_StockID,ST_StockCode,ST_Name,ST_ItemDetail from stock where estatus = 'Active' limit 100">
<field column="ST_StockID" name="stock_ST_StockID" />
<field column="ST_StockCode" name="stock_ST_StockCode" />
<field column="ST_Name" name="stock_ST_Name" />
<field column="ST_ItemDetail" name="stock_ST_ItemDetail" />
<entity name="auction" query="select iauctionid,rad_number,vsku,auction_code from auction limit 100">
<field column="iauctionid" name="auction_iauctionid" />
<field column="rad_number" name="auction_rad_number" />
<field column="vsku" name="auction_vsku" />
<field column="auction_code" name="auction_auction_code" />
</entity>
</entity>
</document>
</dataConfig>
and the schema.xml contains the fields are given below.
<field name="stock_ST_StockID" type="string" indexed="true" stored="true" required="true"/>
<field name="stock_ST_StockCode" type="string" indexed="true" stored="true" required="true"/>
<field name="stock_ST_Name" type="string" indexed="true" stored="true" required="true"/>
<field name="stock_ST_ItemDetail" type="text" indexed="true" stored="true" required="true"/>
<field name="auction_iauctionid" type="string" indexed="true" stored="true" required="true"/>
<field name="auction_rad_number" type="string" indexed="true" stored="true" required="true"/>
<field name="auction_vsku" type="string" indexed="true" stored="true" required="true"/>
<field name="auction_auction_code" type="text" indexed="true" stored="true" required="true"/>
But this way the indexes are being created in wrong way as I put the other table data into the first table in data-config.xml. If I create two entity element like given below then the indexes are not being created.
<dataConfig>
<dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost/lc" user="root" password=""/>
<document name="content">
<entity name="stock" query="select ST_StockID,ST_StockCode,ST_Name,ST_ItemDetail from stock where estatus = 'Active' limit 100">
<field column="ST_StockID" name="stock_ST_StockID" />
<field column="ST_StockCode" name="stock_ST_StockCode" />
<field column="ST_Name" name="stock_ST_Name" />
<field column="ST_ItemDetail" name="stock_ST_ItemDetail" />
</entity>
<entity name="auction" query="select iauctionid,rad_number,vsku,auction_code from auction limit 100">
<field column="iauctionid" name="auction_iauctionid" />
<field column="rad_number" name="auction_rad_number" />
<field column="vsku" name="auction_vsku" />
<field column="auction_code" name="auction_auction_code" />
</entity>
</document>
</dataConfig>
I did not get your answer, can you pls elaborate a little more. I also have the same requirement. I have two tables stock and auction. Basically I am working on a product site. So I have to create index on both tables. and they are not related at all.
Please help
Do you get any errors when indexing the data ??
The following data config is fine as you have two unrelated items.
<dataConfig>
<dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost/lc" user="root" password=""/>
<document name="content">
<entity name="stock" query="select ST_StockID,ST_StockCode,ST_Name,ST_ItemDetail from stock where estatus = 'Active' limit 100">
<field column="ST_StockID" name="stock_ST_StockID" />
<field column="ST_StockCode" name="stock_ST_StockCode" />
<field column="ST_Name" name="stock_ST_Name" />
<field column="ST_ItemDetail" name="stock_ST_ItemDetail" />
</entity>
<entity name="auction" query="select iauctionid,rad_number,vsku,auction_code from auction limit 100">
<field column="iauctionid" name="auction_iauctionid" />
<field column="rad_number" name="auction_rad_number" />
<field column="vsku" name="auction_vsku" />
<field column="auction_code" name="auction_auction_code" />
</entity>
</document>
</dataConfig>
However, there are few things missing ?
Whats the id field for the entity ? As each document should have a unique id, the configuration seems missing above.
Also the id should be unqiue for the entites, else the stock and auction should overwrite each other.
So you may want the id append as stock_ & auction_
You can also add a static field as Stock and auction to your schema and populate them, which would help you the filter out the results when searching and hence improve the performance.
For Assigning the Ids -
You can use the following to create the id value - This should append the Stock_ with the ST_StockID field value.
<field column="id" template="Stock_#${stock.ST_StockID}" />
OR
Use alias in sql e.g. SELECT 'Stock_' || ST_StockID AS ID ..... as use -
<field column="id" name="id" />

Solr : range queries on multiValued fields in sub-entities?

I'm using Solr to index some stuff.
I got a dataconfig.xml with a root entity and a sub entity, like this one :
<entity name="item" query="select id, qty from item">
<field column="id" name="id" />
<field column="qty" name="qty" />
<entity name="prices" query="select price from prices where item_id='${item.id}'">
<field column="price" name="price" />
</entity>
</entity>
And the corresponding schema.xml :
<fields>
<field name="id" type="integer" indexed="true" stored="true" />
<field name="qty" type="sint" indexed="true" stored="true" />
<field name="price" type="sint" indexed="true" stored="true" multiValued="true" />
</fields>
Fields qty (from the root entity) and price (from the sub-entity) are both of type sint (to allow range queries), and price is multiValued since there can be multiple prices values for one item.
When I do a range query on qty, it works as expected. For example, qty:[* TO 10] returns elements with qty up to 10.
But when I do a range query on price, it doesn't work at all : price:[* TO 100] returns elements with prices even over 100 !
Hence my question: are range queries supposed to work on multiValued fields from "sub-entities" ?

Resources