Overview
I wanted to create a product search in Drupal 7. I created a view and exposed the fields that I wanted to have exposed for searching (filtering). The search works perfect but only when you search for items using the Item Title.
The Question:
I want a user to be able to type in a more "descriptive search" using all filters:
Title
Type
Variant
Size
SKU, etc
View SQL Code Sample
SELECT node.nid AS nid, node.type AS node_type, node.language AS node_language, node.title AS node_title, uc_products.model AS uc_products_model, node.created AS node_created, 'node' AS field_data_uc_product_image_node_entity_type, 'node' AS field_data_field_product_variant_node_entity_type, 'node' AS field_data_body_node_entity_type, 'node' AS field_data_field_product_tags_node_entity_type
FROM
{node} node
LEFT JOIN {field_data_body} field_data_body ON node.nid = field_data_body.entity_id AND (field_data_body.entity_type = 'node' AND field_data_body.deleted = '0')
LEFT JOIN {field_data_field_product_variant} field_data_field_product_variant ON node.nid = field_data_field_product_variant.entity_id AND (field_data_field_product_variant.entity_type = 'node' AND field_data_field_product_variant.deleted = '0')
LEFT JOIN {uc_products} uc_products ON node.vid = uc_products.vid
WHERE (( (node.status = '1') AND (node.type IN ('product')) AND (field_data_body.body_value LIKE '%%' ESCAPE '\\') AND (field_data_field_product_variant.field_product_variant_value LIKE '%%' ESCAPE '\\') ))
ORDER BY node_created DESC, node_title ASC
LIMIT 6 OFFSET 0
I wish to find out what I am doing wrong. I wish to merge all the exposed filter entities into one so that they can be searched / filtered from the one search box.
You response is highly appreciated.
You can take a look at this module http://drupal.org/project/views_filters_populate
But it only works with text filters (no combos etc.).
Related
I have difficulty in implementing Oracle query to powerbuilder. I have 3 singeline edit the name is :
1. sle_merk
2. sle_tipe
3. sle_jns
and I have oracle query
select b.nm_merk
, c.keterangan
, c.tipe
, b.keterangan
, c.usrid
, c.otr
, c.dupd
, c.dotr
, c.status
from tipe_kend c
left
outer
join jns_kendaraan b
on c.kd_jenis = b.kd_jenis
left
outer
join merk_kend b
on c.kd_merk = b.kd_merk
where b.kd_jenis like '%%'
AND b.kd_merk like '%%'
AND c.tipe like '%%'
what I want is if all singeline edit is null then the data is appears, but when one of singeline edit is filled then the data is appears where data like %singelineedit%. I have difficulty in implementing the query into Powerbuilder.
Since you don't say you are using a datawindow control I will assume you are not. With that being said then this must be a piece of embedded SQL inside some method. As such you need to declare variables for each of the columns in your retrieve. You also need variables to hold the contents of the SLE controls.
You would end up with something like this:
string ls_nm // make sure datatypes are correct
string ls_sle1, ls_sle2, ls_sle3
// get values of the sle controls
ls_sle1 = sle_merk.text
IF IsNull(ls_sle1) THEN ls_sle1 = ''
ls_sle2 = sle_tipe.text
IF IsNull(ls_sle2) THEN ls_sle2 = ''
ls_sle3 = sle_jns.text
IF IsNull(ls_sle3) THEN ls_sle3 = ''
select b.nm_merk, ...
INTO :ls_nm, ...
from tipe_kend c
left outer join ns_kendaraan b on c.kd_jenis = b.kd_jenis
left outer join merk_kend b on c.kd_merk = b.kd_merk
where b.kd_jenis like '%' + ls_sle1 + '%'
AND b.kd_merk like '%' + ls_sle2 + '%'
AND c.tipe like '% + ls_sle3 + '%';
Note this will FAIL if more than a single row is returned. If you need multiple rows you need to use a datawindow/datastore control (or cursors but they are very inefficient).
I have a Oracle query and would like to transform into Marklogic cts query. It looks like Marklogic CTS doesn't allow to have "and-query" inside of "and-query". I am not sure how Marklogic works. Thanks in advance.
Where clause query:
where (collection = "TRBA" AND fulltext = 1
AND (dnta = "Briefing" OR dnta = "Conference" OR snta = "Workshop"
OR snta = "Published in" AND (snta = "this article" OR dnta = "Journal")
)
AND (cand IN ("Research","Development Center") OR scn IN("424778","98814","393825"))
Translate into Marklogic:
let $uris:= cts:uris(
(),
(),
cts:and-query((
cts:collection-query("/dbs/"TRBA"),
cts:element-value-query(xs:QName("meta:FullTextExists"),"1"),
cts:field-word-query("dnta",("briefing","conference")),
cts:or-query((
cts:element-word-query(xs:QName("meta:snta"),("this article")),
cts:field-word-query("dnta",("Journal")),
cts:and-query((
cts:or-query((
cts:field-word-query("cand", ("Research","Development Center"))
cts:field-word-query("scn",("424778","98814","393825"))
))
))(:inside and-query:)
))(:or-query:)
))(:outside and-query:)
return fn:doc($uris)
There are basic syntax errors in your code above: missing parens, extra double quotes
I don't think you want word query as the translation for "="; word query just says that word appears somewhere in the field in question; I would think that would be a value query instead.
You might want to take a look at cts:parse which takes a string with ANDs and ORs etc. plus bindings for fields and parses a query string into a cts:query
That said, if you assume the AND mixed in with the ORs binds to the closest clause, i.e. as parenthesized so:
(collection = "TRBA" AND
fulltext = 1 AND
(dnta = "Briefing" OR
dnta = "Conference" OR
snta = "Workshop" OR
(snta = "Published in" AND (snta = "this article" OR dnta = "Journal"))
) AND
(cand IN ("Research","Development Center") OR
scn IN ("424778","98814","393825"))
then I would translate this something like this:
cts:and-query((
cts:collection-query("/dbs/TRBA"),
cts:element-value-query(xs:QName("meta:FullTextExists"),"1"),
cts:or-query((
cts:field-value-query("dnta",("Briefing","Conference")),
cts:field-value-query("snta","Workshop"),
cts:and-query((
cts:field-value-query("snta","Published in"),
cts:or-query((
cts:field-value-query("snta","this article"),
cts:field-value-query("dnta","Journal")
))
))
)),
cts:or-query((
cts:field-value-query("cand",("Research","Development Center")),
cts:field-value-query("scn",("424778","98814","392825"))
))
))
It is a pretty direct mapping.
You simply have several typos in your code. There's an extra double quote in the collection-query and you're missing a comma between items in the last or-query.
Once fixing those the code will run. But a pro tip: don't ever fetch URIs only to fetch documents. You're wasting effort. Just fetch the documents directly with a search passing the query.
let $q := cts:and-query((...))
return cts:search(doc(), $q)[1 to 10]
You probably want to add a limit like [1 to 10] as well unless you really intend to return the full result set.
please guide, i am able to work with Dynamic Group by , but when selecting non agrigated fields , i get the following error
No property or field 'name' exists in type 'IGrouping`2'
var result311 = (IQueryable)gle1.temptable.Where(a => a.IsAllowed == false && a.Code == "r01");
var result = result311.GroupBy("new (name, FirstAmountOriginal, SecondAccounting)", "it")
.Select("new (it.name,Sum(FirstAmountOriginal) as FirstAmountOriginalx, Sum(SecondAccounting) as SecondAccountingx)");
Please guide
Firstly, you should not group by the fields you want to aggregate and secondly, the grouping creates a grouping Key consisting of the fields you group by (in this case one), so you must address this key afterwards:
var result = result311.GroupBy("new(name)", "it")
.Select(#"new (it.Key.name,
Sum(FirstAmountOriginal) as FirstAmountOriginalx,
Sum(SecondAccounting) as SecondAccountingx)");
This seems to be about the most generic error I've come across - multiple SO posts about it are all referring to different issues - well here's a new one :)
I get the error above when the following IQueryable is enumerated:
N.B. items is an IQueryable<tblItem> and keywords is a string
items = items.Where(p => p.heading.ToLower().Contains(keywords) ||
p.description.ToLower().Contains(keywords));
This is confusing because, as the error suggests, it should work fine when you use a Contains - does anyone know how to fix this?
If keyword is a collection that supports enumeration, then it should be other way around:
items = items.Where(p => keywords.Contains(p.heading.ToLower()) ||
keywords.Contains(p.description.ToLower()));
If items is IQueryable then the error may be there and nothing to do with your where statement.
Can you try forcing enumeration before adding your where statement?
For example, suppose you are attempting to join an in memory list with a datatable you will get that error when the query is evaluated or enumerated
List<tblCategory> categories = tblCategory.ToList();
IQueryable<tblItem> items = (from r in tblItem
join c in categories on r.CategoryID equals c.Id select r);
// items = items.Where(p => p.heading.ToLower().Contains(keywords) ||
// p.description.ToLower().Contains(keywords));
var firstMatch = items.FirstOrDefault();
// The error will be generated here even if the where is remmed out
SOLVED
Thanks sgmoore for your input - it helped arrive at this solution:
Assgning the IQueryable list to an IEnumerable list, running a ToList on it and THEN using my filters on the list worked great.
IEnumerable<tblItems> temp = items.ToList();
temp = temp.Where(p => p.heading.ToLower().Contains(keywords) ||
p.description.ToLower().Contains(keywords));
items = temp.AsQueryable();
I want to extract information from various websites. I am using HtmlAgilityPack and Linq to XML. So far I have managed to extract the value from a single node in a website by writing:
var q = document.DocumentNode.DescendantNodes()
.Where(n => n.Name == "img" && n.Id == "GraphicalBoard001")
.FirstOrDefault();
But I am really interested in the whole collection of img's that start with "GraphicalBoard". I tried something like:
var q2 = document.DocumentNode.DescendantNodes()
.Where(n => n.Name == "img" && n.Id.Contains("GraphicalBoard"))
.Select...
But it seems that linq doesn't like the Contains-method, since I lose the Select option in intellisense. How can I extract all the img-tags where the Id starts with "GraphicalBoard"?
How can I extract all the img-tags where the Id starts with "GraphicalBoard"?
You had it already, just stop at the call to Where(). The Where() call filters the collection by the items that satisfies the predicate.
Though you should write it so you filter through the img descendants, not all descendants.
var query = doc.DocumentNode.Descendants("img")
.Where(img => img.Id.StartsWith("GraphicalBoard"));