Lucene.Net MoreLikeThis returns 0 interesting terms and no clauses in the query - asp.net

I'm trying to implement the Lucene.Net MoreLikeThis query but it doesn't seem to be able to find anything interesting in the document to search the index.
In my scenario, the user has clicked "More Like This" link on the search results webpage, this passes the document id on the query string. My Lucene.Net code looks like this:
var similarSearch = new MoreLikeThis(reader);
similarSearch.SetFieldNames(new[] { "Place", "Subject", "Description", "Name", "Town", "Occupation" });
similarSearch.MinWordLen = 3;
similarSearch.Boost = true;
var terms = similarSearch.RetrieveInterestingTerms(docid);
var doc = reader[docid];
var searchQuery = similarSearch.Like(docid);
Following execution; the terms variable is an empty array, the doc variable contains the document and the searchQuery has no clauses. When I run the search using the query it returns no documents.
My conclusion is I am able to get the document from the reader, but the MoreLikeThis object is unable to find anything to build a query from.
Any idea why?

I think you may need to set one or more of the following parameters on the MoreLikeThis object: Analyzer, MinTermFreq, and/or MinDocFreq
I had the same issue - no results being returned. Once I set the above parameters (try setting both of the minimums to 1), it worked.

Related

Best way for displaying total Pages for a datasource in Appmaker

I have a Google drive table data source which stores list of open positions. Now in the data source I've set "Query per size" field to 10 so that I can get 10 records per page. I've added a Pager as well to show pagination.
My query is I want to display like "Page 1 of X" to my end users and this X will vary based on certain search filters. What will the best way to achieve this in Appmaker?
I've tried counting total records in a data source as per below code but every time updating that with the search criteria and recounting it is not a proper solution.
//Server side
var newQuery = app.models.Company.newQuery();
var records = newQuery.run();
var totalCount =0;
for(var i=0;i<records.length;i++)
{
totalCount=totalCount+1;
}
return totalCount;
In case you don't have any filters in your table your server code can be as simple as
// Server script
function getPagesCount(pageSize) {
var recordsCount = app.models.MyModel.newQuery().run().length;
var pagesCount = Math.ceil(recordsCount / pageSize);
return pagesCount;
}
As an alternative you can consider creating Calculated Model with a single field PagesCount.
In case you have some filters associated with the table then you'll need to run the query for the pages number with exact same filters.
Most likely the entire setup will not work effectively with Drive Tables since there is no way to query records number without querying records themselves. With Cloud SQL data backend one can create Calculated SQL Model with lightweight native SQL query (here :PageSize is query parameter which should be equal to the query.limit of the actual datasource):
SELECT
Ceil(COUNT(1) / :PageSize) AS RecordsNumber
FROM
TableName
WHERE
...
I've achieved this using Calculated Model as suggested by Pavel.
Steps :
Create a calculated data source with one field count.
In that data source add one parameter searchQuery. This will contain users filter going forward. Currently I have only one search query in which user can search many things. So I've added one parameter only.
In this data source add following server script.
Code:
// Server script
function getTotalRecords(query) {
var receivedQuery = query.parameters.searchQuery;
// console.log('Received query:' + query.parameters.searchQuery);
var records = app.models.Company.newQuery();
records.parameters.SearchText = query.parameters.searchQuery;
if(receivedQuery !== null) {
records.where = '(Name contains? :SearchText or InternalId contains? ' +
':SearchText or LocationList contains? :SearchText )';
}
var recordsCount = records.run().length;
var calculatedModelRecords = [];
var draftRecord = app.models.RecordCount.newRecord();
draftRecord.count = ''+recordsCount;
calculatedModelRecords.push(draftRecord);
return calculatedModelRecords;
}
.
On the Appmaker page bind a label with this data source.
On search query/your filter applied event add following code which Reload this data source and assign value to Parameter.
// Client script
function updateRecordCount(newValue) {
var ds = app.datasources.RecordCount;
ds.query.parameters.searchQuery = newValue;
ds.unload();
ds.load();
}

How to find all the files of a particular model in Alfresco

Good morning. I have a task to make a request that would find all the documents of a certain type. After receiving the result, I need to display the fields of all found documents in the table. How can I do that? Thanks for answers.
You can use Lucene query to find all folders of the specific type.
To retrieve all documents of a certain type you can use Lucene query, this is a working example of query to get all nodes with type ipt:delegation using java.
String query = "TYPE:\"ipt:delegation\"";
SearchParameters sp = new SearchParameters();
StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
sp.addStore(storeRef);
sp.setLanguage(SearchService.LANGUAGE_LUCENE);
sp.setQuery(query);
ResultSet results = null;
try {
results = searchService().query(sp);
for (ResultSetRow row : results) {
NodeRef nodeRef = row.getNodeRef();
// do your work -
}
}
And to retrieve document fields you can use nodeService.getProperties(nodeRef).

