w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
search string match relevance
MySQL has support for full-text indexing and searching: FULLTEXT SEARCH InnoDB now supports full text search as of 5.6 See How to find similar results and sort by similarity?

Categories : PHP

sorting relevance with mysql match against multiple words in 2 tables
Normally you would always need ORDER BY to ensure a certain ordering, but MySQL adds some magic to the natural language matching, that causes rows to always be ordered by relevance. Unfortunately for you, this doesn't apply to boolean searches. http://dev.mysql.com/doc/refman/5.5/en/fulltext-boolean.html says: Boolean full-text searches have these characteristics: They do not automatically sort rows in order of decreasing relevance. You can see this from the preceding query result: The row with the highest relevance is the one that contains “MySQL” twice, but it is listed last, not first. So instead of using a boolean search, you could do a natural language search, or use that other search to order the results by: SELECT a.* FROM item_info_short a LEFT JOIN item_information b O

Categories : Mysql

Python regex to match 2 distinct delimiters
If I understand your needs correctly, you could use this: [[(?:(?<uid>w+)::)?(?!.*::)(?<page>[^| fv]+)(?:|(?<alias>[^| fv]+))?]] ^^^^^^^^ See here for a demo. I added a negative lookahead after the uid capture. I have given names to the captured groups but if you don't want them, that's the one without named captured groups: [[(?:(w+)::)?(?!.*::)([^| fv]+)(?:|([^| fv]+))?]]

Categories : Python

MySQL 5.6.13 count distinct result not match
Because COUNT DISTINCT doesn't consider rows where exists a column value NULL I try the same query with my table. In my table in some rows there are column with NULL value, so the result is different. See this sample SQLFiddle

Categories : Mysql

Django DISTINCT match pattern with tolerance
You can do it in pure Python with difflib. values = """Item1 Linen Shirt Item2 Linen Shirt ItemB Linen Shirt1 Item Linen Skirt ItemC Linen Skirt2""" data = values.split(' ') print(difflib.get_close_matches(data[0], data)) Check the documentation for get_close_matches for additional parameters like tolerance.

Categories : Python

Using matching document original score in filter script for custom filters score query
Documents in a filtered query would be unranked and have the same score. http://www.elasticsearch.org/guide/reference/query-dsl/custom-score-query/ But you can use a custom score query together with a filtered query and use a script to calculate a score based on the document values. This was added in 0.90, I believe.

Categories : Elasticsearch

Combine solr's document score with a static, indexed score
You could try to implement custom SearchComponent that will go trough results on Solr and calculate your custom score there. Get results found from ResponseBuilder (rb.getResults().docSet), iterate trough them, add calculated value to your results and re-sort them. You can then register your SearchComponent as last in RequestHandler chain: <arr name="last-components"> <str>elevator</str> </arr> More info in SolR manual: http://wiki.apache.org/solr/SearchComponent Sorry, but no better idea for now.

Categories : Solr

