search in a view string with '*' in it - xpages

I have an xpage where I'm looking in a view for products where the productname itself (viewScope.product) contains in it's name sometime a '*' for example productname 'apple 2 * d1' and productname 'apple 3 * p' and productname 'apple 2' etc
I don't succeed in obtaining the correct viewresults for the selected product (viewScope.product)
PS the search is an array since I have other selection criteria which do work
<xp:this.data>
<xp:dominoView var="viewPictures"
databaseName="product/demo.nsf" viewName="demo3">
<xp:this.search><![CDATA[#{javascript:var tmpArray = new Array("");
var cTerms = 0;
tmpArray[cTerms++] = "(FIELD Prod = \"" + viewScope.product + "\")";
return tmpArray.toString();
return qstring
]]></xp:this.search>
</xp:dominoView>
</xp:this.data>

You can use ? as a replacement for any one character when doing full text search.
E.g.
FIELD Prod = "apple 2 ? d1"
If there are documents that contains other combinations, e.g. "apple t X d1", this would be included in the search.
I don't know of a way to escape * in full text search.

Related

Xpages: Keep view sort order when filtering on view

My Xpage has a dataView that points to a view which is sorted by employee name. One of the other fields in the employee view is their Location. I have a combobox in the header of the view that allows a user to subset to one location. When subsetted the correct employees appear, but the sort order is lost.
I have looked at a few answers in Stack overflow such as this and this. but cannot get them to work. I think the difference is that
I am not trying to filter on a value that is sorted.
Here is my code for the FT Search:
var tmpArray = new Array("");
var cTerms = 0;
//Geo Location Search
if(viewScope.key != null & viewScope.key != "" & viewScope.key != "All Locations" & viewScope.key != "--Select a Location--") {
tmpArray[cTerms++] = "(FIELD HR_GeoLocation = " + viewScope.key + ")";}
qstring = tmpArray.join(" AND ").trim();
viewScope.queryString = qstring; // this just displays the query
return qstring // this is what sets the search property
The view's first field is the users last name, first name, descending.
FTSearch doesn't return found documents in view's order:
The collection of documents that match the full-text query are sorted
by relevance, with highest relevance first.
Use an additional view which is categorized by Location and use Location as key in
Filter by category name (categoryFilter) or
Filter by column value
(keys/keysExactMatch)
The columns after Location-column are the same as in your current view.

Filter Result Best match result at top and then follow remaining results

I am developing one city filter in mongodb and nodejs with list of city with checkbox like this
city name 1
city name 2
city name 3
city name 4
once we click on any city or multiple city then we receive data with related to that city with following code.
var query = {city:{ $in:city }};
posts.find(query, {} , function(e,docs){
res.json(docs);
});
through query i just pass the city as array and receive Data..But my requirement is :
1.Suppose if i selected any 1 or 2 city then that city result come first and remaining city follow after that city even if those city not selected.
Thanks.
Query1 : db.city.find({name:{$in:["Bangalore"]}})
Query2 - db.city.find({name:{$nin:["Bangalore"]}})
**
- Edit
**
> var result = []; //Define an empty Array
> var cur = db.city.aggregate([{$match:{name:{$in:["Bangalore","Delhi"]}}}]); //Get matching city and save it in cursor
> while(cur.hasNext()){ result.push(cur.next()) } // Retrieve the cursor data and push it in array
> var cur = db.city.aggregate([{$match:{name:{$nin:["Bangalore","Delhi"]}}}]); // Get non matching city and save it in cursor (should be new variable)
> while(cur.hasNext()){ result.push(cur.next()) }
> for(var i=0;i<result.length;i++){printjson(result[i])}
This will give you expected result. Hope you are expecting the same :)

How to load items with SuiteScript Purchase Orders?

Friends'm working with NetSuite and SuiteScript. I can save a purchase order running the script and also charge Purchase Orders created, but when I bring returns data item value as a null value, and I need to get the id of the item.
The result gives me the log NetSuite is:
Purchase Order ID: 3706 Vendor ID: 144 Item ID: null Trandate: 06/08/2015 Form: Standard Purchase Order Currency: Peso CL
this happens all Purchase Orders and obviously if you have an item attached.
function to load javascript to use Purchase Order is as follows:
function loadPurchaseOrder(){
nlapiLogExecution('DEBUG','loadPurchaseOrder', 'Entra a funcion loadPurchaseOrder');
//se aplican filtros para la busqueda del objeto
var filters= new Array();
filters[0] = new nlobjSearchFilter('purchaseorder',null,'isnotempty');
filters[1] = new nlobjSearchFilter('mainline', null, 'is', 'T');
//seleccion de los campos que se quieren extraer
var columns = new Array();
columns[0] = new nlobjSearchColumn('item');
columns[1] = new nlobjSearchColumn('entity');
columns[2] = new nlobjSearchColumn('trandate');
columns[3] = new nlobjSearchColumn('customform');
columns[4] = new nlobjSearchColumn('currency');
columns[5] = new nlobjSearchColumn('internalid');
var results = nlapiSearchRecord('purchaseorder',null,filters,columns);
var out = "";
if(results != null ){
for(var i=0; i< results.length; i++){
var purchaseOrder = results[i];
var idItem = purchaseOrder.getValue('item');
var idVendor = purchaseOrder.getValue('entity');
var trandate = purchaseOrder.getValue('trandate');
var form = purchaseOrder.getText('customform');
var currency = purchaseOrder.getText('currency');
var idPurchaseOrder = purchaseOrder.getText('internalid');
out = " ID Purchase Order: " + idPurchaseOrder + " ID Vendor: " + idVendor + " ID Item: " + idItem
+ " Trandate: " + trandate + " Form: " + form + " Currency: " + currency;
nlapiLogExecution('DEBUG','purchaseOrderCargada', out);
}
}
return out;
}
If someone could please help me. Greetings!
pd:
I've also tried:
var idItem = nlapiGetLineItemField ('item', 'item');
and it does not work = /
This is maybe a longer answer than you're expecting, but here we go.
NetSuite divides Transaction records (Purchase Order is a type of Transaction) into Body and Line Item fields. When you do a Transaction search that includes mainline = 'T', you are telling NetSuite to only retrieve Body field data. The item field, however, is a Line Item field, so NetSuite will not return any data for it. That's why idItem is null.
Understanding the behaviour of the mainline filter is crucial to Transaction searches. Basically, it goes like this:
mainline = 'T' will only return body field data, so it will return exactly one search result per Transaction
mainline = 'F' will only return line item data, so it will return one search result for every line item on matching Transactions
mainline not specified will return both body field and line data, so it will return one result for each transaction itself plus one result for each line on each transaction.
Here's a concrete example. Let's say that there is only one Purchase Order in the system that matches all of your other search filters (besides mainline), and that Purchase Order has three items on it. This is how the search results will change based on the mainline filter:
If mainline = 'T' then you will get exactly one result for the Purchase Order, and you will only get data for Search Columns that are Body fields.
If mainline = 'F' then you will get exactly three results, one for each line item, and all of your Search Columns will contain data whether they are Body or Line fields
If mainline is not specified then you will get exactly four results, one of them will only contain data for Body fields, and the other three will contain both Line and Body data
It's difficult to advise on exactly how you should change your search as I do not know what you plan to do with these search results.

