Apache Solr: Faceted Search on multivalued fields - dictionary

Im currently working on a solr based search application.
I have two multivalued fields for example:
The data is read out of a database.
<int name="id">1</int>
<arr name="type">
<str>Marke</str>
<str>Modell</str>
<str>Fahrzeugtyp</str>
<str>engine</str>
</arr>
<arr name="value">
<str>Volkswagen</str>
<str>Golf</str>
<str>Golf TDI</str>
<str>V-Engine</str>
In my current solr configuration there is no relationship between these two multivalued fields. So that i can say "Marke = Volkswagen".
Besides there must be a relationship between Volkswagen and Golf. So I have to structure a taxonomy out of the two multivalued fields and of the values in the multivalued field itself.
I tried to build a typeAhead. In my current config when i search for Volkswagen - the possible suggestions contain audi and engine2 which does not refer to a Volkswagen model.
solr url:
http://xyz:8983/solr/suggest?&wt=json&facet=true&q=*&facet.field=value&facet.prefix=Volkswagen
I think Solr Faceting on Multiple Concatenated Fields has something to do with it, but I can't adjust it on my problem.
Thanks in reply
Maybe I can use the TemplateTransformer to combine value and type?
With TemplateTransformer I get a result: Marke | Volkswagen
In my data-import.xml (DIH)
<entity> name="tablename" transformer="TemplateTransformer">
<field column="test" template="${tablename.TYPE} | tablename.VALUE}"/>
...
</entity>

It has been a long time since I've solved this problem. Try use this script in your data input handler. Attention - this script is based on solr 3.6.
<script>
<![CDATA[ function f1(row)
{
var eldName = row.get('TYPE');
row.put(eldName, row.get('VALUE'));
return row;
}
]]>
</script>
<entity name="e" transformer="script:f1" query="select TYPE, VALUE from X"></entity>

Related

how to retrieve java map in javascript?

I'm using JSF1.2 apache trinidad tag. I have a requirement like based on the drop down list the associated list of array values should get rendered into the UI.My Bean will have a map (drop down value as key which is unique, the associated list of values retrieved from DB) will be readily available when the page loads. In java script, how to retrieve the associated list value from this map and how to return back the array value into UI? Is there any other options available to achieve this requirement?
Your help on this is really much appreciated.
If I understand this right, you have the entire map available when the page is rendered.
You could prebuild the selectItems in the dropdown beforehand like this:
Map<String, List<String>> map;
//read the map content here
List<SelectItem> items = new ArrayList<SelectItem>();
for(String key: map.keySet()){
items.add(new SelectItem(key, map.get(key)));
}
These items will have the key as the label and the corresponding array as the value.
When you use this in your interface you can do this:
<tr:selectOneChoice value="#{bean.selectedArray}" required="true" autoSubmit="true">
<f:selectItems value="#{bean.items}"
</tr:selectOneChoice>
<tr:outputText value="#{bean.selectedArray}" />
The code isn't complete, but it should get you started.

How can I store Maps in POJOs in Solr?

How can I store Maps in POJOs in Solr? Currently I have a construct like this
#Field("*_locId")
protected Map<String, Integer> geoLocationToLocationId;
In the schema.xml file:
<dynamicField name="*_locId" type="int" indexed="false" stored="true" multiValued="false" />
adding via:
public void addGeoLocationToLocationAutoInMapping(GeoCoordinates geoCoordinates,
Integer id) {
if(this.geoLocationToLocationId == null) {
this.geoLocationToLocationId = new HashMap<String, Integer>();
}
this.geoLocationToLocationId.put(geoCoordinates.toString() +
"_locId", id);
}
getting is similar.
This works, but it's kinda dirty that I store a Java Map like this in Solr because I can get loads of fields. Is there another way to write Java Maps into Solr?
I don't want to index them, I just want to save the data.
Though I would like to follow #Geert-Jan's advice in general, there are times you just want to have Solr return all the data you need. A better hack to store a simple map (String to Integer) like yours in Solr is to store the keys and values as two separate multi-valued fields and make sure the indexes agree on them. So you would have one mutli-valued field like:
geo_location: new york, los angeles, chicago
and another like
location_id: 1, 2, 3
And make sure that none of the values is null in the location_id field, else your indexes in the fields won't match.