Game Center score submitted, but leaderboard shows no score
Just make sure that you do the correct code for submitting the score. This is a way that I really like. Even though you will get warnings because they don't want you to use it in iOS 7, it still works. Just let me know if it doesn't work. (IBAction)submitscoretogamecenter{ GKLocalPlayer *localplayer = [GKLocalPlayer localPlayer]; [localplayer authenticateWithCompletionHandler:^(NSError *error) { }]; //This is the same category id you set in your itunes connect GameCenter LeaderBoard GKScore *myScoreValue = [[[GKScore alloc] initWithCategory:@"insertCategory"] autorelease]; myScoreValue.value = scoreInt; [myScoreValue reportScoreWithCompletionHandler:^(NSError *error){ //insert what happens after it's posted }]; [self checkAchievements]; }

Categories : IOS

How to get tf-idf score and bm25f score of a term in a document using whoosh?
Finally able to figure it out. Here it is for anyone who come here later, For finding TFIDF and BM25F score of a term and document. qp = QueryParser('content', ix.schema) q = qp.parse(unicode('id:1')) with ix.searcher(weighting=scoring.TF_IDF()) as searcher_tfidf: scoring.TFIDF().scorer(searcher_tfidf, 'body', 'algebra').score(q.matcher(searcher_tfidf)) with ix.searcher(weighting=scoring.BM25F()) as searcher_bm25f: scoring.BM25F().scorer(searcher_bm25f, 'body', 'algebra').score(q.matcher(searcher_bm25f)) ix is IndexReader object obtained using open_dir() method or create_in(). The key is to get the Matcher object that matches exactly the required document. So, use an id or any unique field in the schema to get that particular document using qp.parse() method.

Categories : Misc

Problem to plot 3D surface with R‏
Try this to see why I don't think this data is well suited for wireframe: cloud(Z~X+Y, data=FI02, xlab="X", ylab="Y", main="Surface elevation", type="l", screen=list(z=-60, x=-60))

Categories : R

kruskal.test shows "All group levels must be finite" error. What is the problem?
It should work if you run data$Grp <- as.factor(data$Grp) Then (as before): kruskal.test(data$Val, data$Grp) This is because Grp is a character not a factor and is.finite applied to an object of character class is always false (see ?is.finite).

Categories : R

Does 'select distinct' returns the first distinct value or last distinct?
I think there's a misunderstanding here: Your query does not return the records, only the distinct column values. Which, in your example, are 'Sam' and 'Tom'. They have no particular order which can safely be expected. It may be the natural order, or the order in which they are processed on the database (completely depending on the database implementation), or semi-random (such as iterating over items in a set). The order may also vary depending on whether the result was retreived from the data or from the cache. If you want a particular order, then specify it as order criterium: select distinct Name from Emp order by Name asc If you want the distinct values and the first record containing it, use group by: select min(ID), Name from Emp group by Name

Categories : SQL

Relevance feedback in Apache Solr
Unfortunately, it is not possible to configure the MLT handler that way. One way to do it would be to implement a custom SearchComponent and register it to a (dedicated) SearchHadler. I've already done something similar and it is quite easy if you look a the original implementation of MLT component. The most difficult part is the synchronization of the results from different shard servers, but it can be skipped if you do not use shards. I would also strongly recommend to use your own parameters in your implementation to prevent collisions with other components.

Categories : Solr

Sort by relevance using YouTube API in Python
Figured it out, here's the working code in case anyone wants it: http://pastebin.com/Vei3FyUz Also YouTube personalizes results if you're logged in, so be sure to log out when checking accuracy.

Categories : Python

Sort Wordpress Search by Relevance
I think you can use Relevanssi without any problem but need to use a filter hook, check relevanssi_modify_wp_query for more details, check following code function func_reli($qry){ $qry->set( 'post_type', array( 'post', 'page', 'restaurant', 'products' ) ); if ($_GET['myorder'] == 'price') { $qry->set('orderby', 'meta_value_num'); $qry->set('meta_key', 'price'); $qry->set('order', 'ASC'); } else { $qry->set('orderby', 'date'); $qry->set('order', 'DESC'); // <-- set (in your code 'add' is used) } return $qry; // <-- must return, in your code you didn't } add_filter('relevanssi_modify_wp_query', 'func_reli'); I've tested this code and just works fine. In this example I've used 'restaurant' and 'product

Categories : Wordpress

SQL Insert rows into table that must have 2 distinct columns but also one non distinct column
You'll have to just replace the PRIZEID value with new ones. Because it sounds like you currently have duplicates on your PROMOTION table First add all the distinct PRIZENAMEs and COSTs to your new PRIZE table: INSERT INTO prize(PRIZEID, COST, PRIZENAME) SELECT DISTINCT (SELECT MAX(PRIZEID)+1 FROM PRIZE), r.COST, r.PRIZENAME FROM PROMOTION r; Then update your PROMOTIONs table with the new PRIZEID UPDATE PROMOTION R SET R.PRIZEID = (SELECT P.PRIZEID FROM PRIZE WHERE P.PRIZENAME=R.PRIZENAME AND P.COST=R.COST); Then, I think from there you can safely delete the columns from your PROMOTIONs table

Categories : SQL

Select from 3 possible columns, order by occurances / relevance
You could concatenate the fields which will be better than searching them individually SELECT `id` FROM `wp_ss_images` WHERE CONCAT(`keywords`,`title`,`content`) LIKE '%cute%' This doesn't help with the 'greatest to least' part of your question though.

Categories : PHP

How can I get fuzzy results sorted by relevance using ElasticSearch?
Have you adjusted the min_similarity parameter in your fuzzy query? Increasing the min_similarity may filter out the food and only return the necklace. { "fuzzy" : { "jewelry" : { "value" : "neckla", "boost" : 1.0, "min_similarity" : 0.8, "prefix_length" : 0 } } } As mentioned in the answer to this question, an edgeNGram filter may be your best bet here.

Categories : Elasticsearch

SELECT multiple values and order by relevance
Note sure I follow. Do you mean something like this: SELECT user_id , SUM(CASE WHEN subject_id IN(1,2) THEN 1 ELSE 0 END)ttl FROM user_subjects GROUP BY user_id; ?

Categories : Mysql

SOLR Search relevance is in different order with AND statement
Well it should look something like this instead: text:(+query) and +type:(1 2 3)^0 ^0 means that the second condition should be fulfilled but have no relavance!

Categories : Search

Change Background of DataGridCell in relevance to its content
I did it this way: <DataGrid.CellStyle> <Style TargetType="DataGridCell"> <Setter Property="Background"> <Setter.Value> <Binding Path="Row" Mode="OneWay" /> </Setter.Value> </Setter> </Style> </DataGrid.CellStyle> Note that I am using DataView as ItemsSource to DataGrid and therefore I bind to "Row". Item is than basically DataRowView. Then you need to access row values in the converter: public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { var enumValue = (Membe

Categories : C#

Distributing k distinct items among r distinct groups without ordering
The solution is Stirling's Number of the Second Kind * r! So that's: 1/r! * (SUMMATION(j=0 --> r), (-1)^(r-j) * C(r,j) * j^k) * r! Which simplifies to: (SUMMATION(j=0 --> r), (-1)^(r-j) * C(r,j) * j^r)

Categories : Misc

MSQL select regardless of distinct or not distinct (count greater than zero)
In the data in the question, there is no repeating id in table A. The query should be returning only one row from A, then. However, your query has an error. The second join should be back to the first table, not the second: SELECT a.col1, b.col1, c.col2 FROM a LEFT JOIN b ON b.id = a.id LEFT JOIN c ON c.id = a.id WHERE a.id = 1 You had c.id = b.id and b.id could be NULL if there is no match in that table. Also, from your description, I wonder if a union would be the best approach: select a.col1, 'a' from a where id = 1 union all select b.col1, 'b' from b where id = 1 union all select c.col2, 'c' from c where id = 1

Categories : Mysql

Aggregate String[] grabbing first distinct, but I want it to grab the last distinct
Consider using the overload of Select that takes in the index as part of the transformation (documented here). If you want the last distinct element of each distinct element, you might try to use GroupBy order each IGrouping accordingly, and grabbing the correct element of each group. repeat = domain + dir.Split('/') .Select((word, index) => Tuple.Create(word, index)) .Where(x => keep.Contains(x.Item1)) .GroupBy(x => x.Item1) .Select(g => g.OrderByDescending(x => x.Item2).First()) .OrderBy(x => x.Item2) .Select(x => x.Item1) .Aggregate((gi, j) => gi + "/" + j) + repeat.Substring(lastSlash); Here, we couple each word with its index (using the Select overload mentioned above). Then we filter down to the words of interest. Instead of using Distinct, we now use

Categories : C#

Boosting relevance, based on absolute numerical closeness
you can use function queries to calculate the closeness and boost the value. e.g. div(x,65535) which will generate a value of 1 if exact and less values depending on the closeness. You can check for the other queries as well to factor the boost accordingly. And boost the results q={!boost b=div(x,65535)}text:supervillians

Categories : Solr

Select distinct values of distinct group
You can use the following code to get your desired array with only 1 SQL executed $sql = "SELECT title, group_concat(year) as years FROM table_name group by title" $rs = mysql_query($sql); $arr = array(); while($row = mysql_fetch_assoc($rs)) { $arr[$row['title']] = explode(',',$row['years']); }

Categories : PHP

Excel 2007 VBA MATCH function is not finding a match, but a match does exist in that range?
You must use MatchType of 0 to use wild card characters (* or ?) see: http://office.microsoft.com/en-001/excel-help/match-function-HP010062414.aspx Use Application.Match("More items related to*", Range("AZ1:AZ1000"), 0)

Categories : Excel

Join Distinct Id on non-distinct id (MySql)
SELECT t.ID, t.val_string, t.val_int, t.val_datetime FROM table1 AS t LEFT JOIN (subquery) AS v_table ON t.ID = v_table.ID Sample fiddle

Categories : Mysql

Distinct value of a column and do a count on each distinct value
Considering the following example: To get the unique values, and the occurrences of each unique value, you can do the following: The image is tiny, so here is are the formulas to type-in and drag down: FORMULAS 1. Type in the first cell of column B: =IF(ISERROR(INDEX($A$2:$A$8,MATCH(0,INDEX(COUNTIF($B$1:B1,$A$2:$A$8),0,0),0))),"",INDEX($A$2:$A$8,MATCH(0,INDEX(COUNTIF($B$1:B1,$A$2:$A$8),0,0),0))) Drag the formula down the column B. You will get a list of unique values. 2. Type in the first cell of column C: =COUNTIF($A$2:$A$8,B2) Drag the formula down the column C. You will get the number of occurrences of each unique value. RESULT This is what you will get:

Categories : Excel

IQueryable.Distinct() vs List.Distinct()
Obviously you cannot have exact duplicate rows (including the primary key) in your table. Probably what you mean is rows with some equal fields (excluding primary key). Calling Distinct on IQueryable, generates a SQL DISTINCT operator on the resulting query, which compares every field of your table against each other. Because you cannot have exact duplicate rows in the table, it returns all the rows. On the other hand, calling Distinct on a List<User> will use Equals method of the User object to compare objects in memory (after fetching all the rows from database). The final result depends on the implementation of Equals method, which could check only some fields for equal values.

Categories : C#

search for multiple values, sort by relevance (php + MySQL, no full text search)
You can do the count in SQL. Here is an example: select ((col like 'term1') + (col like 'term2') + . . . (col like 'termN') ) as NumMatches from t having NumMatches > 0 order by NumMatches desc; MySQL treats booleans as 0 (for false) and 1 (for true). You can add them together to get the total number of matches.

Categories : PHP

How to Boost The relevance dynamically(boost value get from database) in Tire elasticsearch
You can use the boosting query (official docs here) { "boosting" : { "negative" : { "match" : { "your_field" : "decrease_relevance_text" } }, "negative_boost" : decrease_relevance_points } } I don't know how to create this specifically with tire though, maybe someone else can help you.

Categories : Ruby On Rails

select distinct out of distinct
The easiest way is to do aggreagtion: select etar.EmplKey, min(emp.EmplFullName) FROM EmployeeTarget etar inner join DimEmployee emp on emp.emplkey = etar.emplkey inner join dimbranch br on br.BranchId = etar.BranchId where etar.BranchId = 8 group by etar.EmplKey

Categories : SQL

Regex to match paths that don't match a specific pattern: Express Router
The following regex will match any path except those starting with /foo/ app.get(/^/([^f][^o][^o]|.{1,2}|.{4,})/.*$/, routes.index); I assume that this is a standard javascript regex.

Categories : Regex

How to boost results in elasticsearch, so that match in field1 is always higher then match in field2?
Have you tried setting use_dis_max to be false? This should mean that a doc with "small" in category and title would be higher than a doc with "small" in just the category. As for the strange behaviour you are seeing between the 2nd and 3rd results, I am a bit lost... Can you do the query and ask for the explanation of how the scores were calculated?

Categories : Elasticsearch

Excel VBA: Can't get a match, error "Unable to get the Match property of the WorksheetFunction class"
Use the Application.Match function which allows for better ability to trap errors. When using the WorksheetFunction.Match, when a match is not found, it returns an error, which is what you're experiencing. If Not IsError(Application.Match(Cells(e, 1).Value, myrange, 0)) Then 'Do stuff when the match is found Cells(e, 3).Value = "Yes" Else: Cells(e, 3).Value = "No" End If You could also potentially use the CountIf function: If Application.WorksheetFunction.CountIf(myRange, Cells(e,1).Value) > 0 Then Cells(e,3).Value = "Yes" Else: Cells(e,3).Value = "No" End If Neither of these approaches requires you to use the m1 variable, you can assign this variable within the True part of the If/Then statement, if you need to identify where the match is found.

Categories : Excel

Javascript string.match refuses to return an array of more than one match
You're looking for the form needle.exec(haystack) From my console: > haystack = "{List:[Names:a,b,c][Ages:1,2,3]}"; "{List:[Names:a,b,c][Ages:1,2,3]}" > needle = /^{List:[Names:([a-zA-z,]*)][Ages:([0-9,]*)]}$/g ; /^{List:[Names:([a-zA-z,]*)][Ages:([0-9,]*)]}$/g > needle.exec(haystack); ["{List:[Names:a,b,c][Ages:1,2,3]}", "a,b,c", "1,2,3"]

Categories : Javascript

Merge two data frame on one exact match and one partial URL match
You can put your data in the long format and then process by ID within a data.table . library(reshape2) dat <- do.call(rbind,lapply(list(pattern,dataset),function(x) melt(x,id.vars='SessionId'))) library(data.table) DT <- data.table(dat,key='SessionId') DT[,if(.N ==2) if(length(grep(value[1],value[2]))>0) as.list(value) ,by='SessionId'] SessionId V1 V2 1: 5b8cc8794a02ba868db21faef1 somewebsite.com/abc/detail/110302288511/ somewebsite.com/abc/detail/110302288511/110302288512/ 2: 5b8cc8794a02ba868db21faef3 somewebsite.com/abc/detail/110302288513/ somewebsite.com/abc/detail/110302288513/1103022815/ EDIT benchmarking the 2 solutio

Categories : R

Python Packman score
The score is not updating because you are incrementing a local variable of the method display_score. You can make it a class member of Packman, for example: def __init__(self, x = games.mouse.x, y = games.mouse.y): """Initialise packman""" # do something ... # initialize the score variable self._score = 0 And then, def display_score(self): display_score = games.Text(value = self._score, size = 25, color = color.black, top = 5, right = games.screen.width - 10) games.screen.add(display_score) #increase the score self._score += 1 # add one to the current value You missed the self argument in the definition of the method!

Categories : Python

How can I post the score on the FB / Gmail / etc?
There is a library called SocialAuth for android. It can be used in cocos2d, as i used it in my games. https://code.google.com/p/socialauth-android/

Categories : Android



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.