How to pass a collection name as an argument into methods in Meteor?

Thanks my poor English skill, I have o express my idea by these code below..
Friendly edit:
I am trying to write a generalized confirmAndRemoveCollection method which takes in the collectionName and itemId, and I would like to perform operations on this collection. Since collectionName is a string, I wouldn't be able to perform DB operations on it. Could someone please suggest how I could use the collection name to get access to the actual collection object.
confirmAndRemoveCollection:(collectionName,itemId)->
check(itemId,String)
check(collectionName,String)
sweetAlert({
title:"confirm"
text:"blabla"
type:"info"
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "delete"
cancelButtonText: "cancel"
closeOnConfirm: false,
},(isConfirm)->
if isConfirm
collectionName.remove(itemId)
else
return
swal(
'success'
"selected item deleted"
"success"
)
The variable collectionName is a string object, so you won't be able to call MongoDB methods on it.
One way to accomplish your task is to create an object that maps the string name to the collection object.
For example:
Posts = new Mongo.Collection('posts');
Comments = new Mongo.Collection('comments');
Collections = {
'Posts': Posts,
'Comments': Comments
};
Then you could do something like this in your code
if isConfirm
Collections[collectionName].remove(itemId)
Just to add an alternative here (even though the question is really old): you can pass the collection itself as an argument and it will work.
As the collection is an Object, when you pass it as an argument it will be passed "by reference" and you will be able to call its methods.
Following the example by #FullStack (which also works, of course):
Posts = new Mongo.Collection('posts');
Comments = new Mongo.Collection('comments');
const collectionRemove = (collection, id) => {
const count = collection.remove(id);
console.log(`Removed ${count} items with id ${id} from collection ${collection._name}`)
}
And then do something like:
collectionRemove(Posts, 1);
collectionRemove(Comments, 24);

Linq to Entities does not recognize the method collection Dictionary

I have a model named EmailDetailModel with a Dictionary field.
My query is:
var query = from email in context.EmailModel
where rolesForUser.Contains(email.GroupName)
orderby email.Id descending
select new EmailDetailModel()
{
From = email.From,
Id = email.Id,
message = email.Body,
subject = email.Subject,
pathFileName =
(from pdf in context.PdfModel
where pdf.Email_Id == email.Id
select pdf)
.ToDictionary(k => k.PathFile, v => v.FileName),
timeSend = email.ActiveTime};
However an error occurs on this line when trying to send the list to the view:
View(query.ToPagedList(pageNumber, pageSize));
Saying that:
LINQ to Entities does not recognize the method 'System.Collections.Generic.Dictionary
If anybody could help me, I'm not sure how I can pass the key and value into my pathFileName Dictionary.
The issue likely is that there is no SQL like conversion of the dictionary generation that LINQ to Entities can understand.
I have struggled with similar error messages whenever LINQ cannot be translated to a SQL statement.

pagination in alfresco

I am working on an application which lists and searches document from alfresco. The issue is the alfresco can return upto 5000 records per query. but I don't want my application to list down all documents instead if I can some how implement pagination in alfresco, so that alfresco only return X result per page. I am using Alfresco 4 enterprise edition.
Any help or suggestion please.
UPDATE (Example)
I have written a web script which executes the query and returns all the documents satisfies the condition. Lets say, there are 5000 entries found. I want to modify my web script in a way that the web script returns 100 documents for 1st page, next 100 for second page and so on...
It'll be something like usage of Limit BY and OFFSET keywords. something like this
There are two ways to query on the SearchService (excluding the selectNodes/selectProperties calls). One way is to specify all your arguments directly to the query method. This has the advantage of being concise, but the disadvantage is that you don't get all the options.
Alternately, you can query with a SearchParameters object. This lets you do everything the simple query does, and more. Included in that more are setLimit, setSkipCount and setMaxItems, which will allow you to do your paging.
If your query used to be something like:
searchService.query(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, "lucene", myQuery);
You'd instead do something like:
SearchParameters sp = new SearchParameters();
sp.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
sp.setLanguage("lucene");
sp.setQuery(myQuery);
sp.setMaxItems(100);
sp.setSkipCount(900);
searchService.query(sp);
Assuming you have written your webscript in Javascript you can use the search.query() function and add the page property to the search definition as shown below:
var sort1 = {
column: "#{http://www.alfresco.org/model/content/1.0}modified",
ascending: false
};
var sort2 = {
column: "#{http://www.alfresco.org/model/content/1.0}created",
ascending: false
};
var paging = {
maxItems: 100,
skipCount: 0
};
var def = {
query: "cm:name:test*",
store: "workspace://SpacesStore",
language: "fts-alfresco",
sort: [sort1, sort2],
page: paging
};
var results = search.query(def);
You can find more information here: http://wiki.alfresco.com/wiki/4.0_JavaScript_API#Search_API

Resources