How to search Shopify products using title and vendor

I am using the Shopify Storefront search to generate JSON: http://wiki.shopify.com/Storefront_search
Our client has a very large catalogue and we need to be able to search on the product title and product vendor fields but exclude the product body field.
Here is an example of the problem:
Say we have a products called "Galaxy S4" and "Galaxy S3" with vendor "Samsung" and the body text for the S4 starts "Improving on the wildly popular Galaxy S3" we will get the following search results:
myshopify.com/search?q=samsung galaxy s3&type=product&view=json
(searches all product fields for all the words in "samsung galaxy s3")
"Galaxy S3"
"Galaxy S4"
As the phrase "Galaxy S3" appears in the S4 body text it is listed in the search results -not ideal.
myshopify.com/search?q=title:samsung galaxy s3 OR vendor:samsung galaxy s3&type=product&view=json
(searches title field OR vendor field for all the words in "samsung galaxy s3" - this means that unless all of the words appear in either field no results are returned.)
No results
So the outcome we'd like is that is as long as each word in the search term appears in either the title OR the vendor the item is listed.
I hope this makes sense, any suggestions are appreciated.
This is the approach I have taken. I'm using Javascript to take the search query and turn it into a title OR vendor AND title OR vendor string:
var words = search_query.split(" ");
var search_string = '';
var i;
for (i = 0; i < words.length; ++i) {
if(words[i].length>0){
if(i > 0){
search_string += ' AND ';
}
search_string += 'title:'+words[i]+' OR vendor:'+words[i];
}
}
Using the example above this gives the following string:
myshopify.com/search?q=title:samsung OR vendor:samsung AND title:galaxy OR vendor:galaxy AND title:s3 OR vendor:s3&type=product&view=json
Which returns the desired search results.
Note:
Adding an asterisk to each side of the search words will also return partial word matches. i.e.:
search_string += 'title:*'+words[i]+'* OR vendor:*'+words[i]+'*';
Will make "samsun" match "samsung"

How do you set queries in Google FusionTables--Especially for text value queries?

I'm trying to query the table to show any location which contains the text that the user has input. So if user searches "Rome", Rome Georgia and Rome Italy are displayed, along with any other location containing "Rome". Pretty basic.
Does searchVal need to be in quotes cause its a string? (Like: 'searchVal'). So the commented out part below would look like: layer.setQuery("SELECT * FROM '853697' WHERE Location CONTAINS '" + searchVal + "'");
Furthermore, I switched this query to work with numbers instead, but I'm still not having any luck...
Here's my code:
function initTourMap() {
var nAtlantic = new google.maps.LatLng(31.295359681447383, -53.95838070000002);
var map = new google.maps.Map(document.getElementById('map_canvas'), {
center: nAtlantic,
zoom: 3,
mapTypeId: 'hybrid'
});
var layer = new google.maps.FusionTablesLayer({
query: {
select: 'Location',
from: '853697',
where: 'Nmbr contains 8',
},
});
$("#submitSearch").click(function(){
var searchVal = $("#Search").val();
alert(searchVal);
//layer.setQuery("SELECT * FROM '853697' WHERE Location CONTAINS searchVal"); //search user's input
layer.setQuery("SELECT * FROM '853697' WHERE Nmbr CONTAINS 4");
layer.setMap(map);
});
layer.setMap(map);
//END initTourMap() FUNCTION
}
You can read more about this here:
http://code.google.com/apis/maps/documentation/javascript/layers.html#FusionTablesQueries
I see a couple of issues in your example. The table id is an integer and should never be quoted. searchVal must be quoted when it's a string, but not quoted when it's a number. CONTAINS is a string operator and will not work with numbers. You can use = or >=, etc. Column names must be quoted only if they contain blanks.
Finally, layer.setQuery() is deprecated and while it still works you should use layer.setOption({query:...}). I've had problems with combining the two methods in a single application.

Resources