how to get the list of keywords if we have category tcm id in XSLT TBB(XSLT Mediator)

I am using SDL tridion 2011 SP1.
I want to get the list of keywords under given category using XSLT Mediator.
Have any one come across this situation, If yes please share your views.
But When I actually looked at the Category Item XML it does not have any info related to its keywords.
You will need to create a C# TBB to insert the category keywords into the package, and then access this as a parameter in your XSLT.
You can use a piece of c# like the following:
class GetCategoryKeywords : TemplateBase
{
public override void Transform(Engine engine, Package package)
{
Initialize(engine, package);
String webDavPathCategory = package.GetValue("CategotryWebDavPath");
Category cat = (Category)engine.GetObject(webDavPathCategory);
XmlDocument keywordsXml = new XmlDocument();
keywordsXml.LoadXml(cat.GetListKeywords().OuterXml);
Item output = package.CreateXmlDocumentItem(ContentType.Xml, keywordsXml);
package.PushItem("CategoryKeywords", output);
}
}
This will place an XML document in the package called CategoryKeywords containing the keywords. Then when you invoke the XSLT mediator, set the "Include Package Paramters" value to true, and add a parameter to the top of your XSLT as follows:
<xsl:param name="CategoryKeywords"/>
You can then loop through the new parameter as a variable performing any XPath queries on it that you desire. The following samples may help:
<xsl:variable name="URI" select="$CategoryKeywords//tcm:ListUsedItems/tcm:Item[#Title=$VALUE]/#ID" />
<xsl:for-each select="$CategoryKeywords//tcm:ListItems/tcm:Item">
Do something
<xsl:for-each>

How to get the complete set of Embedded field values in a popup window in the Tridion Web GUI?

I implemented a ribbon tool bar button for Tridion 2011 SP1, which opens an aspx page and populates a drop down list based on a look-up component. The look-up component comprises of different embedded schemas. To filter out the values based on embedded schema name I need to get the Embedded schema field values of component creation page on button click in button JavaScript.
Because in my component creation page consists of multivalued Embedded schema field has the info, which helps look up value filtering process. I am unaware of the command need to be used for the requirement. I know about a command to get the complete component XML, that is: $display.getView().getItemFields().
To get the present RTF field content I am going for the command: target.editor.getHTML(). To get the complete set of Embedded schema field values only,
which command I need to use?
My sample component source:
<root>
<a>sample a</a>
<b>sample b</b>
<c>
<ca>ca 1</ca>
<cb>cb 1</cb>
<cc>cc 1</cc>
</c>
<c>
<ca>ca 2</ca>
<cb>cb 2</cb>
<cc>cc 2</cc>
</c>
<c>
<ca>ca 1</ca>
<cb>cb 1</cb>
<cc>cc 1</cc>
</c>
</root>
I don't think there are public API for that. But you could use component data xml and then parse it by yourself:
var item = $display.getItem();
var xml = item.getContent(); // OR $display.getView().getItemFields();
var xmlDoc = $xml.getNewXmlDocument(xml);
var schema = item.getSchema();
if(schema.isLoaded())
{
var xpath = "/custom:{0}/custom:embeddedFieldName".format(schema.getRootElementName());
var fields = $xml.selectNodes(xmlDoc, xpath, { custom: schema.getNamespaceUri() });
// loop fields and get values ...
}

Xml from sql table

I want to get the contents of a sql table using xml:
projectID - projectName - customerID -customerName - city
i want to list all columns in xml tags and nest the customer seperately inside a project element
how can i then use this in .net correctly?
You can transform the table row into XML using by using xmlelement:
(select xmlelement (name Project,
xmlattributes(p.projectID as id),
xmlelement(p.name as Name),
xmlelement(name Customer,
xmlattributes(p.customerID as id),
xmlforest(p.customerName as Name, p.city as City)
))
)
from
TableName p
You need to replace 'TableName' with whatever your table is called. This basically returns data as XML and nests a new customer element inside a parent project tag. This is the XML outputted:
<Project id="1">
<Project Name>Manhatten Project</Project>
<Customer id="200">
<Name>Jim Doe</Name>
<City>New York</City>
</Customer>
</Project>
You can then parse the XML in .net with the Read() method. If you've not used XML with .net before, read this article for a general introduction.

Resources