Lucene cartesian product diferent documents? - elasticsearch

I have 3 indexed documents:
Cars: Toyota (gt, gtX, gtx12), Ford (corola...), Volkswagen (gtS), Tesla...
Car models: gt, gtX, gtx12
Car colors: white, red
Example search query: "gt*"
Should return:
Volkswagen gtS white
Volkswagen gtS red
Toyota gt white
Toyota gt red
Toyota gtx12 white
Toyota gtx12 red
Toyota gtX red
Toyota gtX white
I can't add them to index like 'Toyota gt', 'Toyota gtx'... because there will be a relay huge index (even more then 50gb in my case, and search is slow).
I implemented in my own: Search by "car" then by "models" then merge but I'm interested if lucene can handle it.

Related

load filtered values in p:dataTable while the page is loading

How to load filtered values in the data table while the page is loading?
I have 3 data tables in a single page.
Tried adding filterValue="BMW" in
<p:column
headerText="Car Type"
sortBy="#{car}"
filterBy="#{car}"
filterValue="BMW" id="carTypeColumn">
<h:outputText id="car"
value="#{carResultsRow.car.type}" />
</p:column>
<p:dataTable id="carResults"
value="#{carMB.car}" var="carResultsRow"
rows="20" paginator="true" widgetVar="carResultsVar"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink}
{PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
style="margin-bottom:20px" rowIndexVar="rowIndex"
lazy="true" sortOrder="DESCENDING"
currentPageReportTemplate="(Displaying {startRecord} - {endRecord} of
{totalRecords})"
rowStyleClass="#{(rowIndex mod 2) eq 0 ? 'highlight1' : 'highlight2'}"
emptyMessage="No results found for search."
reflow="true">
<p:column
headerText="Car Type"
sortBy="#{car}"
filterBy="#{car}" id="carTypeColumn">
<h:outputText id="car"
value="#{carResultsRow.car.type}" />
</p:column>
<p:dataTable id="carResults2"
value="#{carMB.car}" var="carResultsRow"
rows="20" paginator="true" widgetVar="carResultsVar"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink}
{PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
style="margin-bottom:20px" rowIndexVar="rowIndex"
lazy="true" sortOrder="DESCENDING"
currentPageReportTemplate="(Displaying {startRecord} - {endRecord} of
{totalRecords})"
rowStyleClass="#{(rowIndex mod 2) eq 0 ? 'highlight1' : 'highlight2'}"
emptyMessage="No results found for search."
reflow="true">
<p:column
headerText="Car Type"
sortBy="#{car}"
filterBy="#{car}" id="carTypeColumn">
<h:outputText id="car"
value="#{carResultsRow.car.type}" />
</p:column>
<p:dataTable id="carResults3"
value="#{carMB.car}" var="carResultsRow"
rows="20" paginator="true" widgetVar="carResultsVar"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink}
{PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
style="margin-bottom:20px" rowIndexVar="rowIndex"
lazy="true" sortOrder="DESCENDING"
currentPageReportTemplate="(Displaying {startRecord} - {endRecord} of
{totalRecords})"
rowStyleClass="#{(rowIndex mod 2) eq 0 ? 'highlight1' : 'highlight2'}"
emptyMessage="No results found for search."
reflow="true">
<p:column
headerText="Car Type"
sortBy="#{car}"
filterBy="#{car}" id="carTypeColumn">
<h:outputText id="car"
value="#{carResultsRow.car.type}" />
</p:column>
The following data table produces the result-
Actual Results
Data Table 1
ID Year Type Color Status Price
adff7ca0 1974 BMW Blue Sale $14,160.00
50f83d04 1998 Renault Silver Sale $43,645.00
27b7be8d 1995 Merc Red Sold $80,627.00
b35c4322 2006 BMW Orange Sold $16,051.00
7888e692 1997 Fiat Red Sale $4,508.00
adbf1199 2004 Audi Brown Sale $37,511.00
8eb3e5a9 1985 Honda Black Sold $46,729.00
fed0821c 1990 BMW Red Sale $88,185.00
85d2282f 1967 Honda Orange Sold $33,674.00
bc34ed49 1972 BMW Blue Sale $81,567.00
Data Table 2
ID Year Type Color Status Price
adff7ca0 1974 BMW Blue Sale $14,160.00
50f83d04 1998 Renault Silver Sale $43,645.00
27b7be8d 1995 Merc Red Sold $80,627.00
b35c4322 2006 BMW Orange Sold $16,051.00
7888e692 1997 Fiat Red Sale $4,508.00
adbf1199 2004 Audi Brown Sale $37,511.00
8eb3e5a9 1985 Honda Black Sold $46,729.00
fed0821c 1990 BMW Red Sale $88,185.00
85d2282f 1967 Honda Orange Sold $33,674.00
bc34ed49 1972 BMW Blue Sale $81,567.00
Data Table 3
ID Year Type Color Status Price
adff7ca0 1974 BMW Blue Sale $14,160.00
50f83d04 1998 Renault Silver Sale $43,645.00
27b7be8d 1995 Merc Red Sold $80,627.00
b35c4322 2006 BMW Orange Sold $16,051.00
7888e692 1997 Fiat Red Sale $4,508.00
adbf1199 2004 Audi Brown Sale $37,511.00
8eb3e5a9 1985 Honda Black Sold $46,729.00
fed0821c 1990 BMW Red Sale $88,185.00
85d2282f 1967 Honda Orange Sold $33,674.00
bc34ed49 1972 BMW Blue Sale $81,567.00
Expected Results
Here in the expected results data tables were filtered by the type of car, First data table was filtered by the type BMW and contains the type BMW, Second data table was filtered by the type Honda and contains the values of Honda, The third data table contains the type of both Renault and Merc.
Datatable 1
ID Year Type Color Status Price
adff7ca0 1974 BMW Blue Sale $14,160.00
b35c4322 2006 BMW Orange Sold $16,051.00
fed0821c 1990 BMW Red Sale $88,185.00
bc34ed49 1972 BMW Blue Sale $81,567.00
Datatable 2
ID Year Type Color Status Price
85d2282f 1967 Honda Orange Sold $33,674.00
8eb3e5a9 1985 Honda Black Sold $46,729.00
Datatable 3
ID Year Type Color Status Price
50f83d04 1998 Renault Silver Sale $43,645.00
27b7be8d 1995 Merc Red Sold $80,627.00
===============================
Result With the solution posted
filterBy="#{carMB.filterBy}" filterBy = singletonList(new FilterState(
ID Year Type Color Status Price
BMW -------------- Appeared in the filter header
dff7ca0 1974 BMW Blue Sale $14,160
f83d04 1998 Renault Silver Sale $43,640
7be8d 1995 Merc Red Sold $80,627
5c4322 2006 BMW Orange Sold $16,051
88e692 1997 Fiat Red Sale $4,508
bf1199 2004 Audi Brown Sale $37,511
3e5a9 1985 Honda Black Sold $46,729
0821c 1990 BMW Red Sale $88,185
2282f 1967 Honda Orange Sold $33,674
4ed49 1972 BMW Blue Sale $81,567
Assuming your filter works at all when you manually input text, it is still true that the filterValue attribute of p:column does not seeme to trigger actual data filtering. Instead it only populates the filter input with the bound value. (Not sure if this is intentional)
In order to actually apply a default filtering, you'll have to populate a java.util.List with one or more org.primefaces.component.datatable.FilterState instances:
package my.pkg;
import static java.util.Collections.singletonList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
import org.primefaces.component.datatable.FilterState;
#Named
#RequestScoped
public class MyBean {
private List<FilterState> filterBy;
#PostConstruct
public void init() {
filterBy = singletonList(new FilterState("frm1:carResults:column1", "BMW"));
}
// getters / setters
}
Then bind this list to p:dataTable#filterBy attribute:
<h:form id="frm1">
<p:dataTable id="carResults" filterBy="#{myBean.filterBy}" ...>
<p:column id="column1" ...>
...
</p:column>
</p:dataTable>
</h:form>
Note that columns are identified by their xhtml element IDs.
As of PrimeFaces 8.0 FilterState is now named FilterMeta.
In addition to the above answer the following might be helpful:
This fires off an additional asynchronous call to the backend to the lazy loading component to filter the items, but since the page has not loaded properly yet, I needed to use the setTimeout to call after the page has loaded and created the PF object
<h:outputScript target="head">
$(function() {
setTimeout(function() { PF('myTable').filter(); }, 100);
});
</h:outputScript>

Kibana 5 - plotting a stacked bar plot with a different filter for each color

I'm having a bit of truble trying to get Kibana do a certain bar chart.
In a ridiculous reduction, it looks like this:
My data consists of documents of the following structure:
FULL NAME: "Michael Jordan"
PROPERTIES: "53Y MALE 198cm"
DEPARTMENT: Parquet
FULL NAME: "Sasha Digiulian"
PROPERTIES: "24Y FEMALE 157cm"
DEPARTMENT: Rock, Ice
FULL NAME: "Ueli Steck"
PROPERTIES: "40Y MALE 187cm"
DEPARTMENT: Ice
Eventually, I'd like to display a two-colored bar chart with its X axis the department, and the Y axis being a double bar with one color for the number of males for the department and another color for the number of females.
In this case there will be 3 (double) bars for
[Rock, Ice, Parquet]
with Y axis being
[(0,1), (1,1), (1,0)]
Now, for each one separately it is easy - define a filter as a query on PROPERTIES, then a (unique) count aggrigation on FULL NAME. But then again - filter is for ALL the plot, what can I do to make a different filter for each color?
Alternatively, I can try to define a scripted field, something like
MALE_NAME: doc['PROPERTIES'].value=~"MALE"?doc['FULL NAME'].value?""
and same for female. But now, scripted fields won't word on strings...
Any Ideas are greatly welcomed. Thanks!
Seems like this issue is still open. But then there's a workaround here using the Split Bar aggregation. Give it a go.

How do can I remove text from a string in Ruby when there are multiple instances of the text in the string

An example of the string:
"6 red cables, 4 white cables, 9 blue cables"
I want to remove "cables" so that it reads
"6 red, 4 white, 9 blue"
I looked at the slice and sub methods, but they only remove the first instance of "cables". Can someone point me in the right direction?
You can use String#gsub:
2.2.0 :003 > "6 red cables, 4 white cables, 9 blue cables".gsub(" cables", "")
=> "6 red, 4 white, 9 blue"
Reference (compares sub vs gsub):
http://www.dotnetperls.com/sub-ruby
Answer
cleand_value = "6 red cables, 4 white cables, 9 blue cables".gsub("cables", '')
Output "6 red , 4 white , 9 blue "
Explanation:
value = "abc abc"
# Gsub replaces all instances.
value = value.gsub("abc", "---")
puts value
Output
--- ---
You then can get rid of all the white spaces after the commas the same way.
cleaner_value = cleaned_value.gsub(", ", ",") #replaces all instances
output "6 red, 4 white, 9 blue"
Or use the other solutions and do
cleand_value = "6 red cables, 4 white cables, 9 blue cables".gsub(" cables", '') #notice the space before cables. May cause problems unless you know exactly the input

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax t

INSERT INTO `recipe`(`Recipe_Id`, `Recipe_Name`, `Ingredients`, `Method`, `Servings`, `Ranking`) VALUES ([1],['Garlic Chicken'],['4 cloves garlic, chopped','1/2 cup any oil','1/4 cup bread crumbs','4 boneless, skinless chicken breasts''salt as required','black pepper as required'],['(if you have oven Preheat oven to 375 degrees F (190 degrees C))In small pan, stir fry garlic with the oil then mix chicken with garlic and black pepper and add garlic mixture on it and then coat them with bread crumbs then Bake in the preheated oven for 45 minutes to 1 hour. INCASE you donot have oven you can cook it in a sauce pan using 1 cup oil. cook untill it gets golden brown and then serve],[5],[0]);
I do not know where I am wrong. How can this be solved?
You are missing a closing quotation mark after serve. You syntax for the ingredients values is also wrong. It should be:
INSERT INTO recipe
( Recipe_Id ,
Recipe_Name ,
Ingredients ,
Method ,
Servings ,
Ranking
)
VALUES ( 1 ,
'Garlic Chicken' ,
'4 cloves garlic, chopped, 1/2 cup any oil, 1/4 cup bread crumbs, 4 boneless, skinless chicken breasts salt as required,black pepper as required' ,
'(if you have oven Preheat oven to 375 degrees F (190 degrees C))In small pan, stir fry garlic with the oil then mix chicken with garlic and black pepper and add garlic mixture on it and then coat them with bread crumbs then Bake in the preheated oven for 45 minutes to 1 hour. INCASE you donot have oven you can cook it in a sauce pan using 1 cup oil. cook untill it gets golden brown and then serve' ,
5 ,
0
);

Custom options Magento

I am struggeling with Magento custom options.
In Magento you can add custom options at a Simple product. With this option an attribute like "color" can be added. Before the customer want to add the product to his cart, he first select the custom option "color". The price can change at every color.
But the options are very individual. I want the options are dependent on each other.
Something like this:
lenght = 100cm -> wood type: 1 = 120 euro total-> color: green = 140 euro total
-> color: grey = 150 euro total
wood type: 2 = 130 euro total-> color: green = 150 euro total
-> color: grey = 160 euro total
lengt = 120cm -> wood type 1: = 130 euro total-> color: green = 160 euro total
-> color: grey = 170 euro total
wood type 2: = 140 euro total-> color: green = 180 euro total
-> color: grey = 190 euro total
A store that I know that use it is:
http://www.zelfbouwmeubels.nl/tafels/eettafel/
And then select "SAMENSTELLEN".
Do i need an plugin for it or is there an default functionality in Magento.
Consider using a configurable product instead of a simple product, and download a module that will use the selected simple product's pricing. Then you can individually manage each length/wood-type/colour option as an individual SKU and charge different prices for each.
Configurable products:
http://www.magentocommerce.com/knowledge-base/entry/tutorial-creating-a-configurable-product
Module to do what you want:
http://www.magentocommerce.com/magento-connect/Matt+Dean/extension/596/simple-configurable-products

